From b8340df640298363c42e64b419820ec63ca3ae80 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 9 May 2017 19:25:56 -0700 Subject: [PATCH] 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 --- tests/phpunit/includes/api/ApiMainTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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'" ); } } -- 2.20.1