Remove notes about being destructive. We work properly on cloned tables now
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiWatchTest.php
1 <?php
2
3 /**
4 * @group Database
5 * @todo This test suite is severly broken and need a full review
6 */
7 class ApiWatchTest extends ApiTestCase {
8
9 function setUp() {
10 parent::setUp();
11 $this->doLogin();
12 }
13
14 function getTokens() {
15 return $this->getTokenList( self::$users['sysop'] );
16 }
17
18 /**
19 * @group Broken
20 */
21 function testWatchEdit() {
22
23 $data = $this->getTokens();
24
25 $keys = array_keys( $data[0]['query']['pages'] );
26 $key = array_pop( $keys );
27 $pageinfo = $data[0]['query']['pages'][$key];
28
29 $data = $this->doApiRequest( array(
30 'action' => 'edit',
31 'title' => 'UTPage',
32 'text' => 'new text',
33 'token' => $pageinfo['edittoken'],
34 'watchlist' => 'watch' ), $data );
35 $this->assertArrayHasKey( 'edit', $data[0] );
36 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
37 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
38
39 return $data;
40 }
41
42 /**
43 * @depends testWatchEdit
44 */
45 function testWatchClear() {
46
47 $data = $this->doApiRequest( array(
48 'action' => 'query',
49 'list' => 'watchlist' ), $data );
50
51 if ( isset( $data[0]['query']['watchlist'] ) ) {
52 $wl = $data[0]['query']['watchlist'];
53
54 foreach ( $wl as $page ) {
55 $data = $this->doApiRequest( array(
56 'action' => 'watch',
57 'title' => $page['title'],
58 'unwatch' => true ), $data );
59 }
60 }
61 $data = $this->doApiRequest( array(
62 'action' => 'query',
63 'list' => 'watchlist' ), $data );
64 $this->assertArrayHasKey( 'query', $data[0] );
65 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
66 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
67
68 return $data;
69 }
70
71 /**
72 * @group Broken
73 */
74 function testWatchProtect() {
75
76 $data = $this->getTokens();
77
78 $keys = array_keys( $data[0]['query']['pages'] );
79 $key = array_pop( $keys );
80 $pageinfo = $data[0]['query']['pages'][$key];
81
82 $data = $this->doApiRequest( array(
83 'action' => 'protect',
84 'token' => $pageinfo['protecttoken'],
85 'title' => 'UTPage',
86 'protections' => 'edit=sysop',
87 'watchlist' => 'unwatch' ), $data );
88
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] );
93 }
94
95
96 function testGetRollbackToken() {
97
98 $data = $this->getTokens();
99
100 if ( !Title::newFromText( 'UTPage' )->exists() ) {
101 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
102 }
103
104 $data = $this->doApiRequest( array(
105 'action' => 'query',
106 'prop' => 'revisions',
107 'titles' => 'UTPage',
108 'rvtoken' => 'rollback' ), $data );
109
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 );
114
115 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
116 $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
117 }
118
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] );
123
124 return $data;
125 }
126
127 /**
128 * @depends testGetRollbackToken
129 * @group Broken
130 */
131 function testWatchRollback( $data ) {
132 $keys = array_keys( $data[0]['query']['pages'] );
133 $key = array_pop( $keys );
134 $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
135
136 try {
137 $data = $this->doApiRequest( array(
138 'action' => 'rollback',
139 'title' => 'UTPage',
140 'user' => $pageinfo['user'],
141 'token' => $pageinfo['rollbacktoken'],
142 'watchlist' => 'watch' ), $data );
143 } catch( UsageException $ue ) {
144 if( $ue->getCodeString() == 'onlyauthor' ) {
145 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
146 } else {
147 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
148 }
149 }
150
151 $this->assertArrayHasKey( 'rollback', $data[0] );
152 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
153 }
154
155 /**
156 * @group Broken
157 */
158 function testWatchDelete() {
159
160 $data = $this->getTokens();
161
162 $keys = array_keys( $data[0]['query']['pages'] );
163 $key = array_pop( $keys );
164 $pageinfo = $data[0]['query']['pages'][$key];
165
166 $data = $this->doApiRequest( array(
167 'action' => 'delete',
168 'token' => $pageinfo['deletetoken'],
169 'title' => 'UTPage' ), $data );
170 $this->assertArrayHasKey( 'delete', $data[0] );
171 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
172
173 $data = $this->doApiRequest( array(
174 'action' => 'query',
175 'list' => 'watchlist' ), $data );
176
177 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
178 }
179 }