Changed quoting function for oracleDB.
[mediawiki.git] / tests / phpunit / includes / api / ApiWatchTest.php
bloba9bc43ae3b076915c7071488d62f27d324aa59ef
1 <?php
3 /**
4 * @group API
5 * @group Database
6 * @group medium
7 * @todo This test suite is severly broken and need a full review
8 */
9 class ApiWatchTest extends ApiTestCase {
10 protected function setUp() {
11 parent::setUp();
12 $this->doLogin();
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];
22 return $pageinfo;
25 /**
27 function testWatchEdit() {
28 $pageinfo = $this->getTokens();
30 $data = $this->doApiRequest( array(
31 'action' => 'edit',
32 'title' => 'Help:UTPage', // Help namespace is hopefully wikitext
33 'text' => 'new text',
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'] );
40 return $data;
43 /**
44 * @depends testWatchEdit
46 function testWatchClear() {
48 $pageinfo = $this->getTokens();
50 $data = $this->doApiRequest( array(
51 'action' => 'query',
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(
59 'action' => 'watch',
60 'title' => $page['title'],
61 'unwatch' => true,
62 'token' => $pageinfo['watchtoken'] ) );
65 $data = $this->doApiRequest( array(
66 'action' => 'query',
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'] ) );
72 return $data;
75 /**
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] );
94 /**
96 function testGetRollbackToken() {
97 $this->getTokens();
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(
104 'action' => 'query',
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] );
123 return $data;
127 * @group Broken
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];
138 try {
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" );
151 } else {
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(
170 'action' => 'query',
171 'list' => 'watchlist' ) );
173 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );