7cd98d881655b7ca6d79703e0c29861470f62fce
2 /** tests for includes/Html.php */
4 class HtmlTest
extends MediaWikiTestCase
{
5 private static $oldLang;
6 private static $oldContLang;
8 public function setUp() {
9 global $wgLang, $wgContLang, $wgLanguageCode;
11 self
::$oldLang = $wgLang;
12 self
::$oldContLang = $wgContLang;
14 $wgLanguageCode = 'en';
15 $wgContLang = $wgLang = Language
::factory( $wgLanguageCode );
18 public function tearDown() {
19 global $wgLang, $wgContLang, $wgLanguageCode;
20 $wgLang = self
::$oldLang;
21 $wgContLang = self
::$oldContLang;
22 $wgLanguageCode = $wgContLang->getCode();
25 public function testExpandAttributesSkipsNullAndFalse() {
29 Html
::expandAttributes( array( 'foo'=>null) ),
30 'skip keys with null value'
33 Html
::expandAttributes( array( 'foo'=>false) ),
34 'skip keys with false value'
36 $this->AssertNotEmpty(
37 Html
::expandAttributes( array( 'foo'=>'') ),
38 'keep keys with an empty string'
42 public function testExpandAttributesForBooleans() {
46 Html
::expandAttributes( array( 'selected'=>false) ),
47 'Boolean attributes do not generates output when value is false'
51 Html
::expandAttributes( array( 'selected'=>null) ),
52 'Boolean attributes do not generates output when value is null'
56 $wgHtml5 ?
' selected=""' : ' selected="selected"',
57 Html
::expandAttributes( array( 'selected'=>true ) ),
58 'Boolean attributes skip value output'
61 $wgHtml5 ?
' selected=""' : ' selected="selected"',
62 Html
::expandAttributes( array( 'selected' ) ),
63 'Boolean attributes (ex: selected) do not need a value'
68 * Test for Html::expandAttributes()
69 * Please note it output a string prefixed with a space!
71 public function testExpandAttributesVariousExpansions() {
75 Html
::expandAttributes( array( 'empty_string'=>'') ),
76 'Value with an empty string'
80 Html
::expandAttributes( array( 'key'=>'value') ),
85 Html
::expandAttributes( array( 'one'=>1) ),
86 'Value is a numeric one'
90 Html
::expandAttributes( array( 'zero'=>0) ),
91 'Value is a numeric zero'