MediaWiki REL1_32
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.special.changeslist',
31 $styleModules,
32 'has mediawiki.special.changeslist'
33 );
34
35 $this->assertContains(
36 'mediawiki.special.changeslist.enhanced',
37 $styleModules,
38 'has mediawiki.special.changeslist.enhanced'
39 );
40 }
41
43 $enhancedChangesList = $this->newEnhancedChangesList();
44 $enhancedChangesList->beginRecentChangesList();
45
46 $modules = $enhancedChangesList->getOutput()->getModules();
47
48 $this->assertContains( 'jquery.makeCollapsible', $modules, 'has jquery.makeCollapsible' );
49 $this->assertContains( 'mediawiki.icon', $modules, 'has mediawiki.icon' );
50 }
51
53 $enhancedChangesList = $this->newEnhancedChangesList();
54 $html = $enhancedChangesList->beginRecentChangesList();
55
56 $this->assertEquals( '<div class="mw-changeslist">', $html );
57 }
58
62 public function testRecentChangesLine() {
63 $enhancedChangesList = $this->newEnhancedChangesList();
64 $enhancedChangesList->beginRecentChangesList();
65
66 $recentChange = $this->getEditChange( '20131103092153' );
67 $html = $enhancedChangesList->recentChangesLine( $recentChange, false );
68
69 $this->assertInternalType( 'string', $html );
70
71 $recentChange2 = $this->getEditChange( '20131103092253' );
72 $html = $enhancedChangesList->recentChangesLine( $recentChange2, false );
73
74 $this->assertEquals( '', $html );
75 }
76
77 public function testRecentChangesPrefix() {
78 $mockContext = $this->getMockBuilder( RequestContext::class )
79 ->setMethods( [ 'getTitle' ] )
80 ->getMock();
81 $mockContext->method( 'getTitle' )
82 ->will( $this->returnValue( Title::newFromText( 'Expected Context Title' ) ) );
83
84 // One group of two lines
85 $enhancedChangesList = $this->newEnhancedChangesList();
86 $enhancedChangesList->setContext( $mockContext );
87 $enhancedChangesList->setChangeLinePrefixer( function ( $rc, $changesList ) {
88 // Make sure RecentChange and ChangesList objects are the same
89 $this->assertEquals( 'Expected Context Title', $changesList->getContext()->getTitle() );
90 $this->assertTrue( $rc->getTitle() == 'Cat' || $rc->getTitle() == 'Dog' );
91 return 'Hello world prefix';
92 } );
93 $enhancedChangesList->beginRecentChangesList();
94
95 $recentChange = $this->getEditChange( '20131103092153' );
96 $enhancedChangesList->recentChangesLine( $recentChange );
97 $recentChange = $this->getEditChange( '20131103092154' );
98 $enhancedChangesList->recentChangesLine( $recentChange );
99
100 $html = $enhancedChangesList->endRecentChangesList();
101
102 $this->assertRegExp( '/Hello world prefix/', $html );
103
104 // Two separate lines
105 $enhancedChangesList->beginRecentChangesList();
106
107 $recentChange = $this->getEditChange( '20131103092153' );
108 $enhancedChangesList->recentChangesLine( $recentChange );
109 $recentChange = $this->getEditChange( '20131103092154', 'Dog' );
110 $enhancedChangesList->recentChangesLine( $recentChange );
111
112 $html = $enhancedChangesList->endRecentChangesList();
113
114 preg_match_all( '/Hello world prefix/', $html, $matches );
115 $this->assertCount( 2, $matches[0] );
116 }
117
120 $this->getCategorizationChange( '20150629191735', 0, 0 )
121 );
122 $this->assertNotContains( '(diff | hist)', strip_tags( $html ) );
123 }
124
127 $this->getCategorizationChange( '20150629191735', 1025, 1024 )
128 );
129 $this->assertContains( '(diff | hist)', strip_tags( $html ) );
130 }
131
135 public function testEndRecentChangesList() {
136 $enhancedChangesList = $this->newEnhancedChangesList();
137 $enhancedChangesList->beginRecentChangesList();
138
139 $recentChange = $this->getEditChange( '20131103092153' );
140 $enhancedChangesList->recentChangesLine( $recentChange, false );
141
142 $html = $enhancedChangesList->endRecentChangesList();
143 $this->assertRegExp(
144 '/data-mw-revid="5" data-mw-ts="20131103092153" class="[^"]*mw-enhanced-rc[^"]*"/',
145 $html
146 );
147
148 $recentChange2 = $this->getEditChange( '20131103092253' );
149 $enhancedChangesList->recentChangesLine( $recentChange2, false );
150
151 $html = $enhancedChangesList->endRecentChangesList();
152
153 preg_match_all( '/td class="mw-enhanced-rc-nested"/', $html, $matches );
154 $this->assertCount( 2, $matches[0] );
155
156 preg_match_all( '/data-target-page="Cat"/', $html, $matches );
157 $this->assertCount( 2, $matches[0] );
158
159 $recentChange3 = $this->getLogChange();
160 $enhancedChangesList->recentChangesLine( $recentChange3, false );
161
162 $html = $enhancedChangesList->endRecentChangesList();
163 $this->assertContains( 'data-mw-logaction="foo/bar"', $html );
164 $this->assertContains( 'data-mw-logid="25"', $html );
165 $this->assertContains( 'data-target-page="Title"', $html );
166 }
167
171 private function newEnhancedChangesList() {
172 $user = User::newFromId( 0 );
173 $context = $this->testRecentChangesHelper->getTestContext( $user );
174
175 return new EnhancedChangesList( $context );
176 }
177
181 private function getEditChange( $timestamp, $pageTitle = 'Cat' ) {
182 $user = $this->getMutableTestUser()->getUser();
183 $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
184 $user, $pageTitle, 0, 5, 191, $timestamp, 0, 0
185 );
186
187 return $recentChange;
188 }
189
190 private function getLogChange() {
191 $user = $this->getMutableTestUser()->getUser();
192 $recentChange = $this->testRecentChangesHelper->makeLogRecentChange( 'foo', 'bar', $user,
193 'Title', '20131103092153', 0, 0
194 );
195
196 return $recentChange;
197 }
198
202 private function getCategorizationChange( $timestamp, $thisId, $lastId ) {
203 $wikiPage = new WikiPage( Title::newFromText( 'Testpage' ) );
204 $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'page created' );
205
206 $wikiPage = new WikiPage( Title::newFromText( 'Category:Foo' ) );
207 $wikiPage->doEditContent( new WikitextContent( 'Some random text' ), 'category page created' );
208
209 $user = $this->getMutableTestUser()->getUser();
210 $recentChange = $this->testRecentChangesHelper->makeCategorizationRecentChange(
211 $user, 'Category:Foo', $wikiPage->getId(), $thisId, $lastId, $timestamp
212 );
213
214 return $recentChange;
215 }
216
217 private function createCategorizationLine( $recentChange ) {
218 $enhancedChangesList = $this->newEnhancedChangesList();
219 $cacheEntry = $this->testRecentChangesHelper->getCacheEntry( $recentChange );
220
221 $reflection = new \ReflectionClass( get_class( $enhancedChangesList ) );
222 $method = $reflection->getMethod( 'recentChangesBlockLine' );
223 $method->setAccessible( true );
224
225 return $method->invokeArgs( $enhancedChangesList, [ $cacheEntry ] );
226 }
227
228}
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:615
Class representing a MediaWiki article and history.
Definition WikiPage.php:44
Content object for wiki text pages.
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:1580
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:2885
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:2062
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
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:247
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))