* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / api / ApiWatchTest.php
blobcd35a5b85619585a38a6ce43979c96adfdc5019d
1 <?php
3 require_once dirname( __FILE__ ) . '/ApiSetup.php';
5 /**
6 * @group Database
7 * @group Destructive
8 * @todo This test suite is severly broken and need a full review
9 */
10 class ApiWatchTest extends ApiTestSetup {
12 function setUp() {
13 parent::setUp();
14 $this->doLogin();
17 function getTokens() {
18 return $this->getTokenList( $this->sysopUser );
21 /**
22 * @group Broken
24 function testWatchEdit() {
26 $data = $this->getTokens();
28 $keys = array_keys( $data[0]['query']['pages'] );
29 $key = array_pop( $keys );
30 $pageinfo = $data[0]['query']['pages'][$key];
32 $data = $this->doApiRequest( array(
33 'action' => 'edit',
34 'title' => 'UTPage',
35 'text' => 'new text',
36 'token' => $pageinfo['edittoken'],
37 'watchlist' => 'watch' ), $data );
38 $this->assertArrayHasKey( 'edit', $data[0] );
39 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
40 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
42 return $data;
45 /**
46 * @depends testWatchEdit
48 function testWatchClear() {
50 $data = $this->doApiRequest( array(
51 'action' => 'query',
52 'list' => 'watchlist' ), $data );
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 ), $data );
64 $data = $this->doApiRequest( array(
65 'action' => 'query',
66 'list' => 'watchlist' ), $data );
67 $this->assertArrayHasKey( 'query', $data[0] );
68 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
69 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
71 return $data;
74 /**
75 * @group Broken
76 */
77 function testWatchProtect() {
79 $data = $this->getTokens();
81 $keys = array_keys( $data[0]['query']['pages'] );
82 $key = array_pop( $keys );
83 $pageinfo = $data[0]['query']['pages'][$key];
85 $data = $this->doApiRequest( array(
86 'action' => 'protect',
87 'token' => $pageinfo['protecttoken'],
88 'title' => 'UTPage',
89 'protections' => 'edit=sysop',
90 'watchlist' => 'unwatch' ), $data );
92 $this->assertArrayHasKey( 'protect', $data[0] );
93 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
94 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
95 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
99 function testGetRollbackToken() {
101 $data = $this->getTokens();
103 if ( !Title::newFromText( 'UTPage' )->exists() ) {
104 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
107 $data = $this->doApiRequest( array(
108 'action' => 'query',
109 'prop' => 'revisions',
110 'titles' => 'UTPage',
111 'rvtoken' => 'rollback' ), $data );
113 $this->assertArrayHasKey( 'query', $data[0] );
114 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
115 $keys = array_keys( $data[0]['query']['pages'] );
116 $key = array_pop( $keys );
118 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
119 $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
122 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
123 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
124 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
125 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
127 return $data;
131 * @depends testGetRollbackToken
132 * @group Broken
134 function testWatchRollback( $data ) {
135 $keys = array_keys( $data[0]['query']['pages'] );
136 $key = array_pop( $keys );
137 $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
139 try {
140 $data = $this->doApiRequest( array(
141 'action' => 'rollback',
142 'title' => 'UTPage',
143 'user' => $pageinfo['user'],
144 'token' => $pageinfo['rollbacktoken'],
145 'watchlist' => 'watch' ), $data );
146 } catch( UsageException $ue ) {
147 if( $ue->getCodeString() == 'onlyauthor' ) {
148 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
149 } else {
150 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
154 $this->assertArrayHasKey( 'rollback', $data[0] );
155 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
159 * @group Broken
161 function testWatchDelete() {
163 $data = $this->getTokens();
165 $keys = array_keys( $data[0]['query']['pages'] );
166 $key = array_pop( $keys );
167 $pageinfo = $data[0]['query']['pages'][$key];
169 $data = $this->doApiRequest( array(
170 'action' => 'delete',
171 'token' => $pageinfo['deletetoken'],
172 'title' => 'UTPage' ), $data );
173 $this->assertArrayHasKey( 'delete', $data[0] );
174 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
176 $data = $this->doApiRequest( array(
177 'action' => 'query',
178 'list' => 'watchlist' ), $data );
180 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );