X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiOptionsTest.php;h=7e45f4da123ce740876eb98f6204a8d915a915d9;hb=d84c3dde5af90c5c3497d18e427a5c2a38ac6ca8;hp=0a577c1cb6929fffadd8eca52d0215987e10402b;hpb=b5906606e1aa1a795231fb813b766818b1dd6c25;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiOptionsTest.php b/tests/phpunit/includes/api/ApiOptionsTest.php index 0a577c1cb6..7e45f4da12 100644 --- a/tests/phpunit/includes/api/ApiOptionsTest.php +++ b/tests/phpunit/includes/api/ApiOptionsTest.php @@ -30,7 +30,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase { $this->mUserMock->expects( $this->any() ) ->method( 'getEffectiveGroups' )->will( $this->returnValue( [ '*', 'user' ] ) ); $this->mUserMock->expects( $this->any() ) - ->method( 'isAllowed' )->will( $this->returnValue( true ) ); + ->method( 'isAllowedAny' )->will( $this->returnValue( true ) ); // Set up callback for User::getOptionKinds $this->mUserMock->expects( $this->any() ) @@ -146,7 +146,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase { } /** - * @expectedException UsageException + * @expectedException ApiUsageException */ public function testNoToken() { $request = $this->getSampleRequest( [ 'token' => null ] ); @@ -163,13 +163,11 @@ class ApiOptionsTest extends MediaWikiLangTestCase { $request = $this->getSampleRequest(); $this->executeQuery( $request ); - } catch ( UsageException $e ) { - $this->assertEquals( 'notloggedin', $e->getCodeString() ); - $this->assertEquals( 'Anonymous users cannot change preferences', $e->getMessage() ); - + } catch ( ApiUsageException $e ) { + $this->assertTrue( ApiTestCase::apiExceptionHasCode( $e, 'notloggedin' ) ); return; } - $this->fail( "UsageException was not thrown" ); + $this->fail( "ApiUsageException was not thrown" ); } public function testNoOptionname() { @@ -177,13 +175,11 @@ class ApiOptionsTest extends MediaWikiLangTestCase { $request = $this->getSampleRequest( [ 'optionvalue' => '1' ] ); $this->executeQuery( $request ); - } catch ( UsageException $e ) { - $this->assertEquals( 'nooptionname', $e->getCodeString() ); - $this->assertEquals( 'The optionname parameter must be set', $e->getMessage() ); - + } catch ( ApiUsageException $e ) { + $this->assertTrue( ApiTestCase::apiExceptionHasCode( $e, 'nooptionname' ) ); return; } - $this->fail( "UsageException was not thrown" ); + $this->fail( "ApiUsageException was not thrown" ); } public function testNoChanges() { @@ -200,13 +196,11 @@ class ApiOptionsTest extends MediaWikiLangTestCase { $request = $this->getSampleRequest(); $this->executeQuery( $request ); - } catch ( UsageException $e ) { - $this->assertEquals( 'nochanges', $e->getCodeString() ); - $this->assertEquals( 'No changes were requested', $e->getMessage() ); - + } catch ( ApiUsageException $e ) { + $this->assertTrue( ApiTestCase::apiExceptionHasCode( $e, 'nochanges' ) ); return; } - $this->fail( "UsageException was not thrown" ); + $this->fail( "ApiUsageException was not thrown" ); } public function testReset() { @@ -284,26 +278,13 @@ class ApiOptionsTest extends MediaWikiLangTestCase { $this->mUserMock->expects( $this->never() ) ->method( 'resetOptions' ); - $this->mUserMock->expects( $this->at( 2 ) ) - ->method( 'getOptions' ); - - $this->mUserMock->expects( $this->at( 5 ) ) + $this->mUserMock->expects( $this->exactly( 3 ) ) ->method( 'setOption' ) - ->with( $this->equalTo( 'willBeNull' ), $this->identicalTo( null ) ); - - $this->mUserMock->expects( $this->at( 6 ) ) - ->method( 'getOptions' ); - - $this->mUserMock->expects( $this->at( 7 ) ) - ->method( 'setOption' ) - ->with( $this->equalTo( 'willBeEmpty' ), $this->equalTo( '' ) ); - - $this->mUserMock->expects( $this->at( 8 ) ) - ->method( 'getOptions' ); - - $this->mUserMock->expects( $this->at( 9 ) ) - ->method( 'setOption' ) - ->with( $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) ); + ->withConsecutive( + [ $this->equalTo( 'willBeNull' ), $this->identicalTo( null ) ], + [ $this->equalTo( 'willBeEmpty' ), $this->equalTo( '' ) ], + [ $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) ] + ); $this->mUserMock->expects( $this->once() ) ->method( 'saveSettings' ); @@ -321,19 +302,12 @@ class ApiOptionsTest extends MediaWikiLangTestCase { $this->mUserMock->expects( $this->once() ) ->method( 'resetOptions' ); - $this->mUserMock->expects( $this->at( 5 ) ) - ->method( 'getOptions' ); - - $this->mUserMock->expects( $this->at( 6 ) ) + $this->mUserMock->expects( $this->exactly( 2 ) ) ->method( 'setOption' ) - ->with( $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) ); - - $this->mUserMock->expects( $this->at( 7 ) ) - ->method( 'getOptions' ); - - $this->mUserMock->expects( $this->at( 8 ) ) - ->method( 'setOption' ) - ->with( $this->equalTo( 'name' ), $this->equalTo( 'value' ) ); + ->withConsecutive( + [ $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) ], + [ $this->equalTo( 'name' ), $this->equalTo( 'value' ) ] + ); $this->mUserMock->expects( $this->once() ) ->method( 'saveSettings' ); @@ -354,21 +328,14 @@ class ApiOptionsTest extends MediaWikiLangTestCase { $this->mUserMock->expects( $this->never() ) ->method( 'resetOptions' ); - $this->mUserMock->expects( $this->at( 4 ) ) - ->method( 'setOption' ) - ->with( $this->equalTo( 'testmultiselect-opt1' ), $this->identicalTo( true ) ); - - $this->mUserMock->expects( $this->at( 5 ) ) - ->method( 'setOption' ) - ->with( $this->equalTo( 'testmultiselect-opt2' ), $this->identicalTo( null ) ); - - $this->mUserMock->expects( $this->at( 6 ) ) - ->method( 'setOption' ) - ->with( $this->equalTo( 'testmultiselect-opt3' ), $this->identicalTo( false ) ); - - $this->mUserMock->expects( $this->at( 7 ) ) + $this->mUserMock->expects( $this->exactly( 4 ) ) ->method( 'setOption' ) - ->with( $this->equalTo( 'testmultiselect-opt4' ), $this->identicalTo( false ) ); + ->withConsecutive( + [ $this->equalTo( 'testmultiselect-opt1' ), $this->identicalTo( true ) ], + [ $this->equalTo( 'testmultiselect-opt2' ), $this->identicalTo( null ) ], + [ $this->equalTo( 'testmultiselect-opt3' ), $this->identicalTo( false ) ], + [ $this->equalTo( 'testmultiselect-opt4' ), $this->identicalTo( false ) ] + ); $this->mUserMock->expects( $this->once() ) ->method( 'saveSettings' ); @@ -400,7 +367,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase { 'options' => 'success', 'warnings' => [ 'options' => [ - 'warnings' => "Validation error for 'special': cannot be set by this module" + 'warnings' => "Validation error for \"special\": cannot be set by this module." ] ] ], $response ); @@ -423,7 +390,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase { 'options' => 'success', 'warnings' => [ 'options' => [ - 'warnings' => "Validation error for 'unknownOption': not a valid preference" + 'warnings' => "Validation error for \"unknownOption\": not a valid preference." ] ] ], $response );