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(
46 'list' => 'watchlist' ) );
48 if ( isset( $data[0]['query']['watchlist'] ) ) {
49 $wl = $data[0]['query']['watchlist'];
51 foreach ( $wl as $page ) {
52 $data = $this->doApiRequest( array(
54 'title' => $page['title'],
56 'token' => $tokens['watchtoken'] ) );
59 $data = $this->doApiRequest( array(
61 'list' => 'watchlist' ), $data );
62 $this->assertArrayHasKey( 'query', $data[0] );
63 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
64 foreach ( $data[0]['query']['watchlist'] as $index => $item ) {
65 // Previous tests may insert an invalid title
66 // like ":ApiEditPageTest testNonTextEdit", which
68 if ( strpos( $item['title'], ':' ) === 0 ) {
69 unset( $data[0]['query']['watchlist'][$index] );
72 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
79 public function testWatchProtect() {
80 $tokens = $this->getTokens();
82 $data = $this->doApiRequest( array(
83 'action' => 'protect',
84 'token' => $tokens['protecttoken'],
85 'title' => 'Help:UTPage',
86 'protections' => 'edit=sysop',
87 'watchlist' => 'unwatch' ) );
89 $this->assertArrayHasKey( 'protect', $data[0] );
90 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
91 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
92 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
97 public function testGetRollbackToken() {
100 if ( !Title
::newFromText( 'Help:UTPage' )->exists() ) {
101 $this->markTestSkipped( "The article [[Help:UTPage]] does not exist" ); //TODO: just create it?
104 $data = $this->doApiRequest( array(
106 'prop' => 'revisions',
107 'titles' => 'Help: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 (Help: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 public 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',
142 'title' => 'Help:UTPage',
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 'Help:UTPage', cannot test rollback" );
153 $this->fail( "Received error '" . $ue->getCodeString() . "'" );