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