MediaWiki  1.28.0
RCCacheEntryFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
5 
14 
19 
23  private $linkRenderer;
24 
25  public function __construct( $name = null, array $data = [], $dataName = '' ) {
26  parent::__construct( $name, $data, $dataName );
27 
28  $this->testRecentChangesHelper = new TestRecentChangesHelper();
29  }
30 
31  protected function setUp() {
32  parent::setUp();
33 
34  $this->setMwGlobals( [
35  'wgArticlePath' => '/wiki/$1'
36  ] );
37 
38  $this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
39  }
40 
41  public function testNewFromRecentChange() {
42  $user = $this->getMutableTestUser()->getUser();
43  $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
44  $user,
45  'Xyz',
46  5, // curid
47  191, // thisid
48  190, // lastid
49  '20131103212153',
50  0, // counter
51  0 // number of watching users
52  );
53  $cacheEntryFactory = new RCCacheEntryFactory(
54  $this->getContext(),
55  $this->getMessages(),
56  $this->linkRenderer
57  );
58  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
59 
60  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
61 
62  $this->assertEquals( false, $cacheEntry->watched, 'watched' );
63  $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' );
64  $this->assertEquals( 0, $cacheEntry->numberofWatchingusers, 'watching users' );
65  $this->assertEquals( false, $cacheEntry->unpatrolled, 'unpatrolled' );
66 
67  $this->assertUserLinks( $user->getName(), $cacheEntry );
68  $this->assertTitleLink( 'Xyz', $cacheEntry );
69 
70  $diff = [ 'curid' => 5, 'diff' => 191, 'oldid' => 190 ];
71  $cur = [ 'curid' => 5, 'diff' => 0, 'oldid' => 191 ];
72  $this->assertQueryLink( 'cur', $cur, $cacheEntry->curlink, 'cur link' );
73  $this->assertQueryLink( 'prev', $diff, $cacheEntry->lastlink, 'prev link' );
74  $this->assertQueryLink( 'diff', $diff, $cacheEntry->difflink, 'diff link' );
75  }
76 
77  public function testNewForDeleteChange() {
78  $expected = [
79  'title' => 'Abc',
80  'user' => 'TestRecentChangesUser',
81  'timestamp' => '21:21',
82  'numberofWatchingusers' => 0,
83  'unpatrolled' => false
84  ];
85  $user = $this->getMutableTestUser()->getUser();
86  $recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
87  'delete',
88  'delete',
89  $user,
90  'Abc',
91  '20131103212153',
92  0, // counter
93  0 // number of watching users
94  );
95  $cacheEntryFactory = new RCCacheEntryFactory(
96  $this->getContext(),
97  $this->getMessages(),
98  $this->linkRenderer
99  );
100  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
101 
102  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
103 
104  $this->assertEquals( false, $cacheEntry->watched, 'watched' );
105  $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' );
106  $this->assertEquals( 0, $cacheEntry->numberofWatchingusers, 'watching users' );
107  $this->assertEquals( false, $cacheEntry->unpatrolled, 'unpatrolled' );
108 
109  $this->assertDeleteLogLink( $cacheEntry );
110  $this->assertUserLinks( $user->getName(), $cacheEntry );
111 
112  $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
113  $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
114  $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
115  }
116 
117  public function testNewForRevUserDeleteChange() {
118  $user = $this->getMutableTestUser()->getUser();
119  $recentChange = $this->testRecentChangesHelper->makeDeletedEditRecentChange(
120  $user,
121  'Zzz',
122  '20131103212153',
123  191, // thisid
124  190, // lastid
125  '20131103212153',
126  0, // counter
127  0 // number of watching users
128  );
129  $cacheEntryFactory = new RCCacheEntryFactory(
130  $this->getContext(),
131  $this->getMessages(),
132  $this->linkRenderer
133  );
134  $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
135 
136  $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry );
137 
138  $this->assertEquals( false, $cacheEntry->watched, 'watched' );
139  $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' );
140  $this->assertEquals( 0, $cacheEntry->numberofWatchingusers, 'watching users' );
141  $this->assertEquals( false, $cacheEntry->unpatrolled, 'unpatrolled' );
142 
143  $this->assertRevDel( $cacheEntry );
144  $this->assertTitleLink( 'Zzz', $cacheEntry );
145 
146  $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
147  $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
148  $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
149  }
150 
151  private function assertUserLinks( $user, $cacheEntry ) {
152  $this->assertTag(
153  [
154  'tag' => 'a',
155  'attributes' => [
156  'class' => 'new mw-userlink'
157  ],
158  'content' => $user
159  ],
160  $cacheEntry->userlink,
161  'verify user link'
162  );
163 
164  $this->assertTag(
165  [
166  'tag' => 'span',
167  'attributes' => [
168  'class' => 'mw-usertoollinks'
169  ],
170  'child' => [
171  'tag' => 'a',
172  'content' => 'talk',
173  ]
174  ],
175  $cacheEntry->usertalklink,
176  'verify user talk link'
177  );
178 
179  $this->assertTag(
180  [
181  'tag' => 'span',
182  'attributes' => [
183  'class' => 'mw-usertoollinks'
184  ],
185  'child' => [
186  'tag' => 'a',
187  'content' => 'contribs',
188  ]
189  ],
190  $cacheEntry->usertalklink,
191  'verify user tool links'
192  );
193  }
194 
195  private function assertDeleteLogLink( $cacheEntry ) {
196  $this->assertTag(
197  [
198  'tag' => 'a',
199  'attributes' => [
200  'href' => '/wiki/Special:Log/delete',
201  'title' => 'Special:Log/delete'
202  ],
203  'content' => 'Deletion log'
204  ],
205  $cacheEntry->link,
206  'verify deletion log link'
207  );
208  }
209 
210  private function assertRevDel( $cacheEntry ) {
211  $this->assertTag(
212  [
213  'tag' => 'span',
214  'attributes' => [
215  'class' => 'history-deleted'
216  ],
217  'content' => '(username removed)'
218  ],
219  $cacheEntry->userlink,
220  'verify user link for change with deleted revision and user'
221  );
222  }
223 
224  private function assertTitleLink( $title, $cacheEntry ) {
225  $this->assertTag(
226  [
227  'tag' => 'a',
228  'attributes' => [
229  'href' => '/wiki/' . $title,
230  'title' => $title
231  ],
232  'content' => $title
233  ],
234  $cacheEntry->link,
235  'verify title link'
236  );
237  }
238 
239  private function assertQueryLink( $content, $params, $link ) {
240  $this->assertTag(
241  [
242  'tag' => 'a',
243  'content' => $content
244  ],
245  $link,
246  'assert query link element'
247  );
248 
249  foreach ( $params as $key => $value ) {
250  $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
251  }
252  }
253 
254  private function getMessages() {
255  return [
256  'cur' => 'cur',
257  'diff' => 'diff',
258  'hist' => 'hist',
259  'enhancedrc-history' => 'history',
260  'last' => 'prev',
261  'blocklink' => 'block',
262  'history' => 'Page history',
263  'semicolon-separator' => '; ',
264  'pipe-separator' => ' | '
265  ];
266  }
267 
268  private function getContext() {
269  $user = $this->getMutableTestUser()->getUser();
270  $context = $this->testRecentChangesHelper->getTestContext( $user );
271 
272  $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
273  $context->setTitle( $title );
274 
275  return $context;
276  }
277 }
the array() calling protocol came about after MediaWiki 1.4rc1.
$context
Definition: load.php:50
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$value
Helper for generating test recent changes entries.
const NS_SPECIAL
Definition: Defines.php:45
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 MediaWikiServices
Definition: injection.txt:23
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:262
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2889
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= '')
$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:953
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:1046
assertUserLinks($user, $cacheEntry)
static getMutableTestUser($groups=[])
Convenience method for getting a mutable test user.
setMwGlobals($pairs, $value=null)
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300