From 63601400e476c6cf43d985f3e7b9864681695ed4 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Jan 2013 16:46:04 +0100 Subject: Update to MediaWiki 1.20.2 this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024 --- tests/phpunit/includes/api/ApiBlockTest.php | 51 +++- tests/phpunit/includes/api/ApiEditPageTest.php | 84 +++++++ tests/phpunit/includes/api/ApiOptionsTest.php | 276 +++++++++++++++++++++ tests/phpunit/includes/api/ApiPurgeTest.php | 1 + tests/phpunit/includes/api/ApiQueryTest.php | 1 + tests/phpunit/includes/api/ApiTest.php | 1 + tests/phpunit/includes/api/ApiTestCase.php | 59 +++-- tests/phpunit/includes/api/ApiTestUser.php | 59 ----- tests/phpunit/includes/api/ApiUploadTest.php | 1 + tests/phpunit/includes/api/ApiWatchTest.php | 88 +++---- .../phpunit/includes/api/PrefixUniquenessTest.php | 24 ++ .../phpunit/includes/api/RandomImageGenerator.php | 2 +- .../phpunit/includes/api/generateRandomImages.php | 8 +- 13 files changed, 522 insertions(+), 133 deletions(-) create mode 100644 tests/phpunit/includes/api/ApiEditPageTest.php create mode 100644 tests/phpunit/includes/api/ApiOptionsTest.php delete mode 100644 tests/phpunit/includes/api/ApiTestUser.php create mode 100644 tests/phpunit/includes/api/PrefixUniquenessTest.php (limited to 'tests/phpunit/includes/api') diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index b95d8214..5dfceee8 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -1,6 +1,7 @@ 'block', 'user' => 'UTApiBlockee', 'reason' => 'Some reason', - 'token' => $pageinfo['blocktoken'] ), $data, false, self::$users['sysop']->user ); + 'token' => $pageinfo['blocktoken'] ), null, false, self::$users['sysop']->user ); $block = Block::newFromTarget('UTApiBlockee'); @@ -69,4 +68,50 @@ class ApiBlockTest extends ApiTestCase { } + /** + * @dataProvider provideBlockUnblockAction + */ + function testGetTokenUsingABlockingAction( $action ) { + $data = $this->doApiRequest( + array( + 'action' => $action, + 'user' => 'UTApiBlockee', + 'gettoken' => '' ), + null, + false, + self::$users['sysop']->user + ); + $this->assertEquals( 34, strlen( $data[0][$action]["{$action}token"] ) ); + } + + /** + * Attempting to block without a token should give a UsageException with + * error message: + * "The token parameter must be set" + * + * @dataProvider provideBlockUnblockAction + * @expectedException UsageException + */ + function testBlockingActionWithNoToken( $action ) { + $this->doApiRequest( + array( + 'action' => $action, + 'user' => 'UTApiBlockee', + 'reason' => 'Some reason', + ), + null, + false, + self::$users['sysop']->user + ); + } + + /** + * Just provide the 'block' and 'unblock' action to test both API calls + */ + function provideBlockUnblockAction() { + return array( + array( 'block' ), + array( 'unblock' ), + ); + } } diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php new file mode 100644 index 00000000..5297d6da --- /dev/null +++ b/tests/phpunit/includes/api/ApiEditPageTest.php @@ -0,0 +1,84 @@ +doLogin(); + } + + function testEdit( ) { + $name = 'ApiEditPageTest_testEdit'; + + // -- test new page -------------------------------------------- + $apiResult = $this->doApiRequestWithToken( array( + 'action' => 'edit', + 'title' => $name, + 'text' => 'some text', ) ); + $apiResult = $apiResult[0]; + + # Validate API result data + $this->assertArrayHasKey( 'edit', $apiResult ); + $this->assertArrayHasKey( 'result', $apiResult['edit'] ); + $this->assertEquals( 'Success', $apiResult['edit']['result'] ); + + $this->assertArrayHasKey( 'new', $apiResult['edit'] ); + $this->assertArrayNotHasKey( 'nochange', $apiResult['edit'] ); + + $this->assertArrayHasKey( 'pageid', $apiResult['edit'] ); + + // -- test existing page, no change ---------------------------- + $data = $this->doApiRequestWithToken( array( + 'action' => 'edit', + 'title' => $name, + 'text' => 'some text', ) ); + + $this->assertEquals( 'Success', $data[0]['edit']['result'] ); + + $this->assertArrayNotHasKey( 'new', $data[0]['edit'] ); + $this->assertArrayHasKey( 'nochange', $data[0]['edit'] ); + + // -- test existing page, with change -------------------------- + $data = $this->doApiRequestWithToken( array( + 'action' => 'edit', + 'title' => $name, + 'text' => 'different text' ) ); + + $this->assertEquals( 'Success', $data[0]['edit']['result'] ); + + $this->assertArrayNotHasKey( 'new', $data[0]['edit'] ); + $this->assertArrayNotHasKey( 'nochange', $data[0]['edit'] ); + + $this->assertArrayHasKey( 'oldrevid', $data[0]['edit'] ); + $this->assertArrayHasKey( 'newrevid', $data[0]['edit'] ); + $this->assertNotEquals( + $data[0]['edit']['newrevid'], + $data[0]['edit']['oldrevid'], + "revision id should change after edit" + ); + } + + function testEditAppend() { + $this->markTestIncomplete( "not yet implemented" ); + } + + function testEditSection() { + $this->markTestIncomplete( "not yet implemented" ); + } + + function testUndo() { + $this->markTestIncomplete( "not yet implemented" ); + } + + function testEditNonText() { + $this->markTestIncomplete( "not yet implemented" ); + } +} diff --git a/tests/phpunit/includes/api/ApiOptionsTest.php b/tests/phpunit/includes/api/ApiOptionsTest.php new file mode 100644 index 00000000..5243fca1 --- /dev/null +++ b/tests/phpunit/includes/api/ApiOptionsTest.php @@ -0,0 +1,276 @@ + 'success' ); + + function setUp() { + parent::setUp(); + + $this->mUserMock = $this->getMockBuilder( 'User' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->mApiMainMock = $this->getMockBuilder( 'ApiBase' ) + ->disableOriginalConstructor() + ->getMock(); + + // Set up groups + $this->mUserMock->expects( $this->any() ) + ->method( 'getEffectiveGroups' )->will( $this->returnValue( array( '*', 'user')) ); + + // Create a new context + $this->mContext = new DerivativeContext( new RequestContext() ); + $this->mContext->getContext()->setTitle( Title::newFromText( 'Test' ) ); + $this->mContext->setUser( $this->mUserMock ); + + $this->mApiMainMock->expects( $this->any() ) + ->method( 'getContext' ) + ->will( $this->returnValue( $this->mContext ) ); + + $this->mApiMainMock->expects( $this->any() ) + ->method( 'getResult' ) + ->will( $this->returnValue( new ApiResult( $this->mApiMainMock ) ) ); + + + // Empty session + $this->mSession = array(); + + $this->mTested = new ApiOptions( $this->mApiMainMock, 'options' ); + + global $wgHooks; + if ( !isset( $wgHooks['GetPreferences'] ) ) { + $wgHooks['GetPreferences'] = array(); + } + $this->mOldGetPreferencesHooks = $wgHooks['GetPreferences']; + $wgHooks['GetPreferences'][] = array( $this, 'hookGetPreferences' ); + } + + public function tearDown() { + global $wgHooks; + + if ( $this->mOldGetPreferencesHooks !== false ) { + $wgHooks['GetPreferences'] = $this->mOldGetPreferencesHooks; + $this->mOldGetPreferencesHooks = false; + } + + parent::tearDown(); + } + + public function hookGetPreferences( $user, &$preferences ) { + foreach ( array( 'name', 'willBeNull', 'willBeEmpty', 'willBeHappy' ) as $k ) { + $preferences[$k] = array( + 'type' => 'text', + 'section' => 'test', + 'label' => ' ', + ); + } + + return true; + } + + private function getSampleRequest( $custom = array() ) { + $request = array( + 'token' => '123ABC', + 'change' => null, + 'optionname' => null, + 'optionvalue' => null, + ); + return array_merge( $request, $custom ); + } + + private function executeQuery( $request ) { + $this->mContext->setRequest( new FauxRequest( $request, true, $this->mSession ) ); + $this->mTested->execute(); + return $this->mTested->getResult()->getData(); + } + + /** + * @expectedException UsageException + */ + public function testNoToken() { + $request = $this->getSampleRequest( array( 'token' => null ) ); + + $this->executeQuery( $request ); + } + + public function testAnon() { + $this->mUserMock->expects( $this->once() ) + ->method( 'isAnon' ) + ->will( $this->returnValue( true ) ); + + try { + $request = $this->getSampleRequest(); + + $this->executeQuery( $request ); + } catch ( UsageException $e ) { + $this->assertEquals( 'notloggedin', $e->getCodeString() ); + $this->assertEquals( 'Anonymous users cannot change preferences', $e->getMessage() ); + return; + } + $this->fail( "UsageException was not thrown" ); + } + + public function testNoOptionname() { + try { + $request = $this->getSampleRequest( array( 'optionvalue' => '1' ) ); + + $this->executeQuery( $request ); + } catch ( UsageException $e ) { + $this->assertEquals( 'nooptionname', $e->getCodeString() ); + $this->assertEquals( 'The optionname parameter must be set', $e->getMessage() ); + return; + } + $this->fail( "UsageException was not thrown" ); + } + + public function testNoChanges() { + $this->mUserMock->expects( $this->never() ) + ->method( 'resetOptions' ); + + $this->mUserMock->expects( $this->never() ) + ->method( 'setOption' ); + + $this->mUserMock->expects( $this->never() ) + ->method( 'saveSettings' ); + + try { + $request = $this->getSampleRequest(); + + $this->executeQuery( $request ); + } catch ( UsageException $e ) { + $this->assertEquals( 'nochanges', $e->getCodeString() ); + $this->assertEquals( 'No changes were requested', $e->getMessage() ); + return; + } + $this->fail( "UsageException was not thrown" ); + } + + public function testReset() { + $this->mUserMock->expects( $this->once() ) + ->method( 'resetOptions' ); + + $this->mUserMock->expects( $this->never() ) + ->method( 'setOption' ); + + $this->mUserMock->expects( $this->once() ) + ->method( 'saveSettings' ); + + $request = $this->getSampleRequest( array( 'reset' => '' ) ); + + $response = $this->executeQuery( $request ); + + $this->assertEquals( self::$Success, $response ); + } + + public function testOptionWithValue() { + $this->mUserMock->expects( $this->never() ) + ->method( 'resetOptions' ); + + $this->mUserMock->expects( $this->once() ) + ->method( 'setOption' ) + ->with( $this->equalTo( 'name' ), $this->equalTo( 'value' ) ); + + $this->mUserMock->expects( $this->once() ) + ->method( 'saveSettings' ); + + $request = $this->getSampleRequest( array( 'optionname' => 'name', 'optionvalue' => 'value' ) ); + + $response = $this->executeQuery( $request ); + + $this->assertEquals( self::$Success, $response ); + } + + public function testOptionResetValue() { + $this->mUserMock->expects( $this->never() ) + ->method( 'resetOptions' ); + + $this->mUserMock->expects( $this->once() ) + ->method( 'setOption' ) + ->with( $this->equalTo( 'name' ), $this->equalTo( null ) ); + + $this->mUserMock->expects( $this->once() ) + ->method( 'saveSettings' ); + + $request = $this->getSampleRequest( array( 'optionname' => 'name' ) ); + $response = $this->executeQuery( $request ); + + $this->assertEquals( self::$Success, $response ); + } + + public function testChange() { + $this->mUserMock->expects( $this->never() ) + ->method( 'resetOptions' ); + + $this->mUserMock->expects( $this->at( 1 ) ) + ->method( 'getOptions' ); + + $this->mUserMock->expects( $this->at( 2 ) ) + ->method( 'setOption' ) + ->with( $this->equalTo( 'willBeNull' ), $this->equalTo( null ) ); + + $this->mUserMock->expects( $this->at( 3 ) ) + ->method( 'getOptions' ); + + $this->mUserMock->expects( $this->at( 4 ) ) + ->method( 'setOption' ) + ->with( $this->equalTo( 'willBeEmpty' ), $this->equalTo( '' ) ); + + $this->mUserMock->expects( $this->at( 5 ) ) + ->method( 'getOptions' ); + + $this->mUserMock->expects( $this->at( 6 ) ) + ->method( 'setOption' ) + ->with( $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) ); + + $this->mUserMock->expects( $this->once() ) + ->method( 'saveSettings' ); + + $request = $this->getSampleRequest( array( 'change' => 'willBeNull|willBeEmpty=|willBeHappy=Happy' ) ); + + $response = $this->executeQuery( $request ); + + $this->assertEquals( self::$Success, $response ); + } + + public function testResetChangeOption() { + $this->mUserMock->expects( $this->once() ) + ->method( 'resetOptions' ); + + $this->mUserMock->expects( $this->at( 2 ) ) + ->method( 'getOptions' ); + + $this->mUserMock->expects( $this->at( 3 ) ) + ->method( 'setOption' ) + ->with( $this->equalTo( 'willBeHappy' ), $this->equalTo( 'Happy' ) ); + + $this->mUserMock->expects( $this->at( 4 ) ) + ->method( 'getOptions' ); + + $this->mUserMock->expects( $this->at( 5 ) ) + ->method( 'setOption' ) + ->with( $this->equalTo( 'name' ), $this->equalTo( 'value' ) ); + + $this->mUserMock->expects( $this->once() ) + ->method( 'saveSettings' ); + + $args = array( + 'reset' => '', + 'change' => 'willBeHappy=Happy', + 'optionname' => 'name', + 'optionvalue' => 'value' + ); + + $response = $this->executeQuery( $this->getSampleRequest( $args ) ); + + $this->assertEquals( self::$Success, $response ); + } +} diff --git a/tests/phpunit/includes/api/ApiPurgeTest.php b/tests/phpunit/includes/api/ApiPurgeTest.php index 70c20746..2566c6cd 100644 --- a/tests/phpunit/includes/api/ApiPurgeTest.php +++ b/tests/phpunit/includes/api/ApiPurgeTest.php @@ -1,6 +1,7 @@ new ApiTestUser( + 'sysop' => new TestUser( 'Apitestsysop', 'Api Test Sysop', 'api_test_sysop@example.com', array( 'sysop' ) ), - 'uploader' => new ApiTestUser( + 'uploader' => new TestUser( 'Apitestuser', 'Api Test User', 'api_test_user@example.com', @@ -43,15 +39,31 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { } - protected function doApiRequest( $params, $session = null, $appendModule = false, $user = null ) { + protected function doApiRequest( Array $params, Array $session = null, $appendModule = false, User $user = null ) { + global $wgRequest, $wgUser; + if ( is_null( $session ) ) { - $session = array(); + # re-use existing global session by default + $session = $wgRequest->getSessionArray(); } - $context = $this->apiContext->newTestContext( $params, $session, $user ); + # set up global environment + if ( $user ) { + $wgUser = $user; + } + + $wgRequest = new FauxRequest( $params, true, $session ); + RequestContext::getMain()->setRequest( $wgRequest ); + + # set up local environment + $context = $this->apiContext->newTestContext( $wgRequest, $wgUser ); + $module = new ApiMain( $context, true ); + + # run it! $module->execute(); + # construct result $results = array( $module->getResultData(), $context->getRequest(), @@ -68,11 +80,17 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { * Add an edit token to the API request * This is cheating a bit -- we grab a token in the correct format and then add it to the pseudo-session and to the * request, without actually requesting a "real" edit token - * @param $params: key-value API params - * @param $session: session array - * @param $user String|null A User object for the context + * @param $params Array: key-value API params + * @param $session Array|null: session array + * @param $user User|null A User object for the context */ - protected function doApiRequestWithToken( $params, $session, $user = null ) { + protected function doApiRequestWithToken( Array $params, Array $session = null, User $user = null ) { + global $wgRequest; + + if ( $session === null ) { + $session = $wgRequest->getSessionArray(); + } + if ( $session['wsToken'] ) { // add edit token to fake session $session['wsEditToken'] = $session['wsToken']; @@ -97,17 +115,17 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { 'lgtoken' => $token, 'lgname' => self::$users['sysop']->username, 'lgpassword' => self::$users['sysop']->password - ), $data ); + ), $data[2] ); return $data; } - protected function getTokenList( $user ) { + protected function getTokenList( $user, $session = null ) { $data = $this->doApiRequest( array( 'action' => 'query', 'titles' => 'Main Page', - 'intoken' => 'edit|delete|protect|move|block|unblock', - 'prop' => 'info' ), false, $user->user ); + 'intoken' => 'edit|delete|protect|move|block|unblock|watch', + 'prop' => 'info' ), $session, false, $user->user ); return $data; } } @@ -154,14 +172,13 @@ class ApiTestContext extends RequestContext { /** * Returns a DerivativeContext with the request variables in place * - * @param $params Array key-value API params - * @param $session Array session data + * @param $request WebRequest request object including parameters and session * @param $user User or null * @return DerivativeContext */ - public function newTestContext( $params, $session, $user = null ) { + public function newTestContext( WebRequest $request, User $user = null ) { $context = new DerivativeContext( $this ); - $context->setRequest( new FauxRequest( $params, true, $session ) ); + $context->setRequest( $request ); if ( $user !== null ) { $context->setUser( $user ); } diff --git a/tests/phpunit/includes/api/ApiTestUser.php b/tests/phpunit/includes/api/ApiTestUser.php deleted file mode 100644 index 8d5f61a7..00000000 --- a/tests/phpunit/includes/api/ApiTestUser.php +++ /dev/null @@ -1,59 +0,0 @@ -username = $username; - $this->realname = $realname; - $this->email = $email; - $this->groups = $groups; - - // don't allow user to hardcode or select passwords -- people sometimes run tests - // on live wikis. Sometimes we create sysop users in these tests. A sysop user with - // a known password would be a Bad Thing. - $this->password = User::randomPassword(); - - $this->user = User::newFromName( $this->username ); - $this->user->load(); - - // In an ideal world we'd have a new wiki (or mock data store) for every single test. - // But for now, we just need to create or update the user with the desired properties. - // we particularly need the new password, since we just generated it randomly. - // In core MediaWiki, there is no functionality to delete users, so this is the best we can do. - if ( !$this->user->getID() ) { - // create the user - $this->user = User::createNew( - $this->username, array( - "email" => $this->email, - "real_name" => $this->realname - ) - ); - if ( !$this->user ) { - throw new Exception( "error creating user" ); - } - } - - // update the user to use the new random password and other details - $this->user->setPassword( $this->password ); - $this->user->setEmail( $this->email ); - $this->user->setRealName( $this->realname ); - // remove all groups, replace with any groups specified - foreach ( $this->user->getGroups() as $group ) { - $this->user->removeGroup( $group ); - } - if ( count( $this->groups ) ) { - foreach ( $this->groups as $group ) { - $this->user->addGroup( $group ); - } - } - $this->user->saveSettings(); - - } - -} diff --git a/tests/phpunit/includes/api/ApiUploadTest.php b/tests/phpunit/includes/api/ApiUploadTest.php index 7a700326..642fed05 100644 --- a/tests/phpunit/includes/api/ApiUploadTest.php +++ b/tests/phpunit/includes/api/ApiUploadTest.php @@ -1,6 +1,7 @@ doLogin(); } - + function getTokens() { - return $this->getTokenList( self::$users['sysop'] ); + $data = $this->getTokenList( self::$users['sysop'] ); + + $keys = array_keys( $data[0]['query']['pages'] ); + $key = array_pop( $keys ); + $pageinfo = $data[0]['query']['pages'][$key]; + + return $pageinfo; } /** - * @group Broken */ function testWatchEdit() { - - $data = $this->getTokens(); - - $keys = array_keys( $data[0]['query']['pages'] ); - $key = array_pop( $keys ); - $pageinfo = $data[0]['query']['pages'][$key]; + $pageinfo = $this->getTokens(); $data = $this->doApiRequest( array( 'action' => 'edit', 'title' => 'UTPage', 'text' => 'new text', 'token' => $pageinfo['edittoken'], - 'watchlist' => 'watch' ), $data ); + 'watchlist' => 'watch' ) ); $this->assertArrayHasKey( 'edit', $data[0] ); $this->assertArrayHasKey( 'result', $data[0]['edit'] ); $this->assertEquals( 'Success', $data[0]['edit']['result'] ); @@ -41,13 +42,14 @@ class ApiWatchTest extends ApiTestCase { /** * @depends testWatchEdit - * @group Broken */ function testWatchClear() { - + + $pageinfo = $this->getTokens(); + $data = $this->doApiRequest( array( 'action' => 'query', - 'list' => 'watchlist' ), $data ); + 'list' => 'watchlist' ) ); if ( isset( $data[0]['query']['watchlist'] ) ) { $wl = $data[0]['query']['watchlist']; @@ -56,7 +58,8 @@ class ApiWatchTest extends ApiTestCase { $data = $this->doApiRequest( array( 'action' => 'watch', 'title' => $page['title'], - 'unwatch' => true ), $data ); + 'unwatch' => true, + 'token' => $pageinfo['watchtoken'] ) ); } } $data = $this->doApiRequest( array( @@ -70,22 +73,17 @@ class ApiWatchTest extends ApiTestCase { } /** - * @group Broken - */ + */ function testWatchProtect() { - - $data = $this->getTokens(); - - $keys = array_keys( $data[0]['query']['pages'] ); - $key = array_pop( $keys ); - $pageinfo = $data[0]['query']['pages'][$key]; + + $pageinfo = $this->getTokens(); $data = $this->doApiRequest( array( 'action' => 'protect', 'token' => $pageinfo['protecttoken'], 'title' => 'UTPage', 'protections' => 'edit=sysop', - 'watchlist' => 'unwatch' ), $data ); + 'watchlist' => 'unwatch' ) ); $this->assertArrayHasKey( 'protect', $data[0] ); $this->assertArrayHasKey( 'protections', $data[0]['protect'] ); @@ -94,21 +92,20 @@ class ApiWatchTest extends ApiTestCase { } /** - * @group Broken */ function testGetRollbackToken() { - - $data = $this->getTokens(); - + + $pageinfo = $this->getTokens(); + if ( !Title::newFromText( 'UTPage' )->exists() ) { - $this->markTestIncomplete( "The article [[UTPage]] does not exist" ); + $this->markTestSkipped( "The article [[UTPage]] does not exist" ); //TODO: just create it? } $data = $this->doApiRequest( array( 'action' => 'query', 'prop' => 'revisions', 'titles' => 'UTPage', - 'rvtoken' => 'rollback' ), $data ); + 'rvtoken' => 'rollback' ) ); $this->assertArrayHasKey( 'query', $data[0] ); $this->assertArrayHasKey( 'pages', $data[0]['query'] ); @@ -116,7 +113,7 @@ class ApiWatchTest extends ApiTestCase { $key = array_pop( $keys ); if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) { - $this->markTestIncomplete( "Target page (UTPage) doesn't exist" ); + $this->markTestSkipped( "Target page (UTPage) doesn't exist" ); } $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] ); @@ -128,21 +125,27 @@ class ApiWatchTest extends ApiTestCase { } /** - * @depends testGetRollbackToken * @group Broken + * Broken because there is currently no revision info in the $pageinfo + * + * @depends testGetRollbackToken */ function testWatchRollback( $data ) { $keys = array_keys( $data[0]['query']['pages'] ); $key = array_pop( $keys ); - $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0]; + $pageinfo = $data[0]['query']['pages'][$key]; + $revinfo = $pageinfo['revisions'][0]; try { $data = $this->doApiRequest( array( 'action' => 'rollback', 'title' => 'UTPage', - 'user' => $pageinfo['user'], + 'user' => $revinfo['user'], 'token' => $pageinfo['rollbacktoken'], - 'watchlist' => 'watch' ), $data ); + 'watchlist' => 'watch' ) ); + + $this->assertArrayHasKey( 'rollback', $data[0] ); + $this->assertArrayHasKey( 'title', $data[0]['rollback'] ); } catch( UsageException $ue ) { if( $ue->getCodeString() == 'onlyauthor' ) { $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" ); @@ -150,32 +153,23 @@ class ApiWatchTest extends ApiTestCase { $this->fail( "Received error '" . $ue->getCodeString() . "'" ); } } - - $this->assertArrayHasKey( 'rollback', $data[0] ); - $this->assertArrayHasKey( 'title', $data[0]['rollback'] ); } /** - * @group Broken */ function testWatchDelete() { - - $data = $this->getTokens(); - - $keys = array_keys( $data[0]['query']['pages'] ); - $key = array_pop( $keys ); - $pageinfo = $data[0]['query']['pages'][$key]; + $pageinfo = $this->getTokens(); $data = $this->doApiRequest( array( 'action' => 'delete', 'token' => $pageinfo['deletetoken'], - 'title' => 'UTPage' ), $data ); + 'title' => 'UTPage' ) ); $this->assertArrayHasKey( 'delete', $data[0] ); $this->assertArrayHasKey( 'title', $data[0]['delete'] ); $data = $this->doApiRequest( array( 'action' => 'query', - 'list' => 'watchlist' ), $data ); + 'list' => 'watchlist' ) ); $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' ); } diff --git a/tests/phpunit/includes/api/PrefixUniquenessTest.php b/tests/phpunit/includes/api/PrefixUniquenessTest.php new file mode 100644 index 00000000..69b01ea7 --- /dev/null +++ b/tests/phpunit/includes/api/PrefixUniquenessTest.php @@ -0,0 +1,24 @@ +getModules(); + $prefixes = array(); + + foreach ( $modules as $name => $class ) { + $module = new $class( $main, $name ); + $prefix = $module->getModulePrefix(); + if ( isset( $prefixes[$prefix] ) ) { + $this->fail( "Module prefix '{$prefix}' is shared between {$class} and {$prefixes[$prefix]}" ); + } + $prefixes[$module->getModulePrefix()] = $class; + } + $this->assertTrue( true ); // dummy call to make this test non-incomplete + } +} diff --git a/tests/phpunit/includes/api/RandomImageGenerator.php b/tests/phpunit/includes/api/RandomImageGenerator.php index 86c0a828..8b6a3849 100644 --- a/tests/phpunit/includes/api/RandomImageGenerator.php +++ b/tests/phpunit/includes/api/RandomImageGenerator.php @@ -79,7 +79,7 @@ class RandomImageGenerator { foreach ( array( '/usr/share/dict/words', '/usr/dict/words', - dirname( __FILE__ ) . '/words.txt' ) + __DIR__ . '/words.txt' ) as $dictionaryFile ) { if ( is_file( $dictionaryFile ) and is_readable( $dictionaryFile ) ) { $this->dictionaryFile = $dictionaryFile; diff --git a/tests/phpunit/includes/api/generateRandomImages.php b/tests/phpunit/includes/api/generateRandomImages.php index f3a14e5b..ee345623 100644 --- a/tests/phpunit/includes/api/generateRandomImages.php +++ b/tests/phpunit/includes/api/generateRandomImages.php @@ -6,14 +6,18 @@ */ // Evaluate the include path relative to this file -$IP = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ); +$IP = dirname( dirname( dirname( dirname( __DIR__ ) ) ) ); // Start up MediaWiki in command-line mode require_once( "$IP/maintenance/Maintenance.php" ); -require("RandomImageGenerator.php"); +require( __DIR__ . "/RandomImageGenerator.php" ); class GenerateRandomImages extends Maintenance { + public function getDbType() { + return Maintenance::DB_NONE; + } + public function execute() { $getOptSpec = array( -- cgit v1.2.3-54-g00ecf