7 * @todo This test suite is severly broken and need a full review
11 class ApiWatchTest
extends ApiTestCase
{
12 function getTokens() {
13 return $this->getTokenList( self
::$users['sysop'] );
16 public function testWatchEdit() {
17 $tokens = $this->getTokens();
19 $data = $this->doApiRequest( [
21 'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
23 'token' => $tokens['edittoken'],
24 'watchlist' => 'watch' ] );
25 $this->assertArrayHasKey( 'edit', $data[0] );
26 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
27 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
33 * @depends testWatchEdit
35 public function testWatchClear() {
36 $tokens = $this->getTokens();
38 $data = $this->doApiRequest( [
41 'list' => 'watchlist' ] );
43 if ( isset( $data[0]['query']['watchlist'] ) ) {
44 $wl = $data[0]['query']['watchlist'];
46 foreach ( $wl as $page ) {
47 $data = $this->doApiRequest( [
49 'title' => $page['title'],
51 'token' => $tokens['watchtoken'] ] );
54 $data = $this->doApiRequest( [
56 'list' => 'watchlist' ], $data );
57 $this->assertArrayHasKey( 'query', $data[0] );
58 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
59 foreach ( $data[0]['query']['watchlist'] as $index => $item ) {
60 // Previous tests may insert an invalid title
61 // like ":ApiEditPageTest testNonTextEdit", which
63 if ( strpos( $item['title'], ':' ) === 0 ) {
64 unset( $data[0]['query']['watchlist'][$index] );
67 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
72 public function testWatchProtect() {
73 $tokens = $this->getTokens();
75 $data = $this->doApiRequest( [
76 'action' => 'protect',
77 'token' => $tokens['protecttoken'],
78 'title' => 'Help:UTPage',
79 'protections' => 'edit=sysop',
80 'watchlist' => 'unwatch' ] );
82 $this->assertArrayHasKey( 'protect', $data[0] );
83 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
84 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
85 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
88 public function testGetRollbackToken() {
91 if ( !Title
::newFromText( 'Help:UTPage' )->exists() ) {
92 $this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); // TODO: just create it?
95 $data = $this->doApiRequest( [
97 'prop' => 'revisions',
98 'titles' => 'Help:UTPage',
99 'rvtoken' => 'rollback' ] );
101 $this->assertArrayHasKey( 'query', $data[0] );
102 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
103 $keys = array_keys( $data[0]['query']['pages'] );
104 $key = array_pop( $keys );
106 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
107 $this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" );
110 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
111 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
112 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
113 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
120 * Broken because there is currently no revision info in the $pageinfo
122 * @depends testGetRollbackToken
124 public function testWatchRollback( $data ) {
125 $keys = array_keys( $data[0]['query']['pages'] );
126 $key = array_pop( $keys );
127 $pageinfo = $data[0]['query']['pages'][$key];
128 $revinfo = $pageinfo['revisions'][0];
131 $data = $this->doApiRequest( [
132 'action' => 'rollback',
133 'title' => 'Help:UTPage',
134 'user' => $revinfo['user'],
135 'token' => $pageinfo['rollbacktoken'],
136 'watchlist' => 'watch' ] );
138 $this->assertArrayHasKey( 'rollback', $data[0] );
139 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
140 } catch ( ApiUsageException
$ue ) {
141 if ( self
::apiExceptionHasCode( $ue, 'onlyauthor' ) ) {
142 $this->markTestIncomplete( "Only one author to 'Help:UTPage', cannot test rollback" );
144 $this->fail( "Received error '" . $ue->getMessage() . "'" );