ORMRow must not ignore failures on insert by deault.
authordaniel <daniel.kinzler@wikimedia.de>
Wed, 31 Oct 2012 14:37:39 +0000 (15:37 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Wed, 31 Oct 2012 19:15:02 +0000 (20:15 +0100)
ORMRow shouldn't apply the "IGNORE" modifier for insertions by default.
IGNORE means pretending the insert was successfull even if it wasn't.
That's not a good default, and for some databases (like sqlite), may
actually hide errors beyond key conflicts.

Change-Id: I8b00cd03a459419441195ed25091385371b027a5

includes/db/ORMRow.php
includes/site/SitesTable.php
tests/phpunit/includes/db/ORMRowTest.php
tests/phpunit/includes/db/TestORMRowTest.php
tests/phpunit/includes/site/SiteObjectTest.php

index fa25868..eaedb8b 100644 (file)
@@ -263,8 +263,10 @@ abstract class ORMRow implements IORMRow {
                                switch ( $type ) {
                                        case 'array':
                                                $value = (array)$value;
+                                               // fall-through!
                                        case 'blob':
                                                $value = serialize( $value );
+                                               // fall-through!
                                }
 
                                $values[$this->table->getPrefixedField( $name )] = $value;
@@ -389,7 +391,7 @@ abstract class ORMRow implements IORMRow {
                        $this->table->getName(),
                        $this->getWriteValues(),
                        is_null( $functionName ) ? __METHOD__ : $functionName,
-                       is_null( $options ) ? array( 'IGNORE' ) : $options
+                       $options
                );
 
                // DatabaseBase::insert does not always return true for success as documented...
index a03c598..bb12740 100644 (file)
@@ -95,6 +95,7 @@ class SitesTable extends ORMTable {
 
                        'forward' => false,
                        'config' => array(),
+                       'language' => 'en', // XXX: can we default to '' instead?
                );
        }
 
index 9dcaf2b..cd970b3 100644 (file)
@@ -155,12 +155,11 @@ abstract class ORMRowTest extends \MediaWikiTestCase {
 
        /**
         * @dataProvider constructorTestProvider
+        * @depends testSave()
         */
        public function testRemove( array $data, $loadDefaults ) {
                $item = $this->getRowInstance( $data, $loadDefaults );
 
-               $this->assertTrue( $item->save() );
-
                $this->assertTrue( $item->remove() );
 
                $this->assertFalse( $item->hasIdField() );
index c7bea3b..e33ae01 100644 (file)
@@ -87,6 +87,7 @@ class TestORMRowTest extends ORMRowTest {
                        array(
                                array(
                                        'name' => 'Foobar',
+                                       'time' => '20120101020202',
                                        'age' => 42,
                                        'height' => 9000.1,
                                        'awesome' => true,
index e8358f3..207f46c 100644 (file)
@@ -25,6 +25,7 @@
  * @ingroup Test
  *
  * @group Site
+ * @group Database
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
@@ -57,9 +58,9 @@ class SiteObjectTest extends ORMRowTest {
        public function constructorTestProvider() {
                $argLists = array();
 
-               $argLists[] = array( 'global_key' => '42' );
+               $argLists[] = array( 'global_key' => 'foo' );
 
-               $argLists[] = array( 'global_key' => '42', 'type' => Site::TYPE_MEDIAWIKI );
+               $argLists[] = array( 'global_key' => 'bar', 'type' => Site::TYPE_MEDIAWIKI );
 
                $constructorArgs = array();
 
@@ -229,6 +230,17 @@ class SiteObjectTest extends ORMRowTest {
                $this->assertEquals( $path, $site->getPath( 'foo' ) );
        }
 
+       public function testProtocolRelativePath() {
+               /* @var SiteObject $site */
+               $site = $this->getRowInstance( $this->getMockFields(), false );
+
+               $type = $site->getLinkPathType();
+               $path = '//acme.com/'; // protocol-relative URL
+               $site->setPath( $type, $path );
+
+               $this->assertEquals( '', $site->getProtocol() );
+       }
+
        public function provideGetPageUrl() {
                //NOTE: the assumption that the URL is built by replacing $1
                //      with the urlencoded version of $page