MediaWiki  1.23.6
RCCacheEntryFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
12  protected function setUp() {
13  parent::setUp();
14 
15  $this->setMwGlobals( array(
16  'wgArticlePath' => '/wiki/$1'
17  ) );
18  }
19 
23  public function testNewFromRecentChange( $expected, $context, $messages,
24  $recentChange, $watched
25  ) {
26  $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
27  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
28 
29  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
30 
31  $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
32  $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
33  $this->assertEquals(
34  $expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers,
35  'watching users'
36  );
37  $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
38 
39  $this->assertUserLinks( 'Mary', $cacheEntry );
40  $this->assertTitleLink( 'Xyz', $cacheEntry );
41 
42  $this->assertQueryLink( 'cur', $expected['cur'], $cacheEntry->curlink, 'cur link' );
43  $this->assertQueryLink( 'prev', $expected['diff'], $cacheEntry->lastlink, 'prev link' );
44  $this->assertQueryLink( 'diff', $expected['diff'], $cacheEntry->difflink, 'diff link' );
45  }
46 
47  public function editChangeProvider() {
48  return array(
49  array(
50  array(
51  'title' => 'Xyz',
52  'user' => 'Mary',
53  'diff' => array( 'curid' => 5, 'diff' => 191, 'oldid' => 190 ),
54  'cur' => array( 'curid' => 5, 'diff' => 0, 'oldid' => 191 ),
55  'timestamp' => '21:21',
56  'numberofWatchingusers' => 0,
57  'unpatrolled' => false
58  ),
59  $this->getContext(),
60  $this->getMessages(),
61  $this->makeEditRecentChange(
62  'Xyz',
63  $this->getTestUser(),
64  5, // curid
65  191, // thisid
66  190, // lastid
67  '20131103212153',
68  0, // counter
69  0 // number of watching users
70  ),
71  false,
72  'edit'
73  )
74  );
75  }
76 
77  private function makeEditRecentChange( $title, $user, $curid, $thisid, $lastid,
78  $timestamp, $counter, $watchingUsers
79  ) {
80 
81  $attribs = array_merge(
83  array(
84  'rc_user' => $user->getId(),
85  'rc_user_text' => $user->getName(),
86  'rc_this_oldid' => $thisid,
87  'rc_last_oldid' => $lastid,
88  'rc_cur_id' => $curid
89  )
90  );
91 
92  return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
93  }
94 
98  public function testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched ) {
99  $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
100  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
101 
102  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
103 
104  $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
105  $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
106  $this->assertEquals(
107  $expected['numberofWatchingusers'],
108  $cacheEntry->numberofWatchingusers, 'watching users'
109  );
110  $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
111 
112  $this->assertDeleteLogLink( $cacheEntry );
113  $this->assertUserLinks( 'Mary', $cacheEntry );
114 
115  $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
116  $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
117  $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
118  }
119 
120  public function deleteChangeProvider() {
121  return array(
122  array(
123  array(
124  'title' => 'Abc',
125  'user' => 'Mary',
126  'timestamp' => '21:21',
127  'numberofWatchingusers' => 0,
128  'unpatrolled' => false
129  ),
130  $this->getContext(),
131  $this->getMessages(),
132  $this->makeLogRecentChange(
133  'Abc',
134  $this->getTestUser(),
135  '20131103212153',
136  0, // counter
137  0 // number of watching users
138  ),
139  false,
140  'delete'
141  )
142  );
143  }
144 
145  private function makeLogRecentChange( $title, $user, $timestamp, $counter, $watchingUsers ) {
146  $attribs = array_merge(
148  array(
149  'rc_cur_id' => 0,
150  'rc_user' => $user->getId(),
151  'rc_user_text' => $user->getName(),
152  'rc_this_oldid' => 0,
153  'rc_last_oldid' => 0,
154  'rc_old_len' => null,
155  'rc_new_len' => null,
156  'rc_type' => 3,
157  'rc_logid' => 25,
158  'rc_log_type' => 'delete',
159  'rc_log_action' => 'delete'
160  )
161  );
162 
163  return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
164  }
165 
169  public function testNewForRevUserDeleteChange( $expected, $context, $messages,
170  $recentChange, $watched
171  ) {
172  $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
173  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
174 
175  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
176 
177  $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
178  $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
179  $this->assertEquals(
180  $expected['numberofWatchingusers'],
181  $cacheEntry->numberofWatchingusers, 'watching users'
182  );
183  $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
184 
185  $this->assertRevDel( $cacheEntry );
186  $this->assertTitleLink( 'Zzz', $cacheEntry );
187 
188  $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
189  $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
190  $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
191  }
192 
193  public function revUserDeleteProvider() {
194  return array(
195  array(
196  array(
197  'title' => 'Zzz',
198  'user' => 'Mary',
199  'diff' => '',
200  'cur' => '',
201  'timestamp' => '21:21',
202  'numberofWatchingusers' => 0,
203  'unpatrolled' => false
204  ),
205  $this->getContext(),
206  $this->getMessages(),
208  'Zzz',
209  $this->getTestUser(),
210  '20131103212153',
211  191, // thisid
212  190, // lastid
213  '20131103212153',
214  0, // counter
215  0 // number of watching users
216  ),
217  false,
218  'deletedrevuser'
219  )
220  );
221  }
222 
223  private function makeDeletedEditRecentChange( $title, $user, $timestamp, $curid, $thisid,
224  $lastid, $counter, $watchingUsers
225  ) {
226  $attribs = array_merge(
228  array(
229  'rc_user' => $user->getId(),
230  'rc_user_text' => $user->getName(),
231  'rc_deleted' => 5,
232  'rc_cur_id' => $curid,
233  'rc_this_oldid' => $thisid,
234  'rc_last_oldid' => $lastid
235  )
236  );
237 
238  return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
239  }
240 
241  private function assertUserLinks( $user, $cacheEntry ) {
242  $this->assertTag(
243  array(
244  'tag' => 'a',
245  'attributes' => array(
246  'class' => 'new mw-userlink'
247  ),
248  'content' => $user
249  ),
250  $cacheEntry->userlink,
251  'verify user link'
252  );
253 
254  $this->assertTag(
255  array(
256  'tag' => 'span',
257  'attributes' => array(
258  'class' => 'mw-usertoollinks'
259  ),
260  'child' => array(
261  'tag' => 'a',
262  'content' => 'Talk',
263  )
264  ),
265  $cacheEntry->usertalklink,
266  'verify user talk link'
267  );
268 
269  $this->assertTag(
270  array(
271  'tag' => 'span',
272  'attributes' => array(
273  'class' => 'mw-usertoollinks'
274  ),
275  'child' => array(
276  'tag' => 'a',
277  'content' => 'contribs',
278  )
279  ),
280  $cacheEntry->usertalklink,
281  'verify user tool links'
282  );
283  }
284 
285  private function assertDeleteLogLink( $cacheEntry ) {
286  $this->assertTag(
287  array(
288  'tag' => 'a',
289  'attributes' => array(
290  'href' => '/wiki/Special:Log/delete',
291  'title' => 'Special:Log/delete'
292  ),
293  'content' => 'Deletion log'
294  ),
295  $cacheEntry->link,
296  'verify deletion log link'
297  );
298  }
299 
300  private function assertRevDel( $cacheEntry ) {
301  $this->assertTag(
302  array(
303  'tag' => 'span',
304  'attributes' => array(
305  'class' => 'history-deleted'
306  ),
307  'content' => '(username removed)'
308  ),
309  $cacheEntry->userlink,
310  'verify user link for change with deleted revision and user'
311  );
312  }
313 
314  private function assertTitleLink( $title, $cacheEntry ) {
315  $this->assertTag(
316  array(
317  'tag' => 'a',
318  'attributes' => array(
319  'href' => '/wiki/' . $title,
320  'title' => $title
321  ),
322  'content' => $title
323  ),
324  $cacheEntry->link,
325  'verify title link'
326  );
327  }
328 
329  private function assertQueryLink( $content, $params, $link ) {
330  $this->assertTag(
331  array(
332  'tag' => 'a',
333  'content' => $content
334  ),
335  $link,
336  'assert query link element'
337  );
338 
339  foreach ( $params as $key => $value ) {
340  $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
341  }
342  }
343 
344  private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
345  $change = new RecentChange();
346  $change->setAttribs( $attribs );
347  $change->counter = $counter;
348  $change->numberofWatchingusers = $watchingUsers;
349 
350  return $change;
351  }
352 
353  private function getDefaultAttributes( $title, $timestamp ) {
354  return array(
355  'rc_id' => 545,
356  'rc_user' => 0,
357  'rc_user_text' => '127.0.0.1',
358  'rc_ip' => '127.0.0.1',
359  'rc_title' => $title,
360  'rc_namespace' => 0,
361  'rc_timestamp' => $timestamp,
362  'rc_cur_time' => $timestamp,
363  'rc_old_len' => 212,
364  'rc_new_len' => 188,
365  'rc_comment' => '',
366  'rc_minor' => 0,
367  'rc_bot' => 0,
368  'rc_type' => 0,
369  'rc_patrolled' => 1,
370  'rc_deleted' => 0,
371  'rc_logid' => 0,
372  'rc_log_type' => null,
373  'rc_log_action' => '',
374  'rc_params' => '',
375  'rc_source' => 'mw.edit'
376  );
377  }
378 
379  private function getTestUser() {
380  $user = User::newFromName( 'Mary' );
381 
382  if ( !$user->getId() ) {
383  $user->addToDatabase();
384  }
385 
386  return $user;
387  }
388 
389  private function getMessages() {
390  return array(
391  'cur' => 'cur',
392  'diff' => 'diff',
393  'hist' => 'hist',
394  'enhancedrc-history' => 'history',
395  'last' => 'prev',
396  'blocklink' => 'block',
397  'history' => 'Page history',
398  'semicolon-separator' => '; ',
399  'pipe-separator' => ' | '
400  );
401  }
402 
403  private function getContext() {
404  $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
405 
406  $context = new RequestContext();
407  $context->setTitle( $title );
408  $context->setLanguage( Language::factory( 'en' ) );
409 
410  $user = $this->getTestUser();
411  $context->setUser( $user );
412 
413  return $context;
414  }
415 }
RCCacheEntryFactoryTest\testNewForDeleteChange
testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched)
@dataProvider deleteChangeProvider
Definition: RCCacheEntryFactoryTest.php:98
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
RCCacheEntryFactoryTest\deleteChangeProvider
deleteChangeProvider()
Definition: RCCacheEntryFactoryTest.php:120
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
RCCacheEntryFactoryTest
@covers RCCacheEntryFactory
Definition: RCCacheEntryFactoryTest.php:11
RCCacheEntryFactoryTest\testNewForRevUserDeleteChange
testNewForRevUserDeleteChange( $expected, $context, $messages, $recentChange, $watched)
@dataProvider revUserDeleteProvider
Definition: RCCacheEntryFactoryTest.php:169
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:63
RCCacheEntryFactoryTest\getDefaultAttributes
getDefaultAttributes( $title, $timestamp)
Definition: RCCacheEntryFactoryTest.php:353
RCCacheEntryFactoryTest\editChangeProvider
editChangeProvider()
Definition: RCCacheEntryFactoryTest.php:47
RCCacheEntryFactoryTest\getMessages
getMessages()
Definition: RCCacheEntryFactoryTest.php:389
RCCacheEntryFactoryTest\assertDeleteLogLink
assertDeleteLogLink( $cacheEntry)
Definition: RCCacheEntryFactoryTest.php:285
RCCacheEntryFactoryTest\getTestUser
getTestUser()
Definition: RCCacheEntryFactoryTest.php:379
$params
$params
Definition: styleTest.css.php:40
RCCacheEntryFactoryTest\assertRevDel
assertRevDel( $cacheEntry)
Definition: RCCacheEntryFactoryTest.php:300
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
RCCacheEntryFactory
Definition: RCCacheEntryFactory.php:23
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2149
$messages
$messages
Definition: LogTests.i18n.php:8
RCCacheEntryFactoryTest\getContext
getContext()
Definition: RCCacheEntryFactoryTest.php:403
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:68
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
RCCacheEntryFactoryTest\assertTitleLink
assertTitleLink( $title, $cacheEntry)
Definition: RCCacheEntryFactoryTest.php:314
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
RCCacheEntryFactoryTest\testNewFromRecentChange
testNewFromRecentChange( $expected, $context, $messages, $recentChange, $watched)
@dataProvider editChangeProvider
Definition: RCCacheEntryFactoryTest.php:23
RCCacheEntryFactoryTest\revUserDeleteProvider
revUserDeleteProvider()
Definition: RCCacheEntryFactoryTest.php:193
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:30
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$value
$value
Definition: styleTest.css.php:45
RCCacheEntryFactoryTest\setUp
setUp()
Definition: RCCacheEntryFactoryTest.php:12
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
RCCacheEntryFactoryTest\makeEditRecentChange
makeEditRecentChange( $title, $user, $curid, $thisid, $lastid, $timestamp, $counter, $watchingUsers)
Definition: RCCacheEntryFactoryTest.php:77
RCCacheEntryFactoryTest\makeDeletedEditRecentChange
makeDeletedEditRecentChange( $title, $user, $timestamp, $curid, $thisid, $lastid, $counter, $watchingUsers)
Definition: RCCacheEntryFactoryTest.php:223
RCCacheEntryFactoryTest\assertUserLinks
assertUserLinks( $user, $cacheEntry)
Definition: RCCacheEntryFactoryTest.php:241
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
RCCacheEntryFactoryTest\assertQueryLink
assertQueryLink( $content, $params, $link)
Definition: RCCacheEntryFactoryTest.php:329
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1530
RCCacheEntryFactoryTest\makeLogRecentChange
makeLogRecentChange( $title, $user, $timestamp, $counter, $watchingUsers)
Definition: RCCacheEntryFactoryTest.php:145
RCCacheEntryFactoryTest\makeRecentChange
makeRecentChange( $attribs, $counter, $watchingUsers)
Definition: RCCacheEntryFactoryTest.php:344