aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiWatchTest.php
diff options
context:
space:
mode:
authorAmmarpad <ammarpad@yahoo.com>2021-02-02 17:21:52 +0100
committerAmmarpad <ammarpad@yahoo.com>2021-02-02 22:22:03 +0100
commit63951ea911f56a499a34a3f3d68decfcd3a3bf9b (patch)
tree59955e59bbc546b50e293c5d7c024b408ebbf59c /tests/phpunit/includes/api/ApiWatchTest.php
parentcf33d0b185a4a7bf0909fdd81cea61923903b123 (diff)
downloadmediawikicore-63951ea911f56a499a34a3f3d68decfcd3a3bf9b.tar.gz
mediawikicore-63951ea911f56a499a34a3f3d68decfcd3a3bf9b.zip
Fix and re-enable broken ApiWatch test
This was disabled since 2011. Bug: T273603 Change-Id: Ia28db2e1cf5cb2353ad1782be9634b654a009c14
Diffstat (limited to 'tests/phpunit/includes/api/ApiWatchTest.php')
-rw-r--r--tests/phpunit/includes/api/ApiWatchTest.php51
1 files changed, 23 insertions, 28 deletions
diff --git a/tests/phpunit/includes/api/ApiWatchTest.php b/tests/phpunit/includes/api/ApiWatchTest.php
index c6ab9323f489..fa141e382e92 100644
--- a/tests/phpunit/includes/api/ApiWatchTest.php
+++ b/tests/phpunit/includes/api/ApiWatchTest.php
@@ -192,8 +192,10 @@ class ApiWatchTest extends ApiTestCase {
}
public function testGetRollbackToken() {
- // Needs to be here to have rollback-able edit by a different user
- $this->editPage( 'Help:UTPage', __FUNCTION__, '', NS_HELP, $this->getTestUser()->getUser() );
+ // Needs to be here to make sure the page definitely exists and to have
+ // rollback-able edit by a different user for the testWatchRollback() below.
+ $this->editPage( 'UTPage', __FUNCTION__, '', NS_HELP, $this->getTestUser()->getUser() );
+
$contextUser = self::$users['sysop']->getUser();
$data = $this->doApiRequest( [
@@ -219,33 +221,26 @@ class ApiWatchTest extends ApiTestCase {
}
/**
- * @group Broken
- * Broken because there is currently no revision info in the $pageinfo
- *
* @depends testGetRollbackToken
*/
- public function testWatchRollback( $data ) {
- $keys = array_keys( $data[0]['query']['pages'] );
- $key = array_pop( $keys );
- $pageinfo = $data[0]['query']['pages'][$key];
- $revinfo = $pageinfo['revisions'][0];
-
- try {
- $data = $this->doApiRequest( [
- 'action' => 'rollback',
- 'title' => 'Help:UTPage',
- 'user' => $revinfo['user'],
- 'token' => $pageinfo['rollbacktoken'],
- 'watchlist' => 'watch' ] );
-
- $this->assertArrayHasKey( 'rollback', $data[0] );
- $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
- } catch ( ApiUsageException $ue ) {
- if ( self::apiExceptionHasCode( $ue, 'onlyauthor' ) ) {
- $this->markTestIncomplete( "Only one author to 'Help:UTPage', cannot test rollback" );
- } else {
- $this->fail( "Received error '" . $ue->getMessage() . "'" );
- }
- }
+ public function testWatchRollback( $info ) {
+ list( $data, $revInfo, $contextUser ) = $info;
+
+ $title = Title::makeTitle( NS_HELP, 'UTPage' );
+
+ // This (and assertTrue below) are mostly for completeness.
+ $this->assertFalse( $contextUser->isWatched( $title ) );
+
+ $data = $this->doApiRequest( [
+ 'action' => 'rollback',
+ 'title' => 'Help:UTPage',
+ 'user' => $revInfo['user'],
+ 'token' => $contextUser->getEditToken( 'rollback' ),
+ 'watchlist' => 'watch'
+ ] );
+
+ $this->assertArrayHasKey( 'rollback', $data[0] );
+ $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
+ $this->assertTrue( $contextUser->isWatched( $title ) );
}
}