MediaWiki  REL1_31
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::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 
110  public function testNewForRevUserDeleteChange() {
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">\‍(.*<a .+>talk</a>.*\‍)</span>#',
160  $cacheEntry->usertalklink,
161  'verify user talk link'
162  );
163 
164  $this->assertValidHTML( $cacheEntry->usertalklink );
165  $this->assertRegExp(
166  '#^ <span class="mw-usertoollinks">\‍(.*<a .+>contribs</a>.*\‍)</span>$#',
167  $cacheEntry->usertalklink,
168  'verify user tool links'
169  );
170  }
171 
172  private function assertDeleteLogLink( $cacheEntry ) {
173  $this->assertEquals(
174  '(<a href="/wiki/Special:Log/delete" title="Special:Log/delete">Deletion log</a>)',
175  $cacheEntry->link,
176  'verify deletion log link'
177  );
178 
179  $this->assertValidHTML( $cacheEntry->link );
180  }
181 
182  private function assertRevDel( $cacheEntry ) {
183  $this->assertEquals(
184  ' <span class="history-deleted">(username removed)</span>',
185  $cacheEntry->userlink,
186  'verify user link for change with deleted revision and user'
187  );
188  $this->assertValidHTML( $cacheEntry->userlink );
189  }
190 
191  private function assertTitleLink( $title, $cacheEntry ) {
192  $this->assertEquals(
193  '<a href="/wiki/' . $title . '" title="' . $title . '">' . $title . '</a>',
194  $cacheEntry->link,
195  'verify title link'
196  );
197  $this->assertValidHTML( $cacheEntry->link );
198  }
199 
200  private function assertQueryLink( $content, $params, $link ) {
201  $this->assertRegExp(
202  "#^<a .+>$content</a>$#",
203  $link,
204  'verify query link element'
205  );
206  $this->assertValidHTML( $link );
207 
208  foreach ( $params as $key => $value ) {
209  $this->assertRegExp( '/' . $key . '=' . $value . '/', $link, "verify $key link params" );
210  }
211  }
212 
213  private function getMessages() {
214  return [
215  'cur' => 'cur',
216  'diff' => 'diff',
217  'hist' => 'hist',
218  'enhancedrc-history' => 'history',
219  'last' => 'prev',
220  'blocklink' => 'block',
221  'history' => 'Page history',
222  'semicolon-separator' => '; ',
223  'pipe-separator' => ' | '
224  ];
225  }
226 
227  private function getContext() {
228  $user = $this->getMutableTestUser()->getUser();
229  $context = $this->testRecentChangesHelper->getTestContext( $user );
230 
231  $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
232  $context->setTitle( $title );
233 
234  return $context;
235  }
236 }
$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:247
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:273
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
RCCacheEntryFactoryTest
RCCacheEntryFactory.
Definition: RCCacheEntryFactoryTest.php:13
RCCacheEntryFactoryTest\$linkRenderer
LinkRenderer $linkRenderer
Definition: RCCacheEntryFactoryTest.php:23
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:41
RCCacheEntryFactoryTest\testNewForDeleteChange
testNewForDeleteChange()
Definition: RCCacheEntryFactoryTest.php:77
RCCacheEntryFactoryTest\testNewForRevUserDeleteChange
testNewForRevUserDeleteChange()
Definition: RCCacheEntryFactoryTest.php:110
RCCacheEntryFactoryTest\getMessages
getMessages()
Definition: RCCacheEntryFactoryTest.php:213
RCCacheEntryFactoryTest\assertDeleteLogLink
assertDeleteLogLink( $cacheEntry)
Definition: RCCacheEntryFactoryTest.php:172
load
MediaWiki has optional support for a high distributed memory object caching system For general information on but for a larger site with heavy load
Definition: memcached.txt:6
$params
$params
Definition: styleTest.css.php:40
RCCacheEntryFactoryTest\assertRevDel
assertRevDel( $cacheEntry)
Definition: RCCacheEntryFactoryTest.php:182
TestRecentChangesHelper
Helper for generating test recent changes entries.
Definition: TestRecentChangesHelper.php:10
RCCacheEntryFactory
Definition: RCCacheEntryFactory.php:24
php
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
RCCacheEntryFactoryTest\getContext
getContext()
Definition: RCCacheEntryFactoryTest.php:227
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:63
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:678
RCCacheEntryFactoryTest\assertTitleLink
assertTitleLink( $title, $cacheEntry)
Definition: RCCacheEntryFactoryTest.php:191
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3021
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
RCCacheEntryFactoryTest\$testRecentChangesHelper
TestRecentChangesHelper $testRecentChangesHelper
Definition: RCCacheEntryFactoryTest.php:18
$value
$value
Definition: styleTest.css.php:45
RCCacheEntryFactoryTest\setUp
setUp()
Definition: RCCacheEntryFactoryTest.php:31
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:165
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
RCCacheEntryFactoryTest\testNewFromRecentChange
testNewFromRecentChange()
Definition: RCCacheEntryFactoryTest.php:41
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
RCCacheEntryFactoryTest\assertUserLinks
assertUserLinks( $user, $cacheEntry)
Definition: RCCacheEntryFactoryTest.php:149
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:22
RCCacheEntryFactoryTest\assertQueryLink
assertQueryLink( $content, $params, $link)
Definition: RCCacheEntryFactoryTest.php:200
RCCacheEntryFactoryTest\__construct
__construct( $name=null, array $data=[], $dataName='')
Definition: RCCacheEntryFactoryTest.php:25
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
MediaWikiServices
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:25
RCCacheEntryFactoryTest\assertValidHTML
assertValidHTML( $actual)
Definition: RCCacheEntryFactoryTest.php:144
$context
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:2811