From: daniel Date: Wed, 31 Oct 2012 14:37:39 +0000 (+0100) Subject: ORMRow must not ignore failures on insert by deault. X-Git-Tag: 1.31.0-rc.0~21726^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=commitdiff_plain;h=980da6d6a7fca8dd58f11f4116def55d59b5b17d;p=lhc%2Fweb%2Fwiklou.git ORMRow must not ignore failures on insert by deault. 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 --- diff --git a/includes/db/ORMRow.php b/includes/db/ORMRow.php index fa25868d7a..eaedb8b18d 100644 --- a/includes/db/ORMRow.php +++ b/includes/db/ORMRow.php @@ -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... diff --git a/includes/site/SitesTable.php b/includes/site/SitesTable.php index a03c5989fe..bb12740d77 100644 --- a/includes/site/SitesTable.php +++ b/includes/site/SitesTable.php @@ -95,6 +95,7 @@ class SitesTable extends ORMTable { 'forward' => false, 'config' => array(), + 'language' => 'en', // XXX: can we default to '' instead? ); } diff --git a/tests/phpunit/includes/db/ORMRowTest.php b/tests/phpunit/includes/db/ORMRowTest.php index 9dcaf2b372..cd970b3d1a 100644 --- a/tests/phpunit/includes/db/ORMRowTest.php +++ b/tests/phpunit/includes/db/ORMRowTest.php @@ -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() ); diff --git a/tests/phpunit/includes/db/TestORMRowTest.php b/tests/phpunit/includes/db/TestORMRowTest.php index c7bea3bbc2..e33ae0181d 100644 --- a/tests/phpunit/includes/db/TestORMRowTest.php +++ b/tests/phpunit/includes/db/TestORMRowTest.php @@ -87,6 +87,7 @@ class TestORMRowTest extends ORMRowTest { array( array( 'name' => 'Foobar', + 'time' => '20120101020202', 'age' => 42, 'height' => 9000.1, 'awesome' => true, diff --git a/tests/phpunit/includes/site/SiteObjectTest.php b/tests/phpunit/includes/site/SiteObjectTest.php index e8358f388e..207f46c080 100644 --- a/tests/phpunit/includes/site/SiteObjectTest.php +++ b/tests/phpunit/includes/site/SiteObjectTest.php @@ -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