Merge branch 'master' of ssh://gerrit.wikimedia.org:29418/mediawiki/core into Wikidata
[lhc/web/wiklou.git] / tests / phpunit / includes / JavascriptContentTest.php
1 <?php
2
3 /**
4 * @group ContentHandler
5 */
6 class JavascriptContentTest extends WikitextContentTest {
7
8 public function newContent( $text ) {
9 return new JavascriptContent( $text );
10 }
11
12
13 public function dataGetParserOutput() {
14 return array(
15 array("hello <world>\n", "<pre class=\"mw-code mw-js\" dir=\"ltr\">\nhello &lt;world&gt;\n\n</pre>\n"),
16 // @todo: more...?
17 );
18 }
19
20 public function dataGetSection() {
21 return array(
22 array( WikitextContentTest::$sections,
23 "0",
24 null
25 ),
26 array( WikitextContentTest::$sections,
27 "2",
28 null
29 ),
30 array( WikitextContentTest::$sections,
31 "8",
32 null
33 ),
34 );
35 }
36
37 public function dataReplaceSection() {
38 return array(
39 array( WikitextContentTest::$sections,
40 "0",
41 "No more",
42 null,
43 null
44 ),
45 array( WikitextContentTest::$sections,
46 "",
47 "No more",
48 null,
49 null
50 ),
51 array( WikitextContentTest::$sections,
52 "2",
53 "== TEST ==\nmore fun",
54 null,
55 null
56 ),
57 array( WikitextContentTest::$sections,
58 "8",
59 "No more",
60 null,
61 null
62 ),
63 array( WikitextContentTest::$sections,
64 "new",
65 "No more",
66 "New",
67 null
68 ),
69 );
70 }
71
72 public function testAddSectionHeader( ) {
73 $content = $this->newContent( 'hello world' );
74 $c = $content->addSectionHeader( 'test' );
75
76 $this->assertTrue( $content->equals( $c ) );
77 }
78
79 // XXX: currently, preSaveTransform is applied to scripts. this may change or become optional.
80 /*
81 public function dataPreSaveTransform() {
82 return array(
83 array( 'hello this is ~~~',
84 "hello this is ~~~",
85 ),
86 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
87 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
88 ),
89 );
90 }
91 */
92
93 public function dataPreloadTransform() {
94 return array(
95 array( 'hello this is ~~~',
96 "hello this is ~~~",
97 ),
98 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
99 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
100 ),
101 );
102 }
103
104 public function dataGetRedirectTarget() {
105 return array(
106 array( '#REDIRECT [[Test]]',
107 null,
108 ),
109 array( '#REDIRECT Test',
110 null,
111 ),
112 array( '* #REDIRECT [[Test]]',
113 null,
114 ),
115 );
116 }
117
118 /**
119 * @todo: test needs database!
120 */
121 /*
122 public function getRedirectChain() {
123 $text = $this->getNativeData();
124 return Title::newFromRedirectArray( $text );
125 }
126 */
127
128 /**
129 * @todo: test needs database!
130 */
131 /*
132 public function getUltimateRedirectTarget() {
133 $text = $this->getNativeData();
134 return Title::newFromRedirectRecurse( $text );
135 }
136 */
137
138
139 public function dataIsCountable() {
140 return array(
141 array( '',
142 null,
143 'any',
144 true
145 ),
146 array( 'Foo',
147 null,
148 'any',
149 true
150 ),
151 array( 'Foo',
152 null,
153 'comma',
154 false
155 ),
156 array( 'Foo, bar',
157 null,
158 'comma',
159 false
160 ),
161 array( 'Foo',
162 null,
163 'link',
164 false
165 ),
166 array( 'Foo [[bar]]',
167 null,
168 'link',
169 false
170 ),
171 array( 'Foo',
172 true,
173 'link',
174 false
175 ),
176 array( 'Foo [[bar]]',
177 false,
178 'link',
179 false
180 ),
181 array( '#REDIRECT [[bar]]',
182 true,
183 'any',
184 true
185 ),
186 array( '#REDIRECT [[bar]]',
187 true,
188 'comma',
189 false
190 ),
191 array( '#REDIRECT [[bar]]',
192 true,
193 'link',
194 false
195 ),
196 );
197 }
198
199 public function dataGetTextForSummary() {
200 return array(
201 array( "hello\nworld.",
202 16,
203 'hello world.',
204 ),
205 array( 'hello world.',
206 8,
207 'hello...',
208 ),
209 array( '[[hello world]].',
210 8,
211 '[[hel...',
212 ),
213 );
214 }
215
216 # =================================================================================================================
217
218 public function testGetModel() {
219 $content = $this->newContent( "hello world." );
220
221 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() );
222 }
223
224 public function testGetContentHandler() {
225 $content = $this->newContent( "hello world." );
226
227 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() );
228 }
229
230 public function dataEquals( ) {
231 return array(
232 array( new JavascriptContent( "hallo" ), null, false ),
233 array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
234 array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
235 array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),
236 );
237 }
238
239 }