b78037464bd0bcc39c8f9bf39619790eb64f9dc3
[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 * @group Broken
45 */
46 function testWatchClear() {
47
48 $data = $this->doApiRequest( array(
49 'action' => 'query',
50 'list' => 'watchlist' ), $data );
51
52 if ( isset( $data[0]['query']['watchlist'] ) ) {
53 $wl = $data[0]['query']['watchlist'];
54
55 foreach ( $wl as $page ) {
56 $data = $this->doApiRequest( array(
57 'action' => 'watch',
58 'title' => $page['title'],
59 'unwatch' => true ), $data );
60 }
61 }
62 $data = $this->doApiRequest( array(
63 'action' => 'query',
64 'list' => 'watchlist' ), $data );
65 $this->assertArrayHasKey( 'query', $data[0] );
66 $this->assertArrayHasKey( 'watchlist', $data[0]['query'] );
67 $this->assertEquals( 0, count( $data[0]['query']['watchlist'] ) );
68
69 return $data;
70 }
71
72 /**
73 * @group Broken
74 */
75 function testWatchProtect() {
76
77 $data = $this->getTokens();
78
79 $keys = array_keys( $data[0]['query']['pages'] );
80 $key = array_pop( $keys );
81 $pageinfo = $data[0]['query']['pages'][$key];
82
83 $data = $this->doApiRequest( array(
84 'action' => 'protect',
85 'token' => $pageinfo['protecttoken'],
86 'title' => 'UTPage',
87 'protections' => 'edit=sysop',
88 'watchlist' => 'unwatch' ), $data );
89
90 $this->assertArrayHasKey( 'protect', $data[0] );
91 $this->assertArrayHasKey( 'protections', $data[0]['protect'] );
92 $this->assertEquals( 1, count( $data[0]['protect']['protections'] ) );
93 $this->assertArrayHasKey( 'edit', $data[0]['protect']['protections'][0] );
94 }
95
96 /**
97 * @group Broken
98 */
99 function testGetRollbackToken() {
100
101 $data = $this->getTokens();
102
103 if ( !Title::newFromText( 'UTPage' )->exists() ) {
104 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
105 }
106
107 $data = $this->doApiRequest( array(
108 'action' => 'query',
109 'prop' => 'revisions',
110 'titles' => 'UTPage',
111 'rvtoken' => 'rollback' ), $data );
112
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 );
117
118 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
119 $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
120 }
121
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] );
126
127 return $data;
128 }
129
130 /**
131 * @depends testGetRollbackToken
132 * @group Broken
133 */
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];
138
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() . "'" );
151 }
152 }
153
154 $this->assertArrayHasKey( 'rollback', $data[0] );
155 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
156 }
157
158 /**
159 * @group Broken
160 */
161 function testWatchDelete() {
162
163 $data = $this->getTokens();
164
165 $keys = array_keys( $data[0]['query']['pages'] );
166 $key = array_pop( $keys );
167 $pageinfo = $data[0]['query']['pages'][$key];
168
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'] );
175
176 $data = $this->doApiRequest( array(
177 'action' => 'query',
178 'list' => 'watchlist' ), $data );
179
180 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
181 }
182 }