(bug 42226) failure in sites tests
authorjeroendedauw <jeroendedauw@gmail.com>
Thu, 6 Dec 2012 22:34:23 +0000 (23:34 +0100)
committerAntoine Musso <hashar@free.fr>
Fri, 7 Dec 2012 10:38:40 +0000 (11:38 +0100)
MediaWikiSiteTest::testRemove got a duplicate key error.

Change-Id: I7a40fe50b757e4162b7ccf1655d872cbd2c51f5d

includes/db/ORMRow.php
includes/site/SiteObject.php
tests/phpunit/includes/db/ORMRowTest.php

index affd65f..d64530f 100644 (file)
@@ -453,8 +453,8 @@ abstract class ORMRow implements IORMRow {
        }
 
        /**
-        * Gets called after successfull removal.
-        * Can be overriden to get rid of linked data.
+        * Gets called after successful removal.
+        * Can be overridden to get rid of linked data.
         *
         * @since 1.20
         */
index 0c6aeb3..78c942b 100644 (file)
@@ -439,7 +439,7 @@ class SiteObject extends ORMRow implements Site {
        }
 
        /**
-        * @see ORMRow::save
+        * @see IORMRow::save
         * @see Site::save
         *
         * @since 1.21
@@ -449,7 +449,7 @@ class SiteObject extends ORMRow implements Site {
         * @return boolean Success indicator
         */
        public function save( $functionName = null ) {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->table->getWriteDbConnection();
 
                $trx = $dbw->trxLevel();
 
@@ -495,6 +495,25 @@ class SiteObject extends ORMRow implements Site {
                return $success;
        }
 
+       /**
+        * @since 1.21
+        *
+        * @see ORMRow::onRemoved
+        */
+       protected function onRemoved() {
+               $dbw = $this->table->getWriteDbConnection();
+
+               $dbw->delete(
+                       'site_identifiers',
+                       array(
+                               'si_site' => $this->getId()
+                       ),
+                       __METHOD__
+               );
+
+               parent::onRemoved();
+       }
+
        /**
         * @see Site::setPath
         *
index b46ce2e..8516241 100644 (file)
@@ -136,7 +136,7 @@ abstract class ORMRowTest extends \MediaWikiTestCase {
        /**
         * @dataProvider constructorTestProvider
         */
-       public function testSave( array $data, $loadDefaults ) {
+       public function testSaveAndRemove( array $data, $loadDefaults ) {
                $item = $this->getRowInstance( $data, $loadDefaults );
 
                $this->assertTrue( $item->save() );
@@ -151,14 +151,6 @@ abstract class ORMRowTest extends \MediaWikiTestCase {
                $this->assertEquals( $id, $item->getId() );
 
                $this->verifyFields( $item, $data );
-       }
-
-       /**
-        * @dataProvider constructorTestProvider
-        * @depends testSave
-        */
-       public function testRemove( array $data, $loadDefaults ) {
-               $item = $this->getRowInstance( $data, $loadDefaults );
 
                $this->assertTrue( $item->remove() );