Fix for BlockTest -- when setup ran multiple times, the block entry wouldn't get...
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 15 Jun 2011 20:43:24 +0000 (20:43 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 15 Jun 2011 20:43:24 +0000 (20:43 +0000)
By first removing any matching block, we can re-insert it at will and have a fresh working block to test.

tests/phpunit/includes/BlockTest.php

index af434c8..06de380 100644 (file)
@@ -28,7 +28,14 @@ class BlockTest extends MediaWikiLangTestCase {
                        
                        $user->saveSettings();
                }
-               
+
+               // Delete the last round's block if it's still there
+               $oldBlock = Block::newFromTarget( 'UTBlockee' );
+               if ( $oldBlock ) {
+                       // An old block will prevent our new one from saving.
+                       $oldBlock->delete();
+               }
+
                $this->block = new Block( 'UTBlockee', 1, 0,
                        self::REASON
                );
@@ -38,7 +45,12 @@ class BlockTest extends MediaWikiLangTestCase {
                // save up ID for use in assertion. Since ID is an autoincrement,
                // its value might change depending on the order the tests are run.
                // ApiBlockTest insert its own blocks!
-               $this->blockId = $this->block->getId();
+               $newBlockId = $this->block->getId();
+               if ($newBlockId) {
+                       $this->blockId = $newBlockId;
+               } else {
+                       throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" );
+               }
        }
 
        /**