6 * @todo This test suite is severly broken and need a full review
8 class ApiWatchTest
extends ApiTestCase
{
15 function getTokens() {
16 return $this->getTokenList( self
::$users['sysop'] );
22 function testWatchEdit() {
24 $data = $this->getTokens();
26 $keys = array_keys( $data[0]['query']['pages'] );
27 $key = array_pop( $keys );
28 $pageinfo = $data[0]['query']['pages'][$key];
30 $data = $this->doApiRequest( array(
34 'token' => $pageinfo['edittoken'],
35 'watchlist' => 'watch' ), $data );
36 $this->assertArrayHasKey( 'edit', $data[0] );
37 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
38 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
44 * @depends testWatchEdit
47 function testWatchClear() {
49 $data = $this->doApiRequest( array(
51 'list' => 'watchlist' ), $data );
53 if ( isset( $data[0]['query']['watchlist'] ) ) {
54 $wl = $data[0]['query']['watchlist'];
56 foreach ( $wl as $page ) {
57 $data = $this->doApiRequest( array(
59 'title' => $page['title'],
60 'unwatch' => true ), $data );
63 $data = $this->doApiRequest( array(
65 'list' => 'watchlist' ), $data );
66 $this->assertArrayHasKey( 'query', $data[0] );
67 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
68 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
76 function testWatchProtect() {
78 $data = $this->getTokens();
80 $keys = array_keys( $data[0]['query']['pages'] );
81 $key = array_pop( $keys );
82 $pageinfo = $data[0]['query']['pages'][$key];
84 $data = $this->doApiRequest( array(
85 'action' => 'protect',
86 'token' => $pageinfo['protecttoken'],
88 'protections' => 'edit=sysop',
89 'watchlist' => 'unwatch' ), $data );
91 $this->assertArrayHasKey( 'protect', $data[0] );
92 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
93 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
94 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
100 function testGetRollbackToken() {
102 $data = $this->getTokens();
104 if ( !Title
::newFromText( 'UTPage' )->exists() ) {
105 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
108 $data = $this->doApiRequest( array(
110 'prop' => 'revisions',
111 'titles' => 'UTPage',
112 'rvtoken' => 'rollback' ), $data );
114 $this->assertArrayHasKey( 'query', $data[0] );
115 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
116 $keys = array_keys( $data[0]['query']['pages'] );
117 $key = array_pop( $keys );
119 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
120 $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
123 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
124 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
125 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
126 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
132 * @depends testGetRollbackToken
135 function testWatchRollback( $data ) {
136 $keys = array_keys( $data[0]['query']['pages'] );
137 $key = array_pop( $keys );
138 $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
141 $data = $this->doApiRequest( array(
142 'action' => 'rollback',
144 'user' => $pageinfo['user'],
145 'token' => $pageinfo['rollbacktoken'],
146 'watchlist' => 'watch' ), $data );
147 } catch( UsageException
$ue ) {
148 if( $ue->getCodeString() == 'onlyauthor' ) {
149 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
151 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
155 $this->assertArrayHasKey( 'rollback', $data[0] );
156 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
162 function testWatchDelete() {
164 $data = $this->getTokens();
166 $keys = array_keys( $data[0]['query']['pages'] );
167 $key = array_pop( $keys );
168 $pageinfo = $data[0]['query']['pages'][$key];
170 $data = $this->doApiRequest( array(
171 'action' => 'delete',
172 'token' => $pageinfo['deletetoken'],
173 'title' => 'UTPage' ), $data );
174 $this->assertArrayHasKey( 'delete', $data[0] );
175 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
177 $data = $this->doApiRequest( array(
179 'list' => 'watchlist' ), $data );
181 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );