From: Aaron Schulz Date: Wed, 10 May 2017 02:25:56 +0000 (-0700) Subject: Avoid assuming a user with ID 0 exists in ApiMainTest::testAssert X-Git-Tag: 1.31.0-rc.0~3284^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=b8340df640298363c42e64b419820ec63ca3ae80;p=lhc%2Fweb%2Fwiklou.git Avoid assuming a user with ID 0 exists in ApiMainTest::testAssert If the load() triggered by User method calls fails, then mId becomes 0 which means there is no "user" right set in getAutomaticGroups(). Bug: T75174 Change-Id: I2d719e4b96c0142e9d408aa2d4f7c5e7a767a754 --- diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php index 3e6ceb7a6e..ea33a9e3ad 100644 --- a/tests/phpunit/includes/api/ApiMainTest.php +++ b/tests/phpunit/includes/api/ApiMainTest.php @@ -45,9 +45,11 @@ class ApiMainTest extends ApiTestCase { * @param string|bool $error False if no error expected */ public function testAssert( $registered, $rights, $assert, $error ) { - $user = new User(); if ( $registered ) { - $user->setId( 1 ); + $user = $this->getMutableTestUser()->getUser(); + $user->load(); // load before setting mRights + } else { + $user = new User(); } $user->mRights = $rights; try { @@ -57,7 +59,8 @@ class ApiMainTest extends ApiTestCase { ], null, null, $user ); $this->assertFalse( $error ); // That no error was expected } catch ( ApiUsageException $e ) { - $this->assertTrue( self::apiExceptionHasCode( $e, $error ) ); + $this->assertTrue( self::apiExceptionHasCode( $e, $error ), + "Error '{$e->getMessage()}' matched expected '$error'" ); } }