3 require_once dirname( __FILE__
) . '/ApiSetup.php';
9 class ApiWatchTest
extends ApiTestSetup
{
16 function getTokens() {
17 return $this->getTokenList( $this->sysopUser
);
20 function testWatchEdit() {
22 $data = $this->getTokens();
24 $this->markTestIncomplete( "Broken" );
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'] ) );
72 function testWatchProtect() {
74 $data = $this->getTokens();
76 $this->markTestIncomplete( "Broken" );
77 $keys = array_keys( $data[0]['query']['pages'] );
78 $key = array_pop( $keys );
79 $pageinfo = $data[0]['query']['pages'][$key];
81 $data = $this->doApiRequest( array(
82 'action' => 'protect',
83 'token' => $pageinfo['protecttoken'],
85 'protections' => 'edit=sysop',
86 'watchlist' => 'unwatch' ), $data );
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] );
95 function testGetRollbackToken() {
97 $data = $this->getTokens();
99 if ( !Title
::newFromText( 'UTPage' )->exists() ) {
100 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
103 $data = $this->doApiRequest( array(
105 'prop' => 'revisions',
106 'titles' => 'UTPage',
107 'rvtoken' => 'rollback' ), $data );
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->markTestIncomplete( "Target page (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] );
127 * @depends testGetRollbackToken
129 function testWatchRollback( $data ) {
130 $keys = array_keys( $data[0]['query']['pages'] );
131 $key = array_pop( $keys );
132 $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
135 $data = $this->doApiRequest( array(
136 'action' => 'rollback',
138 'user' => $pageinfo['user'],
139 'token' => $pageinfo['rollbacktoken'],
140 'watchlist' => 'watch' ), $data );
141 } catch( UsageException
$ue ) {
142 if( $ue->getCodeString() == 'onlyauthor' ) {
143 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
145 $this->fail( "Received error " . $ue->getCodeString() );
149 $this->assertArrayHasKey( 'rollback', $data[0] );
150 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
154 function testWatchDelete() {
156 $data = $this->getTokens();
158 $this->markTestIncomplete( "Broken" );
159 $keys = array_keys( $data[0]['query']['pages'] );
160 $key = array_pop( $keys );
161 $pageinfo = $data[0]['query']['pages'][$key];
163 $data = $this->doApiRequest( array(
164 'action' => 'delete',
165 'token' => $pageinfo['deletetoken'],
166 'title' => 'UTPage' ), $data );
167 $this->assertArrayHasKey( 'delete', $data[0] );
168 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
170 $data = $this->doApiRequest( array(
172 'list' => 'watchlist' ), $data );
174 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );