r89072 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89071‎ | r89072 | r89073 >
Date:21:25, 28 May 2011
Author:hashar
Status:resolved
Tags:
Comment:
Use the correct ID when retrieving a block

The ID might be different than the one you expect. Since r88755 the tables
are no more dropped and recreated, thus the autoincrement pointer is not
reset. A previous test could have raised that pointer, thus the id might
be above the expected value.
This patch track the block ID inserted and use it in the assertion.
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/BlockTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/BlockTest.php
@@ -6,6 +6,9 @@
77 class BlockTest extends MediaWikiLangTestCase {
88
99 private $block, $madeAt;
 10+
 11+ /* variable used to save up the blockID we insert in this test suite */
 12+ private $blockId;
1013
1114 function setUp() {
1215 global $wgContLang;
@@ -14,6 +17,7 @@
1518 }
1619
1720 function addDBData() {
 21+ //$this->dumpBlocks();
1822
1923 $user = User::newFromName( 'UTBlockee' );
2024 if( $user->getID() == 0 ) {
@@ -29,13 +33,29 @@
3034 $this->madeAt = wfTimestamp( TS_MW );
3135
3236 $this->block->insert();
 37+ // save up ID for use in assertion. Since ID is an autoincrement,
 38+ // its value might change depending on the order the tests are run.
 39+ // ApiBlockTest insert its own blocks!
 40+ $this->blockId = $this->block->getId();
3341 }
34 -
 42+
 43+ /**
 44+ * debug function : dump the ipblocks table
 45+ */
 46+ function dumpBlocks() {
 47+ $v = $this->db->query( 'SELECT * FROM unittest_ipblocks' );
 48+ print "Got " . $v->numRows() . " rows. Full dump follow:\n";
 49+ foreach( $v as $row ) {
 50+ print_r( $row );
 51+ }
 52+ }
 53+
3554 function testInitializerFunctionsReturnCorrectBlock() {
36 -
 55+ // $this->dumpBlocks();
 56+
3757 $this->assertTrue( $this->block->equals( Block::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made");
3858
39 - $this->assertTrue( $this->block->equals( Block::newFromID( 1 ) ), "newFromID() returns the same block as the one that was made");
 59+ $this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made");
4060
4161 }
4262

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88755Fixup phpunit tests so we don't drop/create tables on EVERY SINGLE TEST....demon21:22, 24 May 2011

Status & tagging log