7a12ada5cd797a2f2eecf5a476bf9936fd36d5fb
[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 public function dataPreSaveTransform() {
80 return array(
81 array( 'hello this is ~~~',
82 "hello this is ~~~",
83 ),
84 array( 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
85 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
86 ),
87 );
88 }
89
90 public function dataPreloadTransform() {
91 return array(
92 array( 'hello this is ~~~',
93 "hello this is ~~~",
94 ),
95 array( 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
96 'hello \'\'this\'\' is <noinclude>foo</noinclude><includeonly>bar</includeonly>',
97 ),
98 );
99 }
100
101 public function dataGetRedirectTarget() {
102 return array(
103 array( '#REDIRECT [[Test]]',
104 null,
105 ),
106 array( '#REDIRECT Test',
107 null,
108 ),
109 array( '* #REDIRECT [[Test]]',
110 null,
111 ),
112 );
113 }
114
115 /**
116 * @todo: test needs database!
117 */
118 /*
119 public function getRedirectChain() {
120 $text = $this->getNativeData();
121 return Title::newFromRedirectArray( $text );
122 }
123 */
124
125 /**
126 * @todo: test needs database!
127 */
128 /*
129 public function getUltimateRedirectTarget() {
130 $text = $this->getNativeData();
131 return Title::newFromRedirectRecurse( $text );
132 }
133 */
134
135
136 public function dataIsCountable() {
137 return array(
138 array( '',
139 null,
140 'any',
141 true
142 ),
143 array( 'Foo',
144 null,
145 'any',
146 true
147 ),
148 array( 'Foo',
149 null,
150 'comma',
151 false
152 ),
153 array( 'Foo, bar',
154 null,
155 'comma',
156 false
157 ),
158 array( 'Foo',
159 null,
160 'link',
161 false
162 ),
163 array( 'Foo [[bar]]',
164 null,
165 'link',
166 false
167 ),
168 array( 'Foo',
169 true,
170 'link',
171 false
172 ),
173 array( 'Foo [[bar]]',
174 false,
175 'link',
176 false
177 ),
178 array( '#REDIRECT [[bar]]',
179 true,
180 'any',
181 true
182 ),
183 array( '#REDIRECT [[bar]]',
184 true,
185 'comma',
186 false
187 ),
188 array( '#REDIRECT [[bar]]',
189 true,
190 'link',
191 false
192 ),
193 );
194 }
195
196 public function dataGetTextForSummary() {
197 return array(
198 array( "hello\nworld.",
199 16,
200 'hello world.',
201 ),
202 array( 'hello world.',
203 8,
204 'hello...',
205 ),
206 array( '[[hello world]].',
207 8,
208 '[[hel...',
209 ),
210 );
211 }
212
213 # =================================================================================================================
214
215 public function testGetModel() {
216 $content = $this->newContent( "hello world." );
217
218 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getModel() );
219 }
220
221 public function testGetContentHandler() {
222 $content = $this->newContent( "hello world." );
223
224 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $content->getContentHandler()->getModelID() );
225 }
226
227 public function dataEquals( ) {
228 return array(
229 array( new JavascriptContent( "hallo" ), null, false ),
230 array( new JavascriptContent( "hallo" ), new JavascriptContent( "hallo" ), true ),
231 array( new JavascriptContent( "hallo" ), new CssContent( "hallo" ), false ),
232 array( new JavascriptContent( "hallo" ), new JavascriptContent( "HALLO" ), false ),
233 );
234 }
235
236 }