MediaWiki  1.30.0
OldChangesListTest.php
Go to the documentation of this file.
1 <?php
2 
15 
20 
21  public function __construct( $name = null, array $data = [], $dataName = '' ) {
22  parent::__construct( $name, $data, $dataName );
23 
24  $this->testRecentChangesHelper = new TestRecentChangesHelper();
25  }
26 
27  protected function setUp() {
28  parent::setUp();
29 
30  $this->setMwGlobals( [
31  'wgArticlePath' => '/wiki/$1',
32  ] );
33  $this->setUserLang( 'qqx' );
34  }
35 
39  public function testRecentChangesLine_CssForLineNumber( $expected, $linenumber, $message ) {
40  $oldChangesList = $this->getOldChangesList();
41  $recentChange = $this->getEditChange();
42 
43  $line = $oldChangesList->recentChangesLine( $recentChange, false, $linenumber );
44 
45  $this->assertRegExp( $expected, $line, $message );
46  }
47 
49  return [
50  [ '/mw-line-odd/', 1, 'odd line number' ],
51  [ '/mw-line-even/', 2, 'even line number' ]
52  ];
53  }
54 
56  $oldChangesList = $this->getOldChangesList();
57  $recentChange = $this->getEditChange();
58 
59  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
60 
61  $this->assertRegExp( '/mw-changeslist-line-not-watched/', $line );
62  }
63 
65  $oldChangesList = $this->getOldChangesList();
66  $recentChange = $this->getEditChange();
67 
68  $line = $oldChangesList->recentChangesLine( $recentChange, true, 1 );
69 
70  $this->assertRegExp( '/mw-changeslist-line-watched/', $line );
71  }
72 
73  public function testRecentChangesLine_LogTitle() {
74  $oldChangesList = $this->getOldChangesList();
75  $recentChange = $this->getLogChange( 'delete', 'delete' );
76 
77  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
78 
79  $this->assertRegExp( '/href="\/wiki\/Special:Log\/delete/', $line, 'link has href attribute' );
80  $this->assertRegExp( '/title="Special:Log\/delete/', $line, 'link has title attribute' );
81  $this->assertRegExp( "/dellogpage/", $line, 'link text' );
82  }
83 
85  $oldChangesList = $this->getOldChangesList();
86  $recentChange = $this->getEditChange();
87 
88  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
89 
90  $this->assertRegExp(
91  '/title=Cat&amp;curid=20131103212153&amp;diff=5&amp;oldid=191/',
92  $line,
93  'assert diff link'
94  );
95 
96  $this->assertRegExp(
97  '/title=Cat&amp;curid=20131103212153&amp;action=history"/',
98  $line,
99  'assert history link'
100  );
101  }
102 
103  public function testRecentChangesLine_Flags() {
104  $oldChangesList = $this->getOldChangesList();
105  $recentChange = $this->getNewBotEditChange();
106 
107  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
108 
109  $this->assertContains(
110  '<abbr class="newpage" title="(recentchanges-label-newpage)">(newpageletter)</abbr>',
111  $line,
112  'new page flag'
113  );
114 
115  $this->assertContains(
116  '<abbr class="botedit" title="(recentchanges-label-bot)">(boteditletter)</abbr>',
117  $line,
118  'bot flag'
119  );
120  }
121 
122  public function testRecentChangesLine_Attribs() {
123  $recentChange = $this->getEditChange();
124  $recentChange->mAttribs['ts_tags'] = 'vandalism,newbie';
125 
126  $oldChangesList = $this->getOldChangesList();
127  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
128 
129  $this->assertRegExp(
130  '/<li data-mw-revid="\d+" data-mw-ts="\d+" class="[\w\s-]*mw-tag-vandalism[\w\s-]*">/',
131  $line
132  );
133  $this->assertRegExp(
134  '/<li data-mw-revid="\d+" data-mw-ts="\d+" class="[\w\s-]*mw-tag-newbie[\w\s-]*">/',
135  $line
136  );
137  }
138 
140  $oldChangesList = $this->getOldChangesList();
141 
142  $recentChange = $this->getEditChange();
143  $recentChange->numberofWatchingusers = 100;
144 
145  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
146  $this->assertRegExp( "/(number_of_watching_users_RCview: 100)/", $line );
147  }
148 
150  $oldChangesList = $this->getOldChangesList();
151  $oldChangesList->setWatchlistDivs( true );
152 
153  $recentChange = $this->getEditChange();
154  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
155  $this->assertRegExp( "/watchlist-0-Cat/", $line );
156  }
157 
159  $oldChangesList = $this->getOldChangesList();
160  $oldChangesList->setWatchlistDivs( true );
161 
162  $recentChange = $this->getEditChange();
163  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
164  $this->assertRegExp( '/data-target-page=\"Cat\"/', $line );
165 
166  $recentChange = $this->getLogChange( 'delete', 'delete' );
167  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
168  $this->assertRegExp( '/data-target-page="Abc"/', $line );
169  }
170 
171  public function testRecentChangesLine_prefix() {
172  $mockContext = $this->getMockBuilder( RequestContext::class )
173  ->setMethods( [ 'getTitle' ] )
174  ->getMock();
175  $mockContext->method( 'getTitle' )
176  ->will( $this->returnValue( Title::newFromText( 'Expected Context Title' ) ) );
177 
178  $oldChangesList = $this->getOldChangesList();
179  $oldChangesList->setContext( $mockContext );
180  $recentChange = $this->getEditChange();
181 
182  $oldChangesList->setChangeLinePrefixer( function ( $rc, $changesList ) {
183  // Make sure RecentChange and ChangesList objects are the same
184  $this->assertEquals( 'Expected Context Title', $changesList->getContext()->getTitle() );
185  $this->assertEquals( 'Cat', $rc->getTitle() );
186  return 'I am a prefix';
187  } );
188  $line = $oldChangesList->recentChangesLine( $recentChange );
189  $this->assertRegExp( "/I am a prefix/", $line );
190  }
191 
192  private function getNewBotEditChange() {
193  $user = $this->getMutableTestUser()->getUser();
194 
195  $recentChange = $this->testRecentChangesHelper->makeNewBotEditRecentChange(
196  $user, 'Abc', '20131103212153', 5, 191, 190, 0, 0
197  );
198 
199  return $recentChange;
200  }
201 
202  private function getLogChange( $logType, $logAction ) {
203  $user = $this->getMutableTestUser()->getUser();
204 
205  $recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
206  $logType, $logAction, $user, 'Abc', '20131103212153', 0, 0
207  );
208 
209  return $recentChange;
210  }
211 
212  private function getEditChange() {
213  $user = $this->getMutableTestUser()->getUser();
214  $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
215  $user, 'Cat', '20131103212153', 5, 191, 190, 0, 0
216  );
217 
218  return $recentChange;
219  }
220 
221  private function getOldChangesList() {
222  $context = $this->getContext();
223  return new OldChangesList( $context );
224  }
225 
226  private function getContext() {
227  $user = $this->getMutableTestUser()->getUser();
228  $context = $this->testRecentChangesHelper->getTestContext( $user );
229  $context->setLanguage( 'qqx' );
230 
231  return $context;
232  }
233 
234 }
OldChangesListTest\testRecentChangesLine_DiffHistLinks
testRecentChangesLine_DiffHistLinks()
Definition: OldChangesListTest.php:84
OldChangesListTest\$testRecentChangesHelper
TestRecentChangesHelper $testRecentChangesHelper
Definition: OldChangesListTest.php:19
$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:244
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:268
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
OldChangesListTest\testRecentChangesLine_prefix
testRecentChangesLine_prefix()
Definition: OldChangesListTest.php:171
$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:2581
OldChangesListTest\recentChangesLine_CssForLineNumberProvider
recentChangesLine_CssForLineNumberProvider()
Definition: OldChangesListTest.php:48
$changesList
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:1472
OldChangesListTest\__construct
__construct( $name=null, array $data=[], $dataName='')
Definition: OldChangesListTest.php:21
TestRecentChangesHelper
Helper for generating test recent changes entries.
Definition: TestRecentChangesHelper.php:10
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
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:35
OldChangesListTest\getEditChange
getEditChange()
Definition: OldChangesListTest.php:212
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:672
OldChangesListTest\testRecentChangesLine_WatchedCssClass
testRecentChangesLine_WatchedCssClass()
Definition: OldChangesListTest.php:64
OldChangesListTest\getOldChangesList
getOldChangesList()
Definition: OldChangesListTest.php:221
OldChangesListTest
OldChangesList.
Definition: OldChangesListTest.php:14
OldChangesListTest\testRecentChangesLine_NotWatchedCssClass
testRecentChangesLine_NotWatchedCssClass()
Definition: OldChangesListTest.php:55
MediaWikiTestCase\setUserLang
setUserLang( $lang)
Definition: MediaWikiTestCase.php:877
$line
$line
Definition: cdb.php:58
OldChangesListTest\getNewBotEditChange
getNewBotEditChange()
Definition: OldChangesListTest.php:192
OldChangesListTest\testRecentChangesLine_Attribs
testRecentChangesLine_Attribs()
Definition: OldChangesListTest.php:122
OldChangesList
Definition: OldChangesList.php:23
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:160
OldChangesListTest\testRecentChangesLine_numberOfWatchingUsers
testRecentChangesLine_numberOfWatchingUsers()
Definition: OldChangesListTest.php:139
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
OldChangesListTest\testRecentChangesLine_dataAttribute
testRecentChangesLine_dataAttribute()
Definition: OldChangesListTest.php:158
OldChangesListTest\setUp
setUp()
Definition: OldChangesListTest.php:27
OldChangesListTest\testRecentChangesLine_watchlistCssClass
testRecentChangesLine_watchlistCssClass()
Definition: OldChangesListTest.php:149
OldChangesListTest\testRecentChangesLine_Flags
testRecentChangesLine_Flags()
Definition: OldChangesListTest.php:103
OldChangesListTest\testRecentChangesLine_LogTitle
testRecentChangesLine_LogTitle()
Definition: OldChangesListTest.php:73
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:52
OldChangesListTest\getContext
getContext()
Definition: OldChangesListTest.php:226
OldChangesListTest\testRecentChangesLine_CssForLineNumber
testRecentChangesLine_CssForLineNumber( $expected, $linenumber, $message)
recentChangesLine_CssForLineNumberProvider
Definition: OldChangesListTest.php:39
OldChangesListTest\getLogChange
getLogChange( $logType, $logAction)
Definition: OldChangesListTest.php:202
array
the array() calling protocol came about after MediaWiki 1.4rc1.