Implement extension registration from an extension.json file
[mediawiki.git] / tests / phpunit / includes / changes / RCCacheEntryFactoryTest.php
blobee1a4d0e0fc5320f2287f14a45481ada717ce262
1 <?php
3 /**
4 * @covers RCCacheEntryFactory
6 * @group Database
8 * @licence GNU GPL v2+
9 * @author Katie Filbert < aude.wiki@gmail.com >
11 class RCCacheEntryFactoryTest extends MediaWikiLangTestCase {
13 /**
14 * @var TestRecentChangesHelper
16 private $testRecentChangesHelper;
18 public function __construct( $name = null, array $data = array(), $dataName = '' ) {
19 parent::__construct( $name, $data, $dataName );
21 $this->testRecentChangesHelper = new TestRecentChangesHelper();
24 protected function setUp() {
25 parent::setUp();
27 $this->setMwGlobals( array(
28 'wgArticlePath' => '/wiki/$1'
29 ) );
32 /**
33 * @dataProvider editChangeProvider
35 public function testNewFromRecentChange( $expected, $context, $messages,
36 $recentChange, $watched
37 ) {
38 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
39 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
41 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
43 $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
44 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
45 $this->assertEquals(
46 $expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers,
47 'watching users'
49 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
51 $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
52 $this->assertTitleLink( 'Xyz', $cacheEntry );
54 $this->assertQueryLink( 'cur', $expected['cur'], $cacheEntry->curlink, 'cur link' );
55 $this->assertQueryLink( 'prev', $expected['diff'], $cacheEntry->lastlink, 'prev link' );
56 $this->assertQueryLink( 'diff', $expected['diff'], $cacheEntry->difflink, 'diff link' );
59 public function editChangeProvider() {
60 return array(
61 array(
62 array(
63 'title' => 'Xyz',
64 'user' => 'TestRecentChangesUser',
65 'diff' => array( 'curid' => 5, 'diff' => 191, 'oldid' => 190 ),
66 'cur' => array( 'curid' => 5, 'diff' => 0, 'oldid' => 191 ),
67 'timestamp' => '21:21',
68 'numberofWatchingusers' => 0,
69 'unpatrolled' => false
71 $this->getContext(),
72 $this->getMessages(),
73 $this->testRecentChangesHelper->makeEditRecentChange(
74 $this->getTestUser(),
75 'Xyz',
76 5, // curid
77 191, // thisid
78 190, // lastid
79 '20131103212153',
80 0, // counter
81 0 // number of watching users
83 false
88 /**
89 * @dataProvider deleteChangeProvider
91 public function testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched ) {
92 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
93 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
95 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
97 $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
98 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
99 $this->assertEquals(
100 $expected['numberofWatchingusers'],
101 $cacheEntry->numberofWatchingusers, 'watching users'
103 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
105 $this->assertDeleteLogLink( $cacheEntry );
106 $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
108 $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
109 $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
110 $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
113 public function deleteChangeProvider() {
114 return array(
115 array(
116 array(
117 'title' => 'Abc',
118 'user' => 'TestRecentChangesUser',
119 'timestamp' => '21:21',
120 'numberofWatchingusers' => 0,
121 'unpatrolled' => false
123 $this->getContext(),
124 $this->getMessages(),
125 $this->testRecentChangesHelper->makeLogRecentChange(
126 'delete',
127 'delete',
128 $this->getTestUser(),
129 'Abc',
130 '20131103212153',
131 0, // counter
132 0 // number of watching users
134 false
140 * @dataProvider revUserDeleteProvider
142 public function testNewForRevUserDeleteChange( $expected, $context, $messages,
143 $recentChange, $watched
145 $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
146 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
148 $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
150 $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
151 $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
152 $this->assertEquals(
153 $expected['numberofWatchingusers'],
154 $cacheEntry->numberofWatchingusers, 'watching users'
156 $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
158 $this->assertRevDel( $cacheEntry );
159 $this->assertTitleLink( 'Zzz', $cacheEntry );
161 $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
162 $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
163 $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
166 public function revUserDeleteProvider() {
167 return array(
168 array(
169 array(
170 'title' => 'Zzz',
171 'user' => 'TestRecentChangesUser',
172 'diff' => '',
173 'cur' => '',
174 'timestamp' => '21:21',
175 'numberofWatchingusers' => 0,
176 'unpatrolled' => false
178 $this->getContext(),
179 $this->getMessages(),
180 $this->testRecentChangesHelper->makeDeletedEditRecentChange(
181 $this->getTestUser(),
182 'Zzz',
183 '20131103212153',
184 191, // thisid
185 190, // lastid
186 '20131103212153',
187 0, // counter
188 0 // number of watching users
190 false
195 private function assertUserLinks( $user, $cacheEntry ) {
196 $this->assertTag(
197 array(
198 'tag' => 'a',
199 'attributes' => array(
200 'class' => 'new mw-userlink'
202 'content' => $user
204 $cacheEntry->userlink,
205 'verify user link'
208 $this->assertTag(
209 array(
210 'tag' => 'span',
211 'attributes' => array(
212 'class' => 'mw-usertoollinks'
214 'child' => array(
215 'tag' => 'a',
216 'content' => 'Talk',
219 $cacheEntry->usertalklink,
220 'verify user talk link'
223 $this->assertTag(
224 array(
225 'tag' => 'span',
226 'attributes' => array(
227 'class' => 'mw-usertoollinks'
229 'child' => array(
230 'tag' => 'a',
231 'content' => 'contribs',
234 $cacheEntry->usertalklink,
235 'verify user tool links'
239 private function assertDeleteLogLink( $cacheEntry ) {
240 $this->assertTag(
241 array(
242 'tag' => 'a',
243 'attributes' => array(
244 'href' => '/wiki/Special:Log/delete',
245 'title' => 'Special:Log/delete'
247 'content' => 'Deletion log'
249 $cacheEntry->link,
250 'verify deletion log link'
254 private function assertRevDel( $cacheEntry ) {
255 $this->assertTag(
256 array(
257 'tag' => 'span',
258 'attributes' => array(
259 'class' => 'history-deleted'
261 'content' => '(username removed)'
263 $cacheEntry->userlink,
264 'verify user link for change with deleted revision and user'
268 private function assertTitleLink( $title, $cacheEntry ) {
269 $this->assertTag(
270 array(
271 'tag' => 'a',
272 'attributes' => array(
273 'href' => '/wiki/' . $title,
274 'title' => $title
276 'content' => $title
278 $cacheEntry->link,
279 'verify title link'
283 private function assertQueryLink( $content, $params, $link ) {
284 $this->assertTag(
285 array(
286 'tag' => 'a',
287 'content' => $content
289 $link,
290 'assert query link element'
293 foreach ( $params as $key => $value ) {
294 $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
298 private function getMessages() {
299 return array(
300 'cur' => 'cur',
301 'diff' => 'diff',
302 'hist' => 'hist',
303 'enhancedrc-history' => 'history',
304 'last' => 'prev',
305 'blocklink' => 'block',
306 'history' => 'Page history',
307 'semicolon-separator' => '; ',
308 'pipe-separator' => ' | '
312 private function getTestUser() {
313 $user = User::newFromName( 'TestRecentChangesUser' );
315 if ( !$user->getId() ) {
316 $user->addToDatabase();
319 return $user;
322 private function getContext() {
323 $user = $this->getTestUser();
324 $context = $this->testRecentChangesHelper->getTestContext( $user );
326 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
327 $context->setTitle( $title );
329 return $context;