cc6c587f580cbbcb2ec1862df740888c0436a6a5
6 * @todo This test suite is severly broken and need a full review
8 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(
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'],
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() {
98 $pageinfo = $this->getTokens();
100 if ( !Title
::newFromText( 'UTPage' )->exists() ) {
101 $this->markTestSkipped( "The article [[UTPage]] does not exist" ); //TODO: just create it?
104 $data = $this->doApiRequest( array(
106 'prop' => 'revisions',
107 'titles' => 'UTPage',
108 'rvtoken' => 'rollback' ) );
110 $this->assertArrayHasKey( 'query', $data[0] );
111 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
112 $keys = array_keys( $data[0]['query']['pages'] );
113 $key = array_pop( $keys );
115 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
116 $this->markTestSkipped( "Target page (UTPage) doesn't exist" );
119 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
120 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
121 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
122 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
129 * Broken because there is currently no revision info in the $pageinfo
131 * @depends testGetRollbackToken
133 function testWatchRollback( $data ) {
134 $keys = array_keys( $data[0]['query']['pages'] );
135 $key = array_pop( $keys );
136 $pageinfo = $data[0]['query']['pages'][$key];
137 $revinfo = $pageinfo['revisions'][0];
140 $data = $this->doApiRequest( array(
141 'action' => 'rollback',
143 'user' => $revinfo['user'],
144 'token' => $pageinfo['rollbacktoken'],
145 'watchlist' => 'watch' ) );
147 $this->assertArrayHasKey( 'rollback', $data[0] );
148 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
149 } catch( UsageException
$ue ) {
150 if( $ue->getCodeString() == 'onlyauthor' ) {
151 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
153 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
160 function testWatchDelete() {
161 $pageinfo = $this->getTokens();
163 $data = $this->doApiRequest( array(
164 'action' => 'delete',
165 'token' => $pageinfo['deletetoken'],
166 'title' => 'UTPage' ) );
167 $this->assertArrayHasKey( 'delete', $data[0] );
168 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
170 $data = $this->doApiRequest( array(
172 'list' => 'watchlist' ) );
174 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );