Index: branches/RL2/extensions/Gadgets/tests/GadgetPrefsTest.php |
— | — | @@ -3,13 +3,13 @@ |
4 | 4 | * @group Gadgets |
5 | 5 | */ |
6 | 6 | class GadgetPrefsTest extends MediaWikiTestCase { |
7 | | - //Test preferences descriptions validator (generic) |
| 7 | + // Test preferences descriptions validator (generic) |
8 | 8 | function testPrefsDescriptions() { |
9 | 9 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( null ) ); |
10 | 10 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array() ) ); |
11 | 11 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array( 'fields' => array() ) ) ); |
12 | 12 | |
13 | | - //Test with stdClass instead if array |
| 13 | + // Test with stdClass instead of array |
14 | 14 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( (object)array( |
15 | 15 | 'fields' => array( |
16 | 16 | array( |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | ) |
23 | 23 | ) ) ); |
24 | 24 | |
25 | | - //Test with wrong type |
| 25 | + // Test with wrong type |
26 | 26 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array( |
27 | 27 | 'fields' => array( |
28 | 28 | array( |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | ) |
35 | 35 | ) ) ); |
36 | 36 | |
37 | | - //Test with missing name |
| 37 | + // Test with missing name |
38 | 38 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array( |
39 | 39 | 'fields' => array( |
40 | 40 | array( |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | ) |
46 | 46 | ) ) ); |
47 | 47 | |
48 | | - //Test with wrong preference name |
| 48 | + // Test with wrong preference name |
49 | 49 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array( |
50 | 50 | 'fields' => array( |
51 | 51 | array( |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | ) |
58 | 58 | ) ) ); |
59 | 59 | |
60 | | - //Test with two fields with the same name |
| 60 | + // Test with two fields with the same name |
61 | 61 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array( |
62 | 62 | 'fields' => array( |
63 | 63 | array( |
— | — | @@ -74,7 +74,7 @@ |
75 | 75 | ) |
76 | 76 | ) ) ); |
77 | 77 | |
78 | | - //Test with fields encoded as associative array instead of regular array |
| 78 | + // Test with fields encoded as associative array instead of regular array |
79 | 79 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array( |
80 | 80 | 'fields' => array( |
81 | 81 | 'testBoolean' => array( |
— | — | @@ -86,7 +86,7 @@ |
87 | 87 | ) |
88 | 88 | ) ) ); |
89 | 89 | |
90 | | - //Test with too long preference name (41 characters) |
| 90 | + // Test with too long preference name (41 characters) |
91 | 91 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array( |
92 | 92 | 'fields' => array( |
93 | 93 | array( |
— | — | @@ -111,7 +111,7 @@ |
112 | 112 | ) ) ); |
113 | 113 | |
114 | 114 | |
115 | | - //Test with an unexisting field parameter |
| 115 | + // Test with an unexisting field parameter |
116 | 116 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( array( |
117 | 117 | 'fields' => array( |
118 | 118 | array( |
— | — | @@ -125,7 +125,7 @@ |
126 | 126 | ) ) ); |
127 | 127 | } |
128 | 128 | |
129 | | - //Tests for 'label' type preferences |
| 129 | + // Tests for 'label' type preferences |
130 | 130 | function testPrefsDescriptionsLabel() { |
131 | 131 | $correct = array( |
132 | 132 | 'fields' => array( |
— | — | @@ -136,13 +136,13 @@ |
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | |
140 | | - //Tests with correct values for 'label' |
| 140 | + // Tests with correct values for 'label' |
141 | 141 | foreach ( array( '', '@', '@message', 'foo', '@@not message' ) as $def ) { |
142 | 142 | $correct['fields'][0]['label'] = $def; |
143 | 143 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct ) ); |
144 | 144 | } |
145 | 145 | |
146 | | - //Tests with wrong values for 'label' |
| 146 | + // Tests with wrong values for 'label' |
147 | 147 | $wrong = $correct; |
148 | 148 | foreach ( array( 0, 1, true, false, null, array() ) as $label ) { |
149 | 149 | $wrong['fields'][0]['label'] = $label; |
— | — | @@ -151,7 +151,7 @@ |
152 | 152 | |
153 | 153 | } |
154 | 154 | |
155 | | - //Tests for 'boolean' type preferences |
| 155 | + // Tests for 'boolean' type preferences |
156 | 156 | function testPrefsDescriptionsBoolean() { |
157 | 157 | $correct = array( |
158 | 158 | 'fields' => array( |
— | — | @@ -179,7 +179,7 @@ |
180 | 180 | |
181 | 181 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct2 ) ); |
182 | 182 | |
183 | | - //Tests with wrong default values |
| 183 | + // Tests with wrong default values |
184 | 184 | $wrong = $correct; |
185 | 185 | foreach ( array( 0, 1, '', 'false', 'true', null, array() ) as $def ) { |
186 | 186 | $wrong['fields'][0]['default'] = $def; |
— | — | @@ -187,7 +187,7 @@ |
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | | - //Tests for 'string' type preferences |
| 191 | + // Tests for 'string' type preferences |
192 | 192 | function testPrefsDescriptionsString() { |
193 | 193 | $correct = array( |
194 | 194 | 'fields' => array( |
— | — | @@ -204,21 +204,21 @@ |
205 | 205 | |
206 | 206 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct ) ); |
207 | 207 | |
208 | | - //Tests with wrong default values (when 'required' is not given) |
| 208 | + // Tests with wrong default values (when 'required' is not given) |
209 | 209 | $wrong = $correct; |
210 | 210 | foreach ( array( null, '', true, false, 0, 1, array(), 'short', 'veryverylongstring' ) as $def ) { |
211 | 211 | $wrong['fields'][0]['default'] = $def; |
212 | 212 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( $wrong ) ); |
213 | 213 | } |
214 | 214 | |
215 | | - //Tests with correct default values (when required is not given) |
| 215 | + // Tests with correct default values (when required is not given) |
216 | 216 | $correct2 = $correct; |
217 | 217 | foreach ( array( '6chars', '1234567890' ) as $def ) { |
218 | 218 | $correct2['fields'][0]['default'] = $def; |
219 | 219 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct2 ) ); |
220 | 220 | } |
221 | 221 | |
222 | | - //Tests with wrong default values (when 'required' is false) |
| 222 | + // Tests with wrong default values (when 'required' is false) |
223 | 223 | $wrong = $correct; |
224 | 224 | $wrong['fields'][0]['required'] = false; |
225 | 225 | foreach ( array( null, true, false, 0, 1, array(), 'short', 'veryverylongstring' ) as $def ) { |
— | — | @@ -226,7 +226,7 @@ |
227 | 227 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( $wrong ) ); |
228 | 228 | } |
229 | 229 | |
230 | | - //Tests with correct default values (when required is false) |
| 230 | + // Tests with correct default values (when required is false) |
231 | 231 | $correct2 = $correct; |
232 | 232 | $correct2['fields'][0]['required'] = false; |
233 | 233 | foreach ( array( '', '6chars', '1234567890' ) as $def ) { |
— | — | @@ -245,22 +245,22 @@ |
246 | 246 | ) |
247 | 247 | ); |
248 | 248 | |
249 | | - //Test with empty default when "required" is true |
| 249 | + // Test with empty default when "required" is true |
250 | 250 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct ) ); |
251 | 251 | |
252 | | - //Test with empty default when "required" is true |
| 252 | + // Test with empty default when "required" is true |
253 | 253 | $wrong = $correct; |
254 | 254 | $wrong['fields'][0]['required'] = true; |
255 | 255 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( $wrong ) ); |
256 | 256 | |
257 | | - //Test with empty default when "required" is false and minlength is given |
| 257 | + // Test with empty default when "required" is false and minlength is given |
258 | 258 | $correct2 = $correct; |
259 | 259 | $correct2['fields'][0]['required'] = false; |
260 | 260 | $correct2['fields'][0]['minlength'] = 3; |
261 | 261 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct2 ) ); |
262 | 262 | } |
263 | 263 | |
264 | | - //Tests for 'number' type preferences |
| 264 | + // Tests for 'number' type preferences |
265 | 265 | function testPrefsDescriptionsNumber() { |
266 | 266 | $correctFloat = array( |
267 | 267 | 'fields' => array( |
— | — | @@ -294,7 +294,7 @@ |
295 | 295 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correctFloat ) ); |
296 | 296 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correctInt ) ); |
297 | 297 | |
298 | | - //Tests with wrong default values (with 'required' = true) |
| 298 | + // Tests with wrong default values (with 'required' = true) |
299 | 299 | $wrongFloat = $correctFloat; |
300 | 300 | foreach ( array( '', false, true, null, array(), -100, +100 ) as $def ) { |
301 | 301 | $wrongFloat['fields'][0]['default'] = $def; |
— | — | @@ -315,7 +315,7 @@ |
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
319 | | - //Tests for 'select' type preferences |
| 319 | + // Tests for 'select' type preferences |
320 | 320 | function testPrefsDescriptionsSelect() { |
321 | 321 | $correct = array( |
322 | 322 | 'fields' => array( |
— | — | @@ -335,14 +335,14 @@ |
336 | 336 | ); |
337 | 337 | |
338 | 338 | |
339 | | - //Tests with correct default values |
| 339 | + // Tests with correct default values |
340 | 340 | $correct2 = $correct; |
341 | 341 | foreach ( array( null, true, 3, 'test' ) as $def ) { |
342 | 342 | $correct2['fields'][0]['default'] = $def; |
343 | 343 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct2 ) ); |
344 | 344 | } |
345 | 345 | |
346 | | - //Tests with wrong default values |
| 346 | + // Tests with wrong default values |
347 | 347 | $wrong = $correct; |
348 | 348 | foreach ( array( '', 'true', 'null', false, array(), 0, 1, 3.0001 ) as $def ) { |
349 | 349 | $wrong['fields'][0]['default'] = $def; |
— | — | @@ -350,7 +350,7 @@ |
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | | - //Tests for 'range' type preferences |
| 354 | + // Tests for 'range' type preferences |
355 | 355 | function testPrefsDescriptionsRange() { |
356 | 356 | $correct = array( |
357 | 357 | 'fields' => array( |
— | — | @@ -365,27 +365,27 @@ |
366 | 366 | ) |
367 | 367 | ); |
368 | 368 | |
369 | | - //Tests with correct default values |
| 369 | + // Tests with correct default values |
370 | 370 | $correct2 = $correct; |
371 | 371 | foreach ( array( 15, 33, 45 ) as $def ) { |
372 | 372 | $correct2['fields'][0]['default'] = $def; |
373 | 373 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct2 ) ); |
374 | 374 | } |
375 | 375 | |
376 | | - //Tests with wrong default values |
| 376 | + // Tests with wrong default values |
377 | 377 | $wrong = $correct; |
378 | 378 | foreach ( array( '', true, false, null, array(), '35', 14, 46, 30.2 ) as $def ) { |
379 | 379 | $wrong['fields'][0]['default'] = $def; |
380 | 380 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( $wrong ) ); |
381 | 381 | } |
382 | 382 | |
383 | | - //Test with max not in the set min + k*step (step not given, so it's 1) |
| 383 | + // Test with max not in the set min + k*step (step not given, so it's 1) |
384 | 384 | $wrong = $correct; |
385 | 385 | $wrong['fields'][0]['max'] = 45.5; |
386 | 386 | $this->assertFalse( GadgetPrefs::isPrefsDescriptionValid( $wrong ) ); |
387 | 387 | |
388 | 388 | |
389 | | - //Tests with floating point min, max and step |
| 389 | + // Tests with floating point min, max and step |
390 | 390 | $correct = array( |
391 | 391 | 'fields' => array( |
392 | 392 | array( |
— | — | @@ -402,14 +402,14 @@ |
403 | 403 | |
404 | 404 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct ) ); |
405 | 405 | |
406 | | - //Tests with correct default values |
| 406 | + // Tests with correct default values |
407 | 407 | $correct2 = $correct; |
408 | 408 | foreach ( array( -2.8, -2.55, 0.20, 4.2 ) as $def ) { |
409 | 409 | $correct2['fields'][0]['default'] = $def; |
410 | 410 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct2 ) ); |
411 | 411 | } |
412 | 412 | |
413 | | - //Tests with wrong default values |
| 413 | + // Tests with wrong default values |
414 | 414 | $wrong = $correct; |
415 | 415 | foreach ( array( '', true, false, null, array(), '0.20', -2.7, 0, 4.199999 ) as $def ) { |
416 | 416 | $wrong['fields'][0]['default'] = $def; |
— | — | @@ -417,7 +417,7 @@ |
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
421 | | - //Tests for 'date' type preferences |
| 421 | + // Tests for 'date' type preferences |
422 | 422 | function testPrefsDescriptionsDate() { |
423 | 423 | $correct = array( |
424 | 424 | 'fields' => array( |
— | — | @@ -430,7 +430,7 @@ |
431 | 431 | ) |
432 | 432 | ); |
433 | 433 | |
434 | | - //Tests with correct default values |
| 434 | + // Tests with correct default values |
435 | 435 | $correct2 = $correct; |
436 | 436 | foreach ( array( |
437 | 437 | null, |
— | — | @@ -443,7 +443,7 @@ |
444 | 444 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct2 ) ); |
445 | 445 | } |
446 | 446 | |
447 | | - //Tests with wrong default values |
| 447 | + // Tests with wrong default values |
448 | 448 | $wrong = $correct; |
449 | 449 | foreach ( array( |
450 | 450 | '', true, false, array(), 0, |
— | — | @@ -467,7 +467,7 @@ |
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
471 | | - //Tests for 'color' type preferences |
| 471 | + // Tests for 'color' type preferences |
472 | 472 | function testPrefsDescriptionsColor() { |
473 | 473 | $correct = array( |
474 | 474 | 'fields' => array( |
— | — | @@ -480,7 +480,7 @@ |
481 | 481 | ) |
482 | 482 | ); |
483 | 483 | |
484 | | - //Tests with correct default values |
| 484 | + // Tests with correct default values |
485 | 485 | $correct2 = $correct; |
486 | 486 | foreach ( array( |
487 | 487 | '#000000', |
— | — | @@ -492,7 +492,7 @@ |
493 | 493 | $this->assertTrue( GadgetPrefs::isPrefsDescriptionValid( $correct2 ) ); |
494 | 494 | } |
495 | 495 | |
496 | | - //Tests with wrong default values |
| 496 | + // Tests with wrong default values |
497 | 497 | $wrong = $correct; |
498 | 498 | foreach ( array( |
499 | 499 | '', true, false, null, 0, array(), |
— | — | @@ -510,7 +510,7 @@ |
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | | - //Tests for 'composite' type fields |
| 514 | + // Tests for 'composite' type fields |
515 | 515 | function testPrefsDescriptionsComposite() { |
516 | 516 | $correct = array( |
517 | 517 | 'fields' => array( |
— | — | @@ -574,7 +574,7 @@ |
575 | 575 | $this->assertEquals( $prefs, array( 'foo' => array( 'bar' => false, 'car' => '#123456' ) ) ); |
576 | 576 | } |
577 | 577 | |
578 | | - //Tests for 'list' type fields |
| 578 | + // Tests for 'list' type fields |
579 | 579 | function testPrefsDescriptionsList() { |
580 | 580 | $correct = array( |
581 | 581 | 'fields' => array( |
— | — | @@ -618,7 +618,7 @@ |
619 | 619 | |
620 | 620 | $this->assertEquals( GadgetPrefs::getMessages( $correct ), array( 'msg1', 'msg2' ) ); |
621 | 621 | |
622 | | - //Tests with correct pref values |
| 622 | + // Tests with correct pref values |
623 | 623 | $this->assertTrue( GadgetPrefs::checkPrefsAgainstDescription( |
624 | 624 | $correct, |
625 | 625 | array( 'foo' => array() ) |
— | — | @@ -643,7 +643,7 @@ |
644 | 644 | ) |
645 | 645 | ) ); |
646 | 646 | |
647 | | - //Tests with wrong pref values |
| 647 | + // Tests with wrong pref values |
648 | 648 | $this->assertFalse( GadgetPrefs::checkPrefsAgainstDescription( |
649 | 649 | $correct, |
650 | 650 | array( 'foo' => array( |
— | — | @@ -665,7 +665,7 @@ |
666 | 666 | ) ); |
667 | 667 | |
668 | 668 | |
669 | | - //Tests with 'minlength' and 'maxlength' options |
| 669 | + // Tests with 'minlength' and 'maxlength' options |
670 | 670 | $wrong = $correct; |
671 | 671 | $wrong['fields'][0]['minlength'] = 4; |
672 | 672 | $wrong['fields'][0]['maxlength'] = 3; //maxlength < minlength, wrong |
— | — | @@ -704,14 +704,14 @@ |
705 | 705 | ) |
706 | 706 | ) ); |
707 | 707 | |
708 | | - //Test with 'required' |
| 708 | + // Test with 'required' |
709 | 709 | $correct2['fields'][0]['required'] = false; |
710 | 710 | $this->assertTrue( GadgetPrefs::checkPrefsAgainstDescription( |
711 | 711 | $correct2, |
712 | 712 | array( 'foo' => array() ) //empty array, must be accepted because "required" is false |
713 | 713 | ) ); |
714 | 714 | |
715 | | - //Tests matchPrefsWithDescription |
| 715 | + // Tests matchPrefsWithDescription |
716 | 716 | $prefs = array( 'foo' => array( |
717 | 717 | array( |
718 | 718 | 'bar' => null, |