http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89072

Revision: 89072
Author:   hashar
Date:     2011-05-28 21:25:29 +0000 (Sat, 28 May 2011)
Log Message:
-----------
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: trunk/phase3/tests/phpunit/includes/BlockTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/BlockTest.php   2011-05-28 21:22:29 UTC 
(rev 89071)
+++ trunk/phase3/tests/phpunit/includes/BlockTest.php   2011-05-28 21:25:29 UTC 
(rev 89072)
@@ -6,6 +6,9 @@
 class BlockTest extends MediaWikiLangTestCase {
        
        private $block, $madeAt;
+
+       /* variable used to save up the blockID we insert in this test suite */
+       private $blockId;
        
        function setUp() {
                global $wgContLang;
@@ -14,6 +17,7 @@
        }
        
        function addDBData() {
+               //$this->dumpBlocks();
                
                $user = User::newFromName( 'UTBlockee' );
                if( $user->getID() == 0 ) {
@@ -29,13 +33,29 @@
                $this->madeAt = wfTimestamp( TS_MW );
 
                $this->block->insert();
+               // 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();
        }
-       
+
+       /**
+        * debug function : dump the ipblocks table
+        */
+       function dumpBlocks() {
+               $v = $this->db->query( 'SELECT * FROM unittest_ipblocks' );
+               print "Got " . $v->numRows() . " rows. Full dump follow:\n";
+               foreach( $v as $row ) {
+                       print_r( $row );
+               }
+       }
+
        function testInitializerFunctionsReturnCorrectBlock() {
-               
+               // $this->dumpBlocks();
+
                $this->assertTrue( $this->block->equals( 
Block::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as 
the one that was made");
                
-               $this->assertTrue( $this->block->equals( Block::newFromID( 1 ) 
), "newFromID() returns the same block as the one that was made");
+               $this->assertTrue( $this->block->equals( Block::newFromID( 
$this->blockId ) ), "newFromID() returns the same block as the one that was 
made");
                
        }
        


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to