From: Gergő Tisza Date: Thu, 19 Nov 2015 22:09:29 +0000 (-0800) Subject: Use User::getId instead of trying to fix the ID in BlockTest X-Git-Tag: 1.31.0-rc.0~8931^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=4b72ec94d1db804aceb5fd25c5e808f5524f5d18;p=lhc%2Fweb%2Fwiklou.git Use User::getId instead of trying to fix the ID in BlockTest User::setId() has no effect on User::addToDatabase whatsoever, and directly messing with the database is fragile due to internal ID caching. Just use the insert ID instead. Change-Id: Ib92f2b6d73deacaec90dc06634d8b3ad195d53e3 --- diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index e69fa200c6..2a2b603565 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -136,8 +136,9 @@ class BlockTest extends MediaWikiLangTestCase { public function testBlockedUserCanNotCreateAccount() { $username = 'BlockedUserToCreateAccountWith'; $u = User::newFromName( $username ); - $u->setId( 14146 ); $u->addToDatabase(); + $userId = $u->getId(); + $this->assertNotEquals( 0, $userId, 'sanity' ); TestUser::setPasswordForUser( $u, 'NotRandomPass' ); unset( $u ); @@ -157,7 +158,7 @@ class BlockTest extends MediaWikiLangTestCase { // Foreign perspective (blockee not on current wiki)... $blockOptions = array( 'address' => $username, - 'user' => 14146, + 'user' => $userId, 'reason' => 'crosswiki block...', 'timestamp' => wfTimestampNow(), 'expiry' => $this->db->getInfinity(), @@ -205,13 +206,13 @@ class BlockTest extends MediaWikiLangTestCase { // Local perspective (blockee on current wiki)... $user = User::newFromName( 'UserOnForeignWiki' ); $user->addToDatabase(); - // Set user ID to match the test value - $this->db->update( 'user', array( 'user_id' => 14146 ), array( 'user_id' => $user->getId() ) ); + $userId = $user->getId(); + $this->assertNotEquals( 0, $userId, 'sanity' ); // Foreign perspective (blockee not on current wiki)... $blockOptions = array( 'address' => 'UserOnForeignWiki', - 'user' => 14146, + 'user' => $user->getId(), 'reason' => 'crosswiki block...', 'timestamp' => wfTimestampNow(), 'expiry' => $this->db->getInfinity(), @@ -234,7 +235,7 @@ class BlockTest extends MediaWikiLangTestCase { $block->getTarget()->getName(), 'Correct blockee name' ); - $this->assertEquals( '14146', $block->getTarget()->getId(), 'Correct blockee id' ); + $this->assertEquals( $userId, $block->getTarget()->getId(), 'Correct blockee id' ); $this->assertEquals( 'MetaWikiUser', $block->getBlocker(), 'Correct blocker name' ); $this->assertEquals( 'MetaWikiUser', $block->getByName(), 'Correct blocker name' ); $this->assertEquals( 0, $block->getBy(), 'Correct blocker id' );