7fca538698d0611c0943c19b68ba571ea736e4d2
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiWatchTest.php
1 <?php
2
3 /**
4 * @group Database
5 * @group Destructive
6 * @todo This test suite is severly broken and need a full review
7 */
8 class ApiWatchTest extends ApiTestCase {
9
10 function setUp() {
11 parent::setUp();
12 $this->doLogin();
13 }
14
15 function getTokens() {
16 return $this->getTokenList( self::$users['sysop'] );
17 }
18
19 /**
20 * @group Broken
21 */
22 function testWatchEdit() {
23
24 $data = $this->getTokens();
25
26 $keys = array_keys( $data[0]['query']['pages'] );
27 $key = array_pop( $keys );
28 $pageinfo = $data[0]['query']['pages'][$key];
29
30 $data = $this->doApiRequest( array(
31 'action' => 'edit',
32 'title' => 'UTPage',
33 'text' => 'new text',
34 'token' => $pageinfo['edittoken'],
35 'watchlist' => 'watch' ), $data );
36 $this->assertArrayHasKey( 'edit', $data[0] );
37 $this->assertArrayHasKey( 'result', $data[0]['edit'] );
38 $this->assertEquals( 'Success', $data[0]['edit']['result'] );
39
40 return $data;
41 }
42
43 /**
44 * @depends testWatchEdit
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 function testGetRollbackToken() {
98
99 $data = $this->getTokens();
100
101 if ( !Title::newFromText( 'UTPage' )->exists() ) {
102 $this->markTestIncomplete( "The article [[UTPage]] does not exist" );
103 }
104
105 $data = $this->doApiRequest( array(
106 'action' => 'query',
107 'prop' => 'revisions',
108 'titles' => 'UTPage',
109 'rvtoken' => 'rollback' ), $data );
110
111 $this->assertArrayHasKey( 'query', $data[0] );
112 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
113 $keys = array_keys( $data[0]['query']['pages'] );
114 $key = array_pop( $keys );
115
116 if ( isset( $data[0]['query']['pages'][$key]['missing'] ) ) {
117 $this->markTestIncomplete( "Target page (UTPage) doesn't exist" );
118 }
119
120 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
121 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
122 $this->assertArrayHasKey( 0, $data[0]['query']['pages'][$key]['revisions'] );
123 $this->assertArrayHasKey( 'rollbacktoken', $data[0]['query']['pages'][$key]['revisions'][0] );
124
125 return $data;
126 }
127
128 /**
129 * @depends testGetRollbackToken
130 * @group Broken
131 */
132 function testWatchRollback( $data ) {
133 $keys = array_keys( $data[0]['query']['pages'] );
134 $key = array_pop( $keys );
135 $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
136
137 try {
138 $data = $this->doApiRequest( array(
139 'action' => 'rollback',
140 'title' => 'UTPage',
141 'user' => $pageinfo['user'],
142 'token' => $pageinfo['rollbacktoken'],
143 'watchlist' => 'watch' ), $data );
144 } catch( UsageException $ue ) {
145 if( $ue->getCodeString() == 'onlyauthor' ) {
146 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
147 } else {
148 $this->fail( "Received error '" . $ue->getCodeString() . "'" );
149 }
150 }
151
152 $this->assertArrayHasKey( 'rollback', $data[0] );
153 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
154 }
155
156 /**
157 * @group Broken
158 */
159 function testWatchDelete() {
160
161 $data = $this->getTokens();
162
163 $keys = array_keys( $data[0]['query']['pages'] );
164 $key = array_pop( $keys );
165 $pageinfo = $data[0]['query']['pages'][$key];
166
167 $data = $this->doApiRequest( array(
168 'action' => 'delete',
169 'token' => $pageinfo['deletetoken'],
170 'title' => 'UTPage' ), $data );
171 $this->assertArrayHasKey( 'delete', $data[0] );
172 $this->assertArrayHasKey( 'title', $data[0]['delete'] );
173
174 $data = $this->doApiRequest( array(
175 'action' => 'query',
176 'list' => 'watchlist' ), $data );
177
178 $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' );
179 }
180 }