b78037464bd0bcc39c8f9bf39619790eb64f9dc3
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
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] );
99 function testGetRollbackToken() {
101 $data = $this->getTokens();
103 if ( !Title
::newFromText( 'UTPage' )->exists() ) {
104 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
107 $data = $this->doApiRequest( array(
109 'prop' => 'revisions',
110 'titles' => 'UTPage',
111 'rvtoken' => 'rollback' ), $data );
113 $this->assertArrayHasKey( 'query', $data[0] );
114 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
115 $keys = array_keys( $data[0]['query']['pages'] );
116 $key = array_pop( $keys );
118 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
119 $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
122 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
123 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
124 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
125 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
131 * @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]['revisions'][0];
140 $data = $this->doApiRequest( array(
141 'action' => 'rollback',
143 'user' => $pageinfo['user'],
144 'token' => $pageinfo['rollbacktoken'],
145 'watchlist' => 'watch' ), $data );
146 } catch( UsageException
$ue ) {
147 if( $ue->getCodeString() == 'onlyauthor' ) {
148 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
150 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
154 $this->assertArrayHasKey( 'rollback', $data[0] );
155 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
161 function testWatchDelete() {
163 $data = $this->getTokens();
165 $keys = array_keys( $data[0]['query']['pages'] );
166 $key = array_pop( $keys );
167 $pageinfo = $data[0]['query']['pages'][$key];
169 $data = $this->doApiRequest( array(
170 'action' => 'delete',
171 'token' => $pageinfo['deletetoken'],
172 'title' => 'UTPage' ), $data );
173 $this->assertArrayHasKey( 'delete', $data[0] );
174 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
176 $data = $this->doApiRequest( array(
178 'list' => 'watchlist' ), $data );
180 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );