MediaWiki  1.27.2
RCCacheEntryFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
11 
16 
17  public function __construct( $name = null, array $data = [], $dataName = '' ) {
18  parent::__construct( $name, $data, $dataName );
19 
20  $this->testRecentChangesHelper = new TestRecentChangesHelper();
21  }
22 
23  protected function setUp() {
24  parent::setUp();
25 
26  $this->setMwGlobals( [
27  'wgArticlePath' => '/wiki/$1'
28  ] );
29  }
30 
34  public function testNewFromRecentChange( $expected, $context, $messages,
35  $recentChange, $watched
36  ) {
37  $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
38  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
39 
40  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
41 
42  $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
43  $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
44  $this->assertEquals(
45  $expected['numberofWatchingusers'], $cacheEntry->numberofWatchingusers,
46  'watching users'
47  );
48  $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
49 
50  $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
51  $this->assertTitleLink( 'Xyz', $cacheEntry );
52 
53  $this->assertQueryLink( 'cur', $expected['cur'], $cacheEntry->curlink, 'cur link' );
54  $this->assertQueryLink( 'prev', $expected['diff'], $cacheEntry->lastlink, 'prev link' );
55  $this->assertQueryLink( 'diff', $expected['diff'], $cacheEntry->difflink, 'diff link' );
56  }
57 
58  public function editChangeProvider() {
59  return [
60  [
61  [
62  'title' => 'Xyz',
63  'user' => 'TestRecentChangesUser',
64  'diff' => [ 'curid' => 5, 'diff' => 191, 'oldid' => 190 ],
65  'cur' => [ 'curid' => 5, 'diff' => 0, 'oldid' => 191 ],
66  'timestamp' => '21:21',
67  'numberofWatchingusers' => 0,
68  'unpatrolled' => false
69  ],
70  $this->getContext(),
71  $this->getMessages(),
72  $this->testRecentChangesHelper->makeEditRecentChange(
73  $this->getTestUser(),
74  'Xyz',
75  5, // curid
76  191, // thisid
77  190, // lastid
78  '20131103212153',
79  0, // counter
80  0 // number of watching users
81  ),
82  false
83  ]
84  ];
85  }
86 
90  public function testNewForDeleteChange( $expected, $context, $messages, $recentChange, $watched ) {
91  $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
92  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
93 
94  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
95 
96  $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
97  $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
98  $this->assertEquals(
99  $expected['numberofWatchingusers'],
100  $cacheEntry->numberofWatchingusers, 'watching users'
101  );
102  $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
103 
104  $this->assertDeleteLogLink( $cacheEntry );
105  $this->assertUserLinks( 'TestRecentChangesUser', $cacheEntry );
106 
107  $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
108  $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
109  $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
110  }
111 
112  public function deleteChangeProvider() {
113  return [
114  [
115  [
116  'title' => 'Abc',
117  'user' => 'TestRecentChangesUser',
118  'timestamp' => '21:21',
119  'numberofWatchingusers' => 0,
120  'unpatrolled' => false
121  ],
122  $this->getContext(),
123  $this->getMessages(),
124  $this->testRecentChangesHelper->makeLogRecentChange(
125  'delete',
126  'delete',
127  $this->getTestUser(),
128  'Abc',
129  '20131103212153',
130  0, // counter
131  0 // number of watching users
132  ),
133  false
134  ]
135  ];
136  }
137 
141  public function testNewForRevUserDeleteChange( $expected, $context, $messages,
142  $recentChange, $watched
143  ) {
144  $cacheEntryFactory = new RCCacheEntryFactory( $context, $messages );
145  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, $watched );
146 
147  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
148 
149  $this->assertEquals( $watched, $cacheEntry->watched, 'watched' );
150  $this->assertEquals( $expected['timestamp'], $cacheEntry->timestamp, 'timestamp' );
151  $this->assertEquals(
152  $expected['numberofWatchingusers'],
153  $cacheEntry->numberofWatchingusers, 'watching users'
154  );
155  $this->assertEquals( $expected['unpatrolled'], $cacheEntry->unpatrolled, 'unpatrolled' );
156 
157  $this->assertRevDel( $cacheEntry );
158  $this->assertTitleLink( 'Zzz', $cacheEntry );
159 
160  $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
161  $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
162  $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
163  }
164 
165  public function revUserDeleteProvider() {
166  return [
167  [
168  [
169  'title' => 'Zzz',
170  'user' => 'TestRecentChangesUser',
171  'diff' => '',
172  'cur' => '',
173  'timestamp' => '21:21',
174  'numberofWatchingusers' => 0,
175  'unpatrolled' => false
176  ],
177  $this->getContext(),
178  $this->getMessages(),
179  $this->testRecentChangesHelper->makeDeletedEditRecentChange(
180  $this->getTestUser(),
181  'Zzz',
182  '20131103212153',
183  191, // thisid
184  190, // lastid
185  '20131103212153',
186  0, // counter
187  0 // number of watching users
188  ),
189  false
190  ]
191  ];
192  }
193 
194  private function assertUserLinks( $user, $cacheEntry ) {
195  $this->assertTag(
196  [
197  'tag' => 'a',
198  'attributes' => [
199  'class' => 'new mw-userlink'
200  ],
201  'content' => $user
202  ],
203  $cacheEntry->userlink,
204  'verify user link'
205  );
206 
207  $this->assertTag(
208  [
209  'tag' => 'span',
210  'attributes' => [
211  'class' => 'mw-usertoollinks'
212  ],
213  'child' => [
214  'tag' => 'a',
215  'content' => 'talk',
216  ]
217  ],
218  $cacheEntry->usertalklink,
219  'verify user talk link'
220  );
221 
222  $this->assertTag(
223  [
224  'tag' => 'span',
225  'attributes' => [
226  'class' => 'mw-usertoollinks'
227  ],
228  'child' => [
229  'tag' => 'a',
230  'content' => 'contribs',
231  ]
232  ],
233  $cacheEntry->usertalklink,
234  'verify user tool links'
235  );
236  }
237 
238  private function assertDeleteLogLink( $cacheEntry ) {
239  $this->assertTag(
240  [
241  'tag' => 'a',
242  'attributes' => [
243  'href' => '/wiki/Special:Log/delete',
244  'title' => 'Special:Log/delete'
245  ],
246  'content' => 'Deletion log'
247  ],
248  $cacheEntry->link,
249  'verify deletion log link'
250  );
251  }
252 
253  private function assertRevDel( $cacheEntry ) {
254  $this->assertTag(
255  [
256  'tag' => 'span',
257  'attributes' => [
258  'class' => 'history-deleted'
259  ],
260  'content' => '(username removed)'
261  ],
262  $cacheEntry->userlink,
263  'verify user link for change with deleted revision and user'
264  );
265  }
266 
267  private function assertTitleLink( $title, $cacheEntry ) {
268  $this->assertTag(
269  [
270  'tag' => 'a',
271  'attributes' => [
272  'href' => '/wiki/' . $title,
273  'title' => $title
274  ],
275  'content' => $title
276  ],
277  $cacheEntry->link,
278  'verify title link'
279  );
280  }
281 
282  private function assertQueryLink( $content, $params, $link ) {
283  $this->assertTag(
284  [
285  'tag' => 'a',
286  'content' => $content
287  ],
288  $link,
289  'assert query link element'
290  );
291 
292  foreach ( $params as $key => $value ) {
293  $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
294  }
295  }
296 
297  private function getMessages() {
298  return [
299  'cur' => 'cur',
300  'diff' => 'diff',
301  'hist' => 'hist',
302  'enhancedrc-history' => 'history',
303  'last' => 'prev',
304  'blocklink' => 'block',
305  'history' => 'Page history',
306  'semicolon-separator' => '; ',
307  'pipe-separator' => ' | '
308  ];
309  }
310 
311  private function getTestUser() {
312  $user = User::newFromName( 'TestRecentChangesUser' );
313 
314  if ( !$user->getId() ) {
315  $user->addToDatabase();
316  }
317 
318  return $user;
319  }
320 
321  private function getContext() {
322  $user = $this->getTestUser();
323  $context = $this->testRecentChangesHelper->getTestContext( $user );
324 
325  $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
326  $context->setTitle( $title );
327 
328  return $context;
329  }
330 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:568
the array() calling protocol came about after MediaWiki 1.4rc1.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
$context
Definition: load.php:44
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
$value
Helper for generating test recent changes entries.
const NS_SPECIAL
Definition: Defines.php:58
testNewForRevUserDeleteChange($expected, $context, $messages, $recentChange, $watched)
revUserDeleteProvider
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition: hooks.txt:2581
assertTitleLink($title, $cacheEntry)
TestRecentChangesHelper $testRecentChangesHelper
static assertTag($matcher, $actual, $message= '', $isHtml=true)
Note: we are overriding this method to remove the deprecated error.
__construct($name=null, array $data=[], $dataName= '')
testNewForDeleteChange($expected, $context, $messages, $recentChange, $watched)
deleteChangeProvider
$params
Base class that store and restore the Language objects.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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
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 local account $user
Definition: hooks.txt:242
assertQueryLink($content, $params, $link)
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition: hooks.txt:1004
testNewFromRecentChange($expected, $context, $messages, $recentChange, $watched)
editChangeProvider
assertUserLinks($user, $cacheEntry)
$messages
setMwGlobals($pairs, $value=null)
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310