MediaWiki REL1_33
EnhancedChangesListTest.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
24 $enhancedChangesList = $this->newEnhancedChangesList();
25 $enhancedChangesList->beginRecentChangesList();
26
27 $styleModules = $enhancedChangesList->getOutput()->getModuleStyles();
28
29 $this->assertContains(
30 'mediawiki.icon',
31 $styleModules,
32 'has mediawiki.icon'
33 );
34
35 $this->assertContains(
36 'mediawiki.special.changeslist',
37 $styleModules,
38 'has mediawiki.special.changeslist'
39 );
40
41 $this->assertContains(
42 'mediawiki.special.changeslist.enhanced',
43 $styleModules,
44 'has mediawiki.special.changeslist.enhanced'
45 );
46 }
47
49 $enhancedChangesList = $this->newEnhancedChangesList();
50 $enhancedChangesList->beginRecentChangesList();
51
52 $modules = $enhancedChangesList->getOutput()->getModules();
53
54 $this->assertContains( 'jquery.makeCollapsible', $modules, 'has jquery.makeCollapsible' );
55 }
56
58 $enhancedChangesList = $this->newEnhancedChangesList();
59 $html = $enhancedChangesList->beginRecentChangesList();
60
61 $this->assertEquals( '<div class="mw-changeslist">', $html );
62 }
63
67 public function testRecentChangesLine() {
68 $enhancedChangesList = $this->newEnhancedChangesList();
69 $enhancedChangesList->beginRecentChangesList();
70
71 $recentChange = $this->getEditChange( '20131103092153' );
72 $html = $enhancedChangesList->recentChangesLine( $recentChange, false );
73
74 $this->assertInternalType( 'string', $html );
75
76 $recentChange2 = $this->getEditChange( '20131103092253' );
77 $html = $enhancedChangesList->recentChangesLine( $recentChange2, false );
78
79 $this->assertEquals( '', $html );
80 }
81
82 public function testRecentChangesPrefix() {
83 $mockContext = $this->getMockBuilder( RequestContext::class )
84 ->setMethods( [ 'getTitle' ] )
85 ->getMock();
86 $mockContext->method( 'getTitle' )
87 ->will( $this->returnValue( Title::newFromText( 'Expected Context Title' ) ) );
88
89 // One group of two lines
90 $enhancedChangesList = $this->newEnhancedChangesList();
91 $enhancedChangesList->setContext( $mockContext );
92 $enhancedChangesList->setChangeLinePrefixer( function ( $rc, $changesList ) {
93 // Make sure RecentChange and ChangesList objects are the same
94 $this->assertEquals( 'Expected Context Title', $changesList->getContext()->getTitle() );
95 $this->assertTrue( $rc->getTitle() == 'Cat' || $rc->getTitle() == 'Dog' );
96 return 'Hello world prefix';
97 } );
98 $enhancedChangesList->beginRecentChangesList();
99
100 $recentChange = $this->getEditChange( '20131103092153' );
101 $enhancedChangesList->recentChangesLine( $recentChange );
102 $recentChange = $this->getEditChange( '20131103092154' );
103 $enhancedChangesList->recentChangesLine( $recentChange );
104
105 $html = $enhancedChangesList->endRecentChangesList();
106
107 $this->assertRegExp( '/Hello world prefix/', $html );
108
109 // Two separate lines
110 $enhancedChangesList->beginRecentChangesList();
111
112 $recentChange = $this->getEditChange( '20131103092153' );
113 $enhancedChangesList->recentChangesLine( $recentChange );
114 $recentChange = $this->getEditChange( '20131103092154', 'Dog' );
115 $enhancedChangesList->recentChangesLine( $recentChange );
116
117 $html = $enhancedChangesList->endRecentChangesList();
118
119 preg_match_all( '/Hello world prefix/', $html, $matches );
120 $this->assertCount( 2, $matches[0] );
121 }
122
125 $this->getCategorizationChange( '20150629191735', 0, 0 )
126 );
127 $this->assertNotContains( 'diffhist', strip_tags( $html ) );
128 }
129
132 $this->getCategorizationChange( '20150629191735', 1025, 1024 )
133 );
134 $this->assertContains( 'diffhist', strip_tags( $html ) );
135 }
136
140 public function testEndRecentChangesList() {
141 $enhancedChangesList = $this->newEnhancedChangesList();
142 $enhancedChangesList->beginRecentChangesList();
143
144 $recentChange = $this->getEditChange( '20131103092153' );
145 $enhancedChangesList->recentChangesLine( $recentChange, false );
146
147 $html = $enhancedChangesList->endRecentChangesList();
148 $this->assertRegExp(
149 '/data-mw-revid="5" data-mw-ts="20131103092153" class="[^"]*mw-enhanced-rc[^"]*"/',
150 $html
151 );
152
153 $recentChange2 = $this->getEditChange( '20131103092253' );
154 $enhancedChangesList->recentChangesLine( $recentChange2, false );
155
156 $html = $enhancedChangesList->endRecentChangesList();
157
158 preg_match_all( '/td class="mw-enhanced-rc-nested"/', $html, $matches );
159 $this->assertCount( 2, $matches[0] );
160
161 preg_match_all( '/data-target-page="Cat"/', $html, $matches );
162 $this->assertCount( 2, $matches[0] );
163
164 $recentChange3 = $this->getLogChange();
165 $enhancedChangesList->recentChangesLine( $recentChange3, false );
166
167 $html = $enhancedChangesList->endRecentChangesList();
168 $this->assertContains( 'data-mw-logaction="foo/bar"', $html );
169 $this->assertContains( 'data-mw-logid="25"', $html );
170 $this->assertContains( 'data-target-page="Title"', $html );
171 }
172
176 private function newEnhancedChangesList() {
177 $user = User::newFromId( 0 );
178 $context = $this->testRecentChangesHelper->getTestContext( $user );
179
180 return new EnhancedChangesList( $context );
181 }
182
186 private function getEditChange( $timestamp, $pageTitle = 'Cat' ) {
187 $user = $this->getMutableTestUser()->getUser();
188 $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
189 $user, $pageTitle, 0, 5, 191, $timestamp, 0, 0
190 );
191
192 return $recentChange;
193 }
194
195 private function getLogChange() {
196 $user = $this->getMutableTestUser()->getUser();
197 $recentChange = $this->testRecentChangesHelper->makeLogRecentChange( 'foo', 'bar', $user,
198 'Title', '20131103092153', 0, 0
199 );
200
201 return $recentChange;
202 }
203
207 private function getCategorizationChange( $timestamp, $thisId, $lastId ) {
208 $wikiPage = new WikiPage( Title::newFromText( 'Testpage' ) );
209 $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'page created' );
210
211 $wikiPage = new WikiPage( Title::newFromText( 'Category:Foo' ) );
212 $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'category page created' );
213
214 $user = $this->getMutableTestUser()->getUser();
215 $recentChange = $this->testRecentChangesHelper->makeCategorizationRecentChange(
216 $user, 'Category:Foo', $wikiPage->getId(), $thisId, $lastId, $timestamp
217 );
218
219 return $recentChange;
220 }
221
222 private function createCategorizationLine( $recentChange ) {
223 $enhancedChangesList = $this->newEnhancedChangesList();
224 $cacheEntry = $this->testRecentChangesHelper->getCacheEntry( $recentChange );
225
226 $reflection = new \ReflectionClass( get_class( $enhancedChangesList ) );
227 $method = $reflection->getMethod( 'recentChangesBlockLine' );
228 $method->setAccessible( true );
229
230 return $method->invokeArgs( $enhancedChangesList, [ $cacheEntry ] );
231 }
232
233}
getContext()
Get the base IContextSource object.
TestRecentChangesHelper $testRecentChangesHelper
__construct( $name=null, array $data=[], $dataName='')
getEditChange( $timestamp, $pageTitle='Cat')
getCategorizationChange( $timestamp, $thisId, $lastId)
Base class that store and restore the Language objects.
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Helper for generating test recent changes entries.
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:609
Class representing a MediaWiki article and history.
Definition WikiPage.php:45
Content object for wiki text pages.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges $changesList
Definition hooks.txt:1541
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
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 & $html
Definition hooks.txt:2011
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))