MediaWiki REL1_28
JavaScriptContentTest.php
Go to the documentation of this file.
1<?php
2
9
10 public function newContent( $text ) {
11 return new JavaScriptContent( $text );
12 }
13
14 public static function dataGetParserOutput() {
15 return [
16 [
17 'MediaWiki:Test.js',
18 null,
19 "hello <world>\n",
20 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello &lt;world&gt;\n\n</pre>"
21 ],
22 [
23 'MediaWiki:Test.js',
24 null,
25 "hello(); // [[world]]\n",
26 "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello(); // [[world]]\n\n</pre>",
27 [
28 'Links' => [
29 [ 'World' => 0 ]
30 ]
31 ]
32 ],
33
34 // TODO: more...?
35 ];
36 }
37
38 // XXX: Unused function
39 public static function dataGetSection() {
40 return [
42 '0',
43 null
44 ],
46 '2',
47 null
48 ],
50 '8',
51 null
52 ],
53 ];
54 }
55
56 // XXX: Unused function
57 public static function dataReplaceSection() {
58 return [
60 '0',
61 'No more',
62 null,
63 null
64 ],
66 '',
67 'No more',
68 null,
69 null
70 ],
72 '2',
73 "== TEST ==\nmore fun",
74 null,
75 null
76 ],
78 '8',
79 'No more',
80 null,
81 null
82 ],
84 'new',
85 'No more',
86 'New',
87 null
88 ],
89 ];
90 }
91
95 public function testAddSectionHeader() {
96 $content = $this->newContent( 'hello world' );
97 $c = $content->addSectionHeader( 'test' );
98
99 $this->assertTrue( $content->equals( $c ) );
100 }
101
102 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional.
103 public static function dataPreSaveTransform() {
104 return [
105 [ 'hello this is ~~~',
106 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
107 ],
108 [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
109 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
110 ],
111 [ " Foo \n ",
112 " Foo",
113 ],
114 ];
115 }
116
117 public static function dataPreloadTransform() {
118 return [
119 [
120 'hello this is ~~~',
121 'hello this is ~~~',
122 ],
123 [
124 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
125 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
126 ],
127 ];
128 }
129
130 public static function dataGetRedirectTarget() {
131 return [
132 [ '#REDIRECT [[Test]]',
133 null,
134 ],
135 [ '#REDIRECT Test',
136 null,
137 ],
138 [ '* #REDIRECT [[Test]]',
139 null,
140 ],
141 ];
142 }
143
144 public static function dataIsCountable() {
145 return [
146 [ '',
147 null,
148 'any',
149 true
150 ],
151 [ 'Foo',
152 null,
153 'any',
154 true
155 ],
156 [ 'Foo',
157 null,
158 'comma',
159 false
160 ],
161 [ 'Foo, bar',
162 null,
163 'comma',
164 false
165 ],
166 [ 'Foo',
167 null,
168 'link',
169 false
170 ],
171 [ 'Foo [[bar]]',
172 null,
173 'link',
174 false
175 ],
176 [ 'Foo',
177 true,
178 'link',
179 false
180 ],
181 [ 'Foo [[bar]]',
182 false,
183 'link',
184 false
185 ],
186 [ '#REDIRECT [[bar]]',
187 true,
188 'any',
189 true
190 ],
191 [ '#REDIRECT [[bar]]',
192 true,
193 'comma',
194 false
195 ],
196 [ '#REDIRECT [[bar]]',
197 true,
198 'link',
199 false
200 ],
201 ];
202 }
203
204 public static function dataGetTextForSummary() {
205 return [
206 [ "hello\nworld.",
207 16,
208 'hello world.',
209 ],
210 [ 'hello world.',
211 8,
212 'hello...',
213 ],
214 [ '[[hello world]].',
215 8,
216 '[[hel...',
217 ],
218 ];
219 }
220
224 public function testMatchMagicWord() {
225 $mw = MagicWord::get( "staticredirect" );
226
227 $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
228 $this->assertFalse(
229 $content->matchMagicWord( $mw ),
230 "should not have matched magic word, since it's not wikitext"
231 );
232 }
233
238 public function testUpdateRedirect( $oldText, $expectedText ) {
239 $this->setMwGlobals( [
240 'wgServer' => '//example.org',
241 'wgScriptPath' => '/w',
242 'wgScript' => '/w/index.php',
243 'wgResourceBasePath' => '/w',
244 ] );
245 $target = Title::newFromText( "testUpdateRedirect_target" );
246
247 $content = new JavaScriptContent( $oldText );
248 $newContent = $content->updateRedirect( $target );
249
250 $this->assertEquals( $expectedText, $newContent->getNativeData() );
251 }
252
253 public static function provideUpdateRedirect() {
254 return [
255 [
256 '#REDIRECT [[Someplace]]',
257 '#REDIRECT [[Someplace]]',
258 ],
259
260 // @codingStandardsIgnoreStart Generic.Files.LineLength
261 [
262 '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=MediaWiki:MonoBook.js\u0026action=raw\u0026ctype=text/javascript");',
263 '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=TestUpdateRedirect_target\u0026action=raw\u0026ctype=text/javascript");'
264 ]
265 // @codingStandardsIgnoreEnd
266 ];
267 }
268
272 public function testGetModel() {
273 $content = $this->newContent( "hello world." );
274
275 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() );
276 }
277
281 public function testGetContentHandler() {
282 $content = $this->newContent( "hello world." );
283
284 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() );
285 }
286
287 public static function dataEquals() {
288 return [
289 [ new JavaScriptContent( "hallo" ), null, false ],
290 [ new JavaScriptContent( "hallo" ), new JavaScriptContent( "hallo" ), true ],
291 [ new JavaScriptContent( "hallo" ), new CssContent( "hallo" ), false ],
292 [ new JavaScriptContent( "hallo" ), new JavaScriptContent( "HALLO" ), false ],
293 ];
294 }
295
299 public function testGetRedirectTarget( $title, $text ) {
300 $this->setMwGlobals( [
301 'wgServer' => '//example.org',
302 'wgScriptPath' => '/w',
303 'wgScript' => '/w/index.php',
304 'wgResourceBasePath' => '/w',
305 ] );
306 $content = new JavaScriptContent( $text );
307 $target = $content->getRedirectTarget();
308 $this->assertEquals( $title, $target ? $target->getPrefixedText() : null );
309 }
310
314 public static function provideGetRedirectTarget() {
315 // @codingStandardsIgnoreStart Generic.Files.LineLength
316 return [
317 [
318 'MediaWiki:MonoBook.js',
319 '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=MediaWiki:MonoBook.js\u0026action=raw\u0026ctype=text/javascript");'
320 ],
321 [
322 'User:FooBar/common.js',
323 '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:FooBar/common.js\u0026action=raw\u0026ctype=text/javascript");'
324 ],
325 [
326 'Gadget:FooBaz.js',
327 '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js\u0026action=raw\u0026ctype=text/javascript");'
328 ],
329 // No #REDIRECT comment
330 [
331 null,
332 'mw.loader.load("//example.org/w/index.php?title=MediaWiki:NoRedirect.js\u0026action=raw\u0026ctype=text/javascript");'
333 ],
334 // Different domain
335 [
336 null,
337 '/* #REDIRECT */mw.loader.load("//example.com/w/index.php?title=MediaWiki:OtherWiki.js\u0026action=raw\u0026ctype=text/javascript");'
338 ],
339 ];
340 // @codingStandardsIgnoreEnd
341 }
342}
Content object for CSS pages.
ContentHandler Database ^— needed, because we do need the database to test link updates.
testMatchMagicWord()
JavaScriptContent::matchMagicWord.
testGetModel()
JavaScriptContent::getModel.
testUpdateRedirect( $oldText, $expectedText)
JavaScriptContent::updateRedirect provideUpdateRedirect.
testGetContentHandler()
JavaScriptContent::getContentHandler.
testGetRedirectTarget( $title, $text)
provideGetRedirectTarget
static provideGetRedirectTarget()
Keep this in sync with JavaScriptContentHandlerTest::provideMakeRedirectContent()
testAddSectionHeader()
JavaScriptContent::addSectionHeader.
Content for JavaScript pages.
static & get( $id)
Factory: creates an object representing an ID.
setMwGlobals( $pairs, $value=null)
ContentHandler Database ^— needed, because we do need the database to test link updates.
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:240
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition hooks.txt:1094
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 true
Definition hooks.txt:1950
processing should stop and the error should be shown to the user * false
Definition hooks.txt:189
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