7 * @todo This test suite is severly broken and need a full review
9 class ApiWatchTest
extends ApiTestCase
{
10 protected function setUp() {
15 function getTokens() {
16 $data = $this->getTokenList( self
::$users['sysop'] );
18 $keys = array_keys( $data[0]['query']['pages'] );
19 $key = array_pop( $keys );
20 $pageinfo = $data[0]['query']['pages'][$key];
27 function testWatchEdit() {
28 $pageinfo = $this->getTokens();
30 $data = $this->doApiRequest( array(
32 'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
34 'token' => $pageinfo['edittoken'],
35 'watchlist' => 'watch' ) );
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 $pageinfo = $this->getTokens();
50 $data = $this->doApiRequest( array(
52 'list' => 'watchlist' ) );
54 if ( isset( $data[0]['query']['watchlist'] ) ) {
55 $wl = $data[0]['query']['watchlist'];
57 foreach ( $wl as $page ) {
58 $data = $this->doApiRequest( array(
60 'title' => $page['title'],
62 'token' => $pageinfo['watchtoken'] ) );
65 $data = $this->doApiRequest( array(
67 'list' => 'watchlist' ), $data );
68 $this->assertArrayHasKey( 'query', $data[0] );
69 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
70 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
77 function testWatchProtect() {
79 $pageinfo = $this->getTokens();
81 $data = $this->doApiRequest( array(
82 'action' => 'protect',
83 'token' => $pageinfo['protecttoken'],
84 'title' => 'Help:UTPage',
85 'protections' => 'edit=sysop',
86 'watchlist' => 'unwatch' ) );
88 $this->assertArrayHasKey( 'protect', $data[0] );
89 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
90 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
91 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
96 function testGetRollbackToken() {
99 if ( !Title
::newFromText( 'Help:UTPage' )->exists() ) {
100 $this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); //TODO: just create it?
103 $data = $this->doApiRequest( array(
105 'prop' => 'revisions',
106 'titles' => 'Help:UTPage',
107 'rvtoken' => 'rollback' ) );
109 $this->assertArrayHasKey( 'query', $data[0] );
110 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
111 $keys = array_keys( $data[0]['query']['pages'] );
112 $key = array_pop( $keys );
114 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
115 $this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" );
118 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
119 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
120 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
121 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
128 * Broken because there is currently no revision info in the $pageinfo
130 * @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];
136 $revinfo = $pageinfo['revisions'][0];
139 $data = $this->doApiRequest( array(
140 'action' => 'rollback',
141 'title' => 'Help:UTPage',
142 'user' => $revinfo['user'],
143 'token' => $pageinfo['rollbacktoken'],
144 'watchlist' => 'watch' ) );
146 $this->assertArrayHasKey( 'rollback', $data[0] );
147 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
148 } catch ( UsageException
$ue ) {
149 if ( $ue->getCodeString() == 'onlyauthor' ) {
150 $this->markTestIncomplete( "Only one author to 'Help:UTPage', cannot test rollback" );
152 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
159 function testWatchDelete() {
160 $pageinfo = $this->getTokens();
162 $data = $this->doApiRequest( array(
163 'action' => 'delete',
164 'token' => $pageinfo['deletetoken'],
165 'title' => 'Help:UTPage' ) );
166 $this->assertArrayHasKey( 'delete', $data[0] );
167 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
169 $this->doApiRequest( array(
171 'list' => 'watchlist' ) );
173 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );