From 15445510ff6cffc61e95406a83b29181cecb9ffd Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 15 Jun 2011 20:43:24 +0000 Subject: [PATCH] Fix for BlockTest -- when setup ran multiple times, the block entry wouldn't get re-saved and we'd end up with null or 0 as our block id. 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 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index af434c87b1..06de380997 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -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?" ); + } } /** -- 2.20.1