Index: trunk/phase3/tests/phpunit/includes/HtmlTest.php |
— | — | @@ -0,0 +1,90 @@ |
| 2 | +<?php |
| 3 | +/** tests for includes/Html.php */ |
| 4 | + |
| 5 | +class HtmlTest extends MediaWikiTestCase { |
| 6 | + private static $oldLang; |
| 7 | + |
| 8 | + public function setUp() { |
| 9 | + global $wgLang, $wgLanguageCode; |
| 10 | + |
| 11 | + self::$oldLang = $wgLang; |
| 12 | + $wgLanguageCode = 'en'; |
| 13 | + $wgLang = Language::factory( $wgLanguageCode ); |
| 14 | + } |
| 15 | + |
| 16 | + public function tearDown() { |
| 17 | + global $wgLang, $wgLanguageCode; |
| 18 | + $wgLang = self::$oldLang; |
| 19 | + $wgLanguageCode = $wgLang->getCode(); |
| 20 | + } |
| 21 | + |
| 22 | + public function testExpandAttributesSkipsNullAndFalse() { |
| 23 | + |
| 24 | + ### EMPTY ######## |
| 25 | + $this->AssertEmpty( |
| 26 | + Html::expandAttributes( array( 'foo'=>null) ), |
| 27 | + 'skip keys with null value' |
| 28 | + ); |
| 29 | + $this->AssertEmpty( |
| 30 | + Html::expandAttributes( array( 'foo'=>false) ), |
| 31 | + 'skip keys with false value' |
| 32 | + ); |
| 33 | + $this->AssertNotEmpty( |
| 34 | + Html::expandAttributes( array( 'foo'=>'') ), |
| 35 | + 'keep keys with an empty string' |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + public function testExpandAttributesForBooleans() { |
| 40 | + $this->AssertEquals( |
| 41 | + '', |
| 42 | + Html::expandAttributes( array( 'selected'=>false) ), |
| 43 | + 'Boolean attributes do not generates output when value is false' |
| 44 | + ); |
| 45 | + $this->AssertEquals( |
| 46 | + '', |
| 47 | + Html::expandAttributes( array( 'selected'=>null) ), |
| 48 | + 'Boolean attributes do not generates output when value is null' |
| 49 | + ); |
| 50 | + |
| 51 | + ### FIXME: maybe they should just output 'selected' |
| 52 | + $this->AssertEquals( |
| 53 | + ' selected=""', |
| 54 | + Html::expandAttributes( array( 'selected'=>true ) ), |
| 55 | + 'Boolean attributes skip value output' |
| 56 | + ); |
| 57 | + $this->AssertEquals( |
| 58 | + ' selected=""', |
| 59 | + Html::expandAttributes( array( 'selected' ) ), |
| 60 | + 'Boolean attributes (ex: selected) do not need a value' |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Test for Html::expandAttributes() |
| 66 | + * Please note it output a string prefixed with a space! |
| 67 | + */ |
| 68 | + public function testExpandAttributesVariousExpansions() { |
| 69 | + ### NOT EMPTY #### |
| 70 | + $this->AssertEquals( |
| 71 | + ' empty_string=""', |
| 72 | + Html::expandAttributes( array( 'empty_string'=>'') ), |
| 73 | + 'Value with an empty string' |
| 74 | + ); |
| 75 | + $this->AssertEquals( |
| 76 | + ' key="value"', |
| 77 | + Html::expandAttributes( array( 'key'=>'value') ), |
| 78 | + 'Value is a string' |
| 79 | + ); |
| 80 | + $this->AssertEquals( |
| 81 | + ' one="1"', |
| 82 | + Html::expandAttributes( array( 'one'=>1) ), |
| 83 | + 'Value is a numeric one' |
| 84 | + ); |
| 85 | + $this->AssertEquals( |
| 86 | + ' zero="0"', |
| 87 | + Html::expandAttributes( array( 'zero'=>0) ), |
| 88 | + 'Value is a numeric zero' |
| 89 | + ); |
| 90 | + } |
| 91 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/HtmlTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 92 | + native |