MediaWiki  1.23.3
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 array(
16  array(
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  array(
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  array(
28  'Links' => array(
29  array( 'World' => 0 )
30  )
31  )
32  ),
33 
34  // TODO: more...?
35  );
36  }
37 
38  // XXX: Unused function
39  public static function dataGetSection() {
40  return array(
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 array(
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 array(
105  array( 'hello this is ~~~',
106  "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
107  ),
108  array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
109  'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
110  ),
111  array( " Foo \n ",
112  " Foo",
113  ),
114  );
115  }
116 
117  public static function dataPreloadTransform() {
118  return array(
119  array( 'hello this is ~~~',
120  'hello this is ~~~',
121  ),
122  array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
123  'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
124  ),
125  );
126  }
127 
128  public static function dataGetRedirectTarget() {
129  return array(
130  array( '#REDIRECT [[Test]]',
131  null,
132  ),
133  array( '#REDIRECT Test',
134  null,
135  ),
136  array( '* #REDIRECT [[Test]]',
137  null,
138  ),
139  );
140  }
141 
145  /*
146  public function getRedirectChain() {
147  $text = $this->getNativeData();
148  return Title::newFromRedirectArray( $text );
149  }
150  */
151 
155  /*
156  public function getUltimateRedirectTarget() {
157  $text = $this->getNativeData();
158  return Title::newFromRedirectRecurse( $text );
159  }
160  */
161 
162  public static function dataIsCountable() {
163  return array(
164  array( '',
165  null,
166  'any',
167  true
168  ),
169  array( 'Foo',
170  null,
171  'any',
172  true
173  ),
174  array( 'Foo',
175  null,
176  'comma',
177  false
178  ),
179  array( 'Foo, bar',
180  null,
181  'comma',
182  false
183  ),
184  array( 'Foo',
185  null,
186  'link',
187  false
188  ),
189  array( 'Foo [[bar]]',
190  null,
191  'link',
192  false
193  ),
194  array( 'Foo',
195  true,
196  'link',
197  false
198  ),
199  array( 'Foo [[bar]]',
200  false,
201  'link',
202  false
203  ),
204  array( '#REDIRECT [[bar]]',
205  true,
206  'any',
207  true
208  ),
209  array( '#REDIRECT [[bar]]',
210  true,
211  'comma',
212  false
213  ),
214  array( '#REDIRECT [[bar]]',
215  true,
216  'link',
217  false
218  ),
219  );
220  }
221 
222  public static function dataGetTextForSummary() {
223  return array(
224  array( "hello\nworld.",
225  16,
226  'hello world.',
227  ),
228  array( 'hello world.',
229  8,
230  'hello...',
231  ),
232  array( '[[hello world]].',
233  8,
234  '[[hel...',
235  ),
236  );
237  }
238 
242  public function testMatchMagicWord() {
243  $mw = MagicWord::get( "staticredirect" );
244 
245  $content = $this->newContent( "#REDIRECT [[FOO]]\n__STATICREDIRECT__" );
246  $this->assertFalse( $content->matchMagicWord( $mw ), "should not have matched magic word, since it's not wikitext" );
247  }
248 
252  public function testUpdateRedirect() {
253  $target = Title::newFromText( "testUpdateRedirect_target" );
254 
255  $content = $this->newContent( "#REDIRECT [[Someplace]]" );
256  $newContent = $content->updateRedirect( $target );
257 
258  $this->assertTrue( $content->equals( $newContent ), "content should be unchanged since it's not wikitext" );
259  }
260 
264  public function testGetModel() {
265  $content = $this->newContent( "hello world." );
266 
267  $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() );
268  }
269 
273  public function testGetContentHandler() {
274  $content = $this->newContent( "hello world." );
275 
276  $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() );
277  }
278 
279  public static function dataEquals() {
280  return array(
281  array( new JavaScriptContent( "hallo" ), null, false ),
282  array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "hallo" ), true ),
283  array( new JavaScriptContent( "hallo" ), new CssContent( "hallo" ), false ),
284  array( new JavaScriptContent( "hallo" ), new JavaScriptContent( "HALLO" ), false ),
285  );
286  }
287 }
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:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MagicWord\get
static & get( $id)
Factory: creates an object representing an ID.
Definition: MagicWord.php:238
TextContentTest
@group ContentHandler @group Database ^— needed, because we do need the database to test link updates
Definition: TextContentTest.php:8
CssContent
Content object for CSS pages.
Definition: CssContent.php:33
JavaScriptContentTest\dataIsCountable
static dataIsCountable()
Definition: JavaScriptContentTest.php:162
WikitextContentTest\$sections
static $sections
Definition: WikitextContentTest.php:10
JavaScriptContentTest\dataGetParserOutput
static dataGetParserOutput()
Definition: JavaScriptContentTest.php:14
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
JavaScriptContent
Content for JavaScript pages.
Definition: JavaScriptContent.php:33
JavaScriptContentTest\testUpdateRedirect
testUpdateRedirect()
@covers JavaScriptContent::updateRedirect
Definition: JavaScriptContentTest.php:252
JavaScriptContentTest\testGetModel
testGetModel()
@covers JavaScriptContent::getModel
Definition: JavaScriptContentTest.php:264
JavaScriptContentTest\dataGetRedirectTarget
static dataGetRedirectTarget()
Definition: JavaScriptContentTest.php:128
JavaScriptContentTest\testAddSectionHeader
testAddSectionHeader()
@covers JavaScriptContent::addSectionHeader
Definition: JavaScriptContentTest.php:95
JavaScriptContentTest\dataGetTextForSummary
static dataGetTextForSummary()
Definition: JavaScriptContentTest.php:222
JavaScriptContentTest\testGetContentHandler
testGetContentHandler()
@covers JavaScriptContent::getContentHandler
Definition: JavaScriptContentTest.php:273
JavaScriptContentTest
@group ContentHandler @group Database ^— needed, because we do need the database to test link updates
Definition: JavaScriptContentTest.php:8
JavaScriptContentTest\dataReplaceSection
static dataReplaceSection()
Definition: JavaScriptContentTest.php:57
JavaScriptContentTest\dataPreloadTransform
static dataPreloadTransform()
Definition: JavaScriptContentTest.php:117
JavaScriptContentTest\dataGetSection
static dataGetSection()
Definition: JavaScriptContentTest.php:39
JavaScriptContentTest\newContent
newContent( $text)
Definition: JavaScriptContentTest.php:10
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:284
JavaScriptContentTest\testMatchMagicWord
testMatchMagicWord()
@covers JavaScriptContent::matchMagicWord
Definition: JavaScriptContentTest.php:242
JavaScriptContentTest\dataEquals
static dataEquals()
Definition: JavaScriptContentTest.php:279
JavaScriptContentTest\dataPreSaveTransform
static dataPreSaveTransform()
Definition: JavaScriptContentTest.php:103