7fca538698d0611c0943c19b68ba571ea736e4d2
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
46 function testWatchClear() {
48 $data = $this->doApiRequest( array(
50 'list' => 'watchlist' ), $data );
52 if ( isset( $data[0]['query']['watchlist'] ) ) {
53 $wl = $data[0]['query']['watchlist'];
55 foreach ( $wl as $page ) {
56 $data = $this->doApiRequest( array(
58 'title' => $page['title'],
59 'unwatch' => true ), $data );
62 $data = $this->doApiRequest( array(
64 'list' => 'watchlist' ), $data );
65 $this->assertArrayHasKey( 'query', $data[0] );
66 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
67 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
75 function testWatchProtect() {
77 $data = $this->getTokens();
79 $keys = array_keys( $data[0]['query']['pages'] );
80 $key = array_pop( $keys );
81 $pageinfo = $data[0]['query']['pages'][$key];
83 $data = $this->doApiRequest( array(
84 'action' => 'protect',
85 'token' => $pageinfo['protecttoken'],
87 'protections' => 'edit=sysop',
88 'watchlist' => 'unwatch' ), $data );
90 $this->assertArrayHasKey( 'protect', $data[0] );
91 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
92 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
93 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
97 function testGetRollbackToken() {
99 $data = $this->getTokens();
101 if ( !Title
::newFromText( 'UTPage' )->exists() ) {
102 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
105 $data = $this->doApiRequest( array(
107 'prop' => 'revisions',
108 'titles' => 'UTPage',
109 'rvtoken' => 'rollback' ), $data );
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->markTestIncomplete( "Target page (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] );
129 * @depends testGetRollbackToken
132 function testWatchRollback( $data ) {
133 $keys = array_keys( $data[0]['query']['pages'] );
134 $key = array_pop( $keys );
135 $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
138 $data = $this->doApiRequest( array(
139 'action' => 'rollback',
141 'user' => $pageinfo['user'],
142 'token' => $pageinfo['rollbacktoken'],
143 'watchlist' => 'watch' ), $data );
144 } catch( UsageException
$ue ) {
145 if( $ue->getCodeString() == 'onlyauthor' ) {
146 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
148 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
152 $this->assertArrayHasKey( 'rollback', $data[0] );
153 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
159 function testWatchDelete() {
161 $data = $this->getTokens();
163 $keys = array_keys( $data[0]['query']['pages'] );
164 $key = array_pop( $keys );
165 $pageinfo = $data[0]['query']['pages'][$key];
167 $data = $this->doApiRequest( array(
168 'action' => 'delete',
169 'token' => $pageinfo['deletetoken'],
170 'title' => 'UTPage' ), $data );
171 $this->assertArrayHasKey( 'delete', $data[0] );
172 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
174 $data = $this->doApiRequest( array(
176 'list' => 'watchlist' ), $data );
178 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );