MediaWiki REL1_33
RCCacheEntryFactoryTest.php
Go to the documentation of this file.
1<?php
2
5
14
19
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::class, $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 );
73 $this->assertQueryLink( 'prev', $diff, $cacheEntry->lastlink );
74 $this->assertQueryLink( 'diff', $diff, $cacheEntry->difflink );
75 }
76
77 public function testNewForDeleteChange() {
78 $user = $this->getMutableTestUser()->getUser();
79 $recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
80 'delete',
81 'delete',
82 $user,
83 'Abc',
84 '20131103212153',
85 0, // counter
86 0 // number of watching users
87 );
88 $cacheEntryFactory = new RCCacheEntryFactory(
89 $this->getContext(),
90 $this->getMessages(),
91 $this->linkRenderer
92 );
93 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
94
95 $this->assertInstanceOf( RCCacheEntry::class, $cacheEntry );
96
97 $this->assertEquals( false, $cacheEntry->watched, 'watched' );
98 $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' );
99 $this->assertEquals( 0, $cacheEntry->numberofWatchingusers, 'watching users' );
100 $this->assertEquals( false, $cacheEntry->unpatrolled, 'unpatrolled' );
101
102 $this->assertDeleteLogLink( $cacheEntry );
103 $this->assertUserLinks( $user->getName(), $cacheEntry );
104
105 $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
106 $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
107 $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
108 }
109
111 $user = $this->getMutableTestUser()->getUser();
112 $recentChange = $this->testRecentChangesHelper->makeDeletedEditRecentChange(
113 $user,
114 'Zzz',
115 '20131103212153',
116 191, // thisid
117 190, // lastid
118 '20131103212153',
119 0, // counter
120 0 // number of watching users
121 );
122 $cacheEntryFactory = new RCCacheEntryFactory(
123 $this->getContext(),
124 $this->getMessages(),
125 $this->linkRenderer
126 );
127 $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false );
128
129 $this->assertInstanceOf( RCCacheEntry::class, $cacheEntry );
130
131 $this->assertEquals( false, $cacheEntry->watched, 'watched' );
132 $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' );
133 $this->assertEquals( 0, $cacheEntry->numberofWatchingusers, 'watching users' );
134 $this->assertEquals( false, $cacheEntry->unpatrolled, 'unpatrolled' );
135
136 $this->assertRevDel( $cacheEntry );
137 $this->assertTitleLink( 'Zzz', $cacheEntry );
138
139 $this->assertEquals( 'cur', $cacheEntry->curlink, 'cur link for delete log or rev' );
140 $this->assertEquals( 'diff', $cacheEntry->difflink, 'diff link for delete log or rev' );
141 $this->assertEquals( 'prev', $cacheEntry->lastlink, 'pref link for delete log or rev' );
142 }
143
144 private function assertValidHTML( $actual ) {
145 // Throws if invalid
146 $doc = PHPUnit_Util_XML::load( $actual, /* isHtml */ true );
147 }
148
149 private function assertUserLinks( $user, $cacheEntry ) {
150 $this->assertValidHTML( $cacheEntry->userlink );
151 $this->assertRegExp(
152 '#^<a .*class="new mw-userlink".*><bdi>' . $user . '</bdi></a>#',
153 $cacheEntry->userlink,
154 'verify user link'
155 );
156
157 $this->assertValidHTML( $cacheEntry->usertalklink );
158 $this->assertRegExp(
159 '#^ <span class="mw-usertoollinks mw-changeslist-links">.*<span><a .+>talk</a></span>.*</span>#',
160 $cacheEntry->usertalklink,
161 'verify user talk link'
162 );
163
164 $this->assertValidHTML( $cacheEntry->usertalklink );
165 $this->assertRegExp(
166 '#^ <span class="mw-usertoollinks mw-changeslist-links">.*<span><a .+>' .
167 'contribs</a></span>.*</span>$#',
168 $cacheEntry->usertalklink,
169 'verify user tool links'
170 );
171 }
172
173 private function assertDeleteLogLink( $cacheEntry ) {
174 $this->assertEquals(
175 '(<a href="/wiki/Special:Log/delete" title="Special:Log/delete">Deletion log</a>)',
176 $cacheEntry->link,
177 'verify deletion log link'
178 );
179
180 $this->assertValidHTML( $cacheEntry->link );
181 }
182
183 private function assertRevDel( $cacheEntry ) {
184 $this->assertEquals(
185 ' <span class="history-deleted">(username removed)</span>',
186 $cacheEntry->userlink,
187 'verify user link for change with deleted revision and user'
188 );
189 $this->assertValidHTML( $cacheEntry->userlink );
190 }
191
192 private function assertTitleLink( $title, $cacheEntry ) {
193 $this->assertEquals(
194 '<a href="/wiki/' . $title . '" title="' . $title . '">' . $title . '</a>',
195 $cacheEntry->link,
196 'verify title link'
197 );
198 $this->assertValidHTML( $cacheEntry->link );
199 }
200
201 private function assertQueryLink( $content, $params, $link ) {
202 $this->assertRegExp(
203 "#^<a .+>$content</a>$#",
204 $link,
205 'verify query link element'
206 );
207 $this->assertValidHTML( $link );
208
209 foreach ( $params as $key => $value ) {
210 $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
211 }
212 }
213
214 private function getMessages() {
215 return [
216 'cur' => 'cur',
217 'diff' => 'diff',
218 'hist' => 'hist',
219 'enhancedrc-history' => 'history',
220 'last' => 'prev',
221 'blocklink' => 'block',
222 'history' => 'Page history',
223 'semicolon-separator' => '; ',
224 'pipe-separator' => ' | '
225 ];
226 }
227
228 private function getContext() {
229 $user = $this->getMutableTestUser()->getUser();
230 $context = $this->testRecentChangesHelper->getTestContext( $user );
231
232 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
233 $context->setTitle( $title );
234
235 return $context;
236 }
237}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Base class that store and restore the Language objects.
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Class that generates HTML links for pages.
MediaWikiServices is the service locator for the application scope of MediaWiki.
TestRecentChangesHelper $testRecentChangesHelper
__construct( $name=null, array $data=[], $dataName='')
assertUserLinks( $user, $cacheEntry)
assertQueryLink( $content, $params, $link)
assertTitleLink( $title, $cacheEntry)
Helper for generating test recent changes entries.
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
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
const NS_SPECIAL
Definition Defines.php:62
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2848
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:3069
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
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:37
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$content
$params