diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2021-02-02 18:26:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2021-02-02 18:26:06 +0000 |
commit | cf33d0b185a4a7bf0909fdd81cea61923903b123 (patch) | |
tree | 0747614739ad4a34261430a52982a3d0d94e4e01 /tests/phpunit/includes/api/ApiWatchTest.php | |
parent | 8214c9381bf991d14e94ebb8194bf40c6ed0ed66 (diff) | |
parent | a944bc6b6ba3fb3f59501abaf733338682fe29b3 (diff) | |
download | mediawikicore-cf33d0b185a4a7bf0909fdd81cea61923903b123.tar.gz mediawikicore-cf33d0b185a4a7bf0909fdd81cea61923903b123.zip |
Merge "Improve ApiWatchTest"
Diffstat (limited to 'tests/phpunit/includes/api/ApiWatchTest.php')
-rw-r--r-- | tests/phpunit/includes/api/ApiWatchTest.php | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/tests/phpunit/includes/api/ApiWatchTest.php b/tests/phpunit/includes/api/ApiWatchTest.php index 1e0184fa4c76..c6ab9323f489 100644 --- a/tests/phpunit/includes/api/ApiWatchTest.php +++ b/tests/phpunit/includes/api/ApiWatchTest.php @@ -24,11 +24,6 @@ class ApiWatchTest extends ApiTestCase { ] ); } - protected function tearDown(): void { - ConvertibleTimestamp::setFakeTime( false ); - parent::tearDown(); - } - protected function getTokens() { return $this->getTokenList( self::$users['sysop'] ); } @@ -96,10 +91,10 @@ class ApiWatchTest extends ApiTestCase { } public function testWatchInvalidExpiry() { - $this->expectException( ApiUsageException::class ); - $this->expectExceptionMessage( - 'Invalid value "invalid expiry" for expiry parameter "expiry".' - ); + $this->setExpectedApiException( [ + 'paramvalidator-badexpiry', 'expiry', 'invalid expiry', + ] ); + $this->doApiRequestWithToken( [ 'action' => 'watch', 'titles' => 'Talk:Test page', @@ -109,10 +104,10 @@ class ApiWatchTest extends ApiTestCase { } public function testWatchExpiryInPast() { - $this->expectException( ApiUsageException::class ); - $this->expectExceptionMessage( - 'Value "20010101000000" for expiry parameter "expiry" is in the past.' - ); + $this->setExpectedApiException( [ + 'paramvalidator-badexpiry-past', 'expiry', '20010101000000', + ] ); + $this->doApiRequestWithToken( [ 'action' => 'watch', 'titles' => 'Talk:Test page', @@ -129,7 +124,9 @@ class ApiWatchTest extends ApiTestCase { 'title' => 'Help:UTPage', // Help namespace is hopefully wikitext 'text' => 'new text', 'token' => $tokens['edittoken'], - 'watchlist' => 'watch' ] ); + 'watchlist' => 'watch' + ] ); + $this->assertArrayHasKey( 'edit', $data[0] ); $this->assertArrayHasKey( 'result', $data[0]['edit'] ); $this->assertEquals( 'Success', $data[0]['edit']['result'] ); @@ -185,7 +182,8 @@ class ApiWatchTest extends ApiTestCase { 'token' => $tokens['protecttoken'], 'title' => 'Help:UTPage', 'protections' => 'edit=sysop', - 'watchlist' => 'unwatch' ] ); + 'watchlist' => 'unwatch' + ] ); $this->assertArrayHasKey( 'protect', $data[0] ); $this->assertArrayHasKey( 'protections', $data[0]['protect'] ); @@ -194,33 +192,30 @@ class ApiWatchTest extends ApiTestCase { } public function testGetRollbackToken() { - $this->getTokens(); - - if ( !Title::newFromText( 'Help:UTPage' )->exists() ) { - $this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); // TODO: just create it? - } + // Needs to be here to have rollback-able edit by a different user + $this->editPage( 'Help:UTPage', __FUNCTION__, '', NS_HELP, $this->getTestUser()->getUser() ); + $contextUser = self::$users['sysop']->getUser(); $data = $this->doApiRequest( [ 'action' => 'query', 'prop' => 'revisions', 'titles' => 'Help:UTPage', - 'rvtoken' => 'rollback' ] ); + 'rvtoken' => 'rollback' + ], null, null, $contextUser ); $this->assertArrayHasKey( 'query', $data[0] ); $this->assertArrayHasKey( 'pages', $data[0]['query'] ); $keys = array_keys( $data[0]['query']['pages'] ); $key = array_pop( $keys ); + $pageInfo = $data[0]['query']['pages'][$key]; + $revInfo = $pageInfo['revisions'][0]; - if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) { - $this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" ); - } - - $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] ); - $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] ); - $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] ); - $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] ); + $this->assertArrayHasKey( 'pageid', $pageInfo ); + $this->assertArrayHasKey( 'revisions', $pageInfo ); + $this->assertArrayHasKey( 0, $pageInfo['revisions'] ); + $this->assertArrayHasKey( 'rollbacktoken', $revInfo ); - return $data; + return [ $data, $revInfo, $contextUser ]; } /** |