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