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 return $this->getTokenList( self
::$users['sysop'] );
21 public function testWatchEdit() {
22 $tokens = $this->getTokens();
24 $data = $this->doApiRequest( array(
26 'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
28 'token' => $tokens['edittoken'],
29 'watchlist' => 'watch' ) );
30 $this->assertArrayHasKey( 'edit', $data[0] );
31 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
32 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
38 * @depends testWatchEdit
40 public function testWatchClear() {
41 $tokens = $this->getTokens();
43 $data = $this->doApiRequest( array(
45 'list' => 'watchlist' ) );
47 if ( isset( $data[0]['query']['watchlist'] ) ) {
48 $wl = $data[0]['query']['watchlist'];
50 foreach ( $wl as $page ) {
51 $data = $this->doApiRequest( array(
53 'title' => $page['title'],
55 'token' => $tokens['watchtoken'] ) );
58 $data = $this->doApiRequest( array(
60 'list' => 'watchlist' ), $data );
61 $this->assertArrayHasKey( 'query', $data[0] );
62 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
63 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
70 public function testWatchProtect() {
71 $tokens = $this->getTokens();
73 $data = $this->doApiRequest( array(
74 'action' => 'protect',
75 'token' => $tokens['protecttoken'],
76 'title' => 'Help:UTPage',
77 'protections' => 'edit=sysop',
78 'watchlist' => 'unwatch' ) );
80 $this->assertArrayHasKey( 'protect', $data[0] );
81 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
82 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
83 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
88 public function testGetRollbackToken() {
91 if ( !Title
::newFromText( 'Help:UTPage' )->exists() ) {
92 $this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); //TODO: just create it?
95 $data = $this->doApiRequest( array(
97 'prop' => 'revisions',
98 'titles' => 'Help:UTPage',
99 'rvtoken' => 'rollback' ) );
101 $this->assertArrayHasKey( 'query', $data[0] );
102 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
103 $keys = array_keys( $data[0]['query']['pages'] );
104 $key = array_pop( $keys );
106 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
107 $this->markTestSkipped( "Target page (Help:UTPage) doesn't exist" );
110 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
111 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
112 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
113 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
120 * Broken because there is currently no revision info in the $pageinfo
122 * @depends testGetRollbackToken
124 public function testWatchRollback( $data ) {
125 $keys = array_keys( $data[0]['query']['pages'] );
126 $key = array_pop( $keys );
127 $pageinfo = $data[0]['query']['pages'][$key];
128 $revinfo = $pageinfo['revisions'][0];
131 $data = $this->doApiRequest( array(
132 'action' => 'rollback',
133 'title' => 'Help:UTPage',
134 'user' => $revinfo['user'],
135 'token' => $pageinfo['rollbacktoken'],
136 'watchlist' => 'watch' ) );
138 $this->assertArrayHasKey( 'rollback', $data[0] );
139 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
140 } catch ( UsageException
$ue ) {
141 if ( $ue->getCodeString() == 'onlyauthor' ) {
142 $this->markTestIncomplete( "Only one author to 'Help:UTPage', cannot test rollback" );
144 $this->fail( "Received error '" . $ue->getCodeString() . "'" );