5 * @todo This test suite is severly broken and need a full review
7 class ApiWatchTest
extends ApiTestCase
{
14 function getTokens() {
15 return $this->getTokenList( self
::$users['sysop'] );
21 function testWatchEdit() {
23 $data = $this->getTokens();
25 $keys = array_keys( $data[0]['query']['pages'] );
26 $key = array_pop( $keys );
27 $pageinfo = $data[0]['query']['pages'][$key];
29 $data = $this->doApiRequest( array(
33 'token' => $pageinfo['edittoken'],
34 'watchlist' => 'watch' ), $data );
35 $this->assertArrayHasKey( 'edit', $data[0] );
36 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
37 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
43 * @depends testWatchEdit
45 function testWatchClear() {
47 $data = $this->doApiRequest( array(
49 'list' => 'watchlist' ), $data );
51 if ( isset( $data[0]['query']['watchlist'] ) ) {
52 $wl = $data[0]['query']['watchlist'];
54 foreach ( $wl as $page ) {
55 $data = $this->doApiRequest( array(
57 'title' => $page['title'],
58 'unwatch' => true ), $data );
61 $data = $this->doApiRequest( array(
63 'list' => 'watchlist' ), $data );
64 $this->assertArrayHasKey( 'query', $data[0] );
65 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
66 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
74 function testWatchProtect() {
76 $data = $this->getTokens();
78 $keys = array_keys( $data[0]['query']['pages'] );
79 $key = array_pop( $keys );
80 $pageinfo = $data[0]['query']['pages'][$key];
82 $data = $this->doApiRequest( array(
83 'action' => 'protect',
84 'token' => $pageinfo['protecttoken'],
86 'protections' => 'edit=sysop',
87 'watchlist' => 'unwatch' ), $data );
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] );
96 function testGetRollbackToken() {
98 $data = $this->getTokens();
100 if ( !Title
::newFromText( 'UTPage' )->exists() ) {
101 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
104 $data = $this->doApiRequest( array(
106 'prop' => 'revisions',
107 'titles' => 'UTPage',
108 'rvtoken' => 'rollback' ), $data );
110 $this->assertArrayHasKey( 'query', $data[0] );
111 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
112 $keys = array_keys( $data[0]['query']['pages'] );
113 $key = array_pop( $keys );
115 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
116 $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
119 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
120 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
121 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
122 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
128 * @depends testGetRollbackToken
131 function testWatchRollback( $data ) {
132 $keys = array_keys( $data[0]['query']['pages'] );
133 $key = array_pop( $keys );
134 $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
137 $data = $this->doApiRequest( array(
138 'action' => 'rollback',
140 'user' => $pageinfo['user'],
141 'token' => $pageinfo['rollbacktoken'],
142 'watchlist' => 'watch' ), $data );
143 } catch( UsageException
$ue ) {
144 if( $ue->getCodeString() == 'onlyauthor' ) {
145 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
147 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
151 $this->assertArrayHasKey( 'rollback', $data[0] );
152 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
158 function testWatchDelete() {
160 $data = $this->getTokens();
162 $keys = array_keys( $data[0]['query']['pages'] );
163 $key = array_pop( $keys );
164 $pageinfo = $data[0]['query']['pages'][$key];
166 $data = $this->doApiRequest( array(
167 'action' => 'delete',
168 'token' => $pageinfo['deletetoken'],
169 'title' => 'UTPage' ), $data );
170 $this->assertArrayHasKey( 'delete', $data[0] );
171 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
173 $data = $this->doApiRequest( array(
175 'list' => 'watchlist' ), $data );
177 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );