MediaWiki  1.27.3
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( '/tabindex="0"/', $line, 'assert tab index' );
97  $this->assertRegExp(
98  '/title=Cat&amp;curid=20131103212153&amp;action=history"/',
99  $line,
100  'assert history link'
101  );
102  }
103 
104  public function testRecentChangesLine_Flags() {
105  $oldChangesList = $this->getOldChangesList();
106  $recentChange = $this->getNewBotEditChange();
107 
108  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
109 
110  $this->assertContains(
111  '<abbr class="newpage" title="(recentchanges-label-newpage)">(newpageletter)</abbr>',
112  $line,
113  'new page flag'
114  );
115 
116  $this->assertContains(
117  '<abbr class="botedit" title="(recentchanges-label-bot)">(boteditletter)</abbr>',
118  $line,
119  'bot flag'
120  );
121  }
122 
123  public function testRecentChangesLine_Tags() {
124  $recentChange = $this->getEditChange();
125  $recentChange->mAttribs['ts_tags'] = 'vandalism,newbie';
126 
127  $oldChangesList = $this->getOldChangesList();
128  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
129 
130  $this->assertRegExp( '/<li class="[\w\s-]*mw-tag-vandalism[\w\s-]*">/', $line );
131  $this->assertRegExp( '/<li class="[\w\s-]*mw-tag-newbie[\w\s-]*">/', $line );
132  }
133 
135  $oldChangesList = $this->getOldChangesList();
136 
137  $recentChange = $this->getEditChange();
138  $recentChange->numberofWatchingusers = 100;
139 
140  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
141  $this->assertRegExp( "/(number_of_watching_users_RCview: 100)/", $line );
142  }
143 
145  $oldChangesList = $this->getOldChangesList();
146  $oldChangesList->setWatchlistDivs( true );
147 
148  $recentChange = $this->getEditChange();
149  $line = $oldChangesList->recentChangesLine( $recentChange, false, 1 );
150  $this->assertRegExp( "/watchlist-0-Cat/", $line );
151  }
152 
153  private function getNewBotEditChange() {
154  $user = $this->getTestUser();
155 
156  $recentChange = $this->testRecentChangesHelper->makeNewBotEditRecentChange(
157  $user, 'Abc', '20131103212153', 5, 191, 190, 0, 0
158  );
159 
160  return $recentChange;
161  }
162 
163  private function getLogChange( $logType, $logAction ) {
164  $user = $this->getTestUser();
165 
166  $recentChange = $this->testRecentChangesHelper->makeLogRecentChange(
167  $logType, $logAction, $user, 'Abc', '20131103212153', 0, 0
168  );
169 
170  return $recentChange;
171  }
172 
173  private function getEditChange() {
174  $user = $this->getTestUser();
175  $recentChange = $this->testRecentChangesHelper->makeEditRecentChange(
176  $user, 'Cat', '20131103212153', 5, 191, 190, 0, 0
177  );
178 
179  return $recentChange;
180  }
181 
182  private function getOldChangesList() {
183  $context = $this->getContext();
184  return new OldChangesList( $context );
185  }
186 
187  private function getTestUser() {
188  $user = User::newFromName( 'TestRecentChangesUser' );
189 
190  if ( !$user->getId() ) {
191  $user->addToDatabase();
192  }
193 
194  return $user;
195  }
196 
197  private function getContext() {
198  $user = $this->getTestUser();
199  $context = $this->testRecentChangesHelper->getTestContext( $user );
200  $context->setLanguage( 'qqx' );
201 
202  return $context;
203  }
204 
205 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:568
the array() calling protocol came about after MediaWiki 1.4rc1.
$context
Definition: load.php:44
Helper for generating test recent changes entries.
__construct($name=null, array $data=[], $dataName= '')
testRecentChangesLine_CssForLineNumber($expected, $linenumber, $message)
recentChangesLine_CssForLineNumberProvider
Base class that store and restore the Language objects.
getLogChange($logType, $logAction)
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:246
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
$line
Definition: cdb.php:59
TestRecentChangesHelper $testRecentChangesHelper
setMwGlobals($pairs, $value=null)
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:314