Merge "mw.loader: Guard against odd setTimeout behaviour in old Firefox"
[mediawiki.git] / tests / phpunit / includes / api / ApiWatchTest.php
blobaefd93986203b6915910558ba7c742b3aa3caae2
1 <?php
3 /**
4 * @group API
5 * @group Database
6 * @group medium
7 * @todo This test suite is severly broken and need a full review
8 */
9 class ApiWatchTest extends ApiTestCase {
11 protected function setUp() {
12 parent::setUp();
13 $this->doLogin();
16 function getTokens() {
17 $data = $this->getTokenList( self::$users['sysop'] );
19 $keys = array_keys( $data[0]['query']['pages'] );
20 $key = array_pop( $keys );
21 $pageinfo = $data[0]['query']['pages'][$key];
23 return $pageinfo;
26 /**
28 function testWatchEdit() {
29 $pageinfo = $this->getTokens();
31 $data = $this->doApiRequest( array(
32 'action' => 'edit',
33 'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
34 'text' => 'new text',
35 'token' => $pageinfo['edittoken'],
36 'watchlist' => 'watch' ) );
37 $this->assertArrayHasKey( 'edit', $data[0] );
38 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
39 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
41 return $data;
44 /**
45 * @depends testWatchEdit
47 function testWatchClear() {
49 $pageinfo = $this->getTokens();
51 $data = $this->doApiRequest( array(
52 'action' => 'query',
53 'list' => 'watchlist' ) );
55 if ( isset( $data[0]['query']['watchlist'] ) ) {
56 $wl = $data[0]['query']['watchlist'];
58 foreach ( $wl as $page ) {
59 $data = $this->doApiRequest( array(
60 'action' => 'watch',
61 'title' => $page['title'],
62 'unwatch' => true,
63 'token' => $pageinfo['watchtoken'] ) );
66 $data = $this->doApiRequest( array(
67 'action' => 'query',
68 'list' => 'watchlist' ), $data );
69 $this->assertArrayHasKey( 'query', $data[0] );
70 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
71 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
73 return $data;
76 /**
78 function testWatchProtect() {
80 $pageinfo = $this->getTokens();
82 $data = $this->doApiRequest( array(
83 'action' => 'protect',
84 'token' => $pageinfo['protecttoken'],
85 'title' => 'Help:UTPage',
86 'protections' => 'edit=sysop',
87 'watchlist' => 'unwatch' ) );
89 $this->assertArrayHasKey( 'protect', $data[0] );
90 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
91 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
92 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
95 /**
97 function testGetRollbackToken() {
99 $pageinfo = $this->getTokens();
101 if ( !Title::newFromText( 'Help:UTPage' )->exists() ) {
102 $this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); //TODO: just create it?
105 $data = $this->doApiRequest( array(
106 'action' => 'query',
107 'prop' => 'revisions',
108 'titles' => 'Help:UTPage',
109 'rvtoken' => 'rollback' ) );
111 $this->assertArrayHasKey( 'query', $data[0] );
112 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
113 $keys = array_keys( $data[0]['query']['pages'] );
114 $key = array_pop( $keys );
116 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
117 $this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" );
120 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
121 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
122 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
123 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
125 return $data;
129 * @group Broken
130 * Broken because there is currently no revision info in the $pageinfo
132 * @depends testGetRollbackToken
134 function testWatchRollback( $data ) {
135 $keys = array_keys( $data[0]['query']['pages'] );
136 $key = array_pop( $keys );
137 $pageinfo = $data[0]['query']['pages'][$key];
138 $revinfo = $pageinfo['revisions'][0];
140 try {
141 $data = $this->doApiRequest( array(
142 'action' => 'rollback',
143 'title' => 'Help:UTPage',
144 'user' => $revinfo['user'],
145 'token' => $pageinfo['rollbacktoken'],
146 'watchlist' => 'watch' ) );
148 $this->assertArrayHasKey( 'rollback', $data[0] );
149 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
150 } catch ( UsageException $ue ) {
151 if ( $ue->getCodeString() == 'onlyauthor' ) {
152 $this->markTestIncomplete( "Only one author to 'Help:UTPage', cannot test rollback" );
153 } else {
154 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
161 function testWatchDelete() {
162 $pageinfo = $this->getTokens();
164 $data = $this->doApiRequest( array(
165 'action' => 'delete',
166 'token' => $pageinfo['deletetoken'],
167 'title' => 'Help:UTPage' ) );
168 $this->assertArrayHasKey( 'delete', $data[0] );
169 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
171 $data = $this->doApiRequest( array(
172 'action' => 'query',
173 'list' => 'watchlist' ) );
175 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );