Merge "Set relevant title on Special:RecentChangesLinked"
[lhc/web/wiklou.git] / tests / phpunit / includes / HtmlTest.php
index e934965..d4d9551 100644 (file)
@@ -112,7 +112,8 @@ class HtmlTest extends MediaWikiTestCase {
                        Html::expandAttributes( array( 'foo' => false ) ),
                        'skip keys with false value'
                );
-               $this->assertNotEmpty(
+               $this->assertEquals(
+                       ' foo=""',
                        Html::expandAttributes( array( 'foo' => '' ) ),
                        'keep keys with an empty string'
                );
@@ -153,6 +154,33 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers HTML::expandAttributes
+        */
+       public function testExpandAttributesForNumbers() {
+               $this->assertEquals(
+                       ' value=1',
+                       Html::expandAttributes( array( 'value' => 1 ) ),
+                       'Integer value is cast to a string'
+               );
+               $this->assertEquals(
+                       ' value=1.1',
+                       Html::expandAttributes( array( 'value' => 1.1 ) ),
+                       'Float value is cast to a string'
+               );
+       }
+
+       /**
+        * @covers HTML::expandAttributes
+        */
+       public function testExpandAttributesForObjects() {
+               $this->assertEquals(
+                       ' value=stringValue',
+                       Html::expandAttributes( array( 'value' => new HtmlTestValue() ) ),
+                       'Object value is converted to a string'
+               );
+       }
+
        /**
         * Test for Html::expandAttributes()
         * Please note it output a string prefixed with a space!
@@ -299,6 +327,21 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Html::expandAttributes
+        * @expectedException MWException
+        */
+       public function testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException() {
+               // Real-life test case found in the Popups extension (see Gerrit cf0fd64),
+               // when used with an outdated BetaFeatures extension (see Gerrit deda1e7)
+               Html::expandAttributes( array(
+                       'src' => array(
+                               'ltr' => 'ltr.svg',
+                               'rtl' => 'rtl.svg'
+                       )
+               ) );
+       }
+
        /**
         * @covers Html::namespaceSelector
         */
@@ -664,4 +707,67 @@ class HtmlTest extends MediaWikiTestCase {
                        )
                );
        }
+
+       public function testWrapperInput() {
+               $this->assertEquals(
+                       '<input type=radio value=testval name=testname>',
+                       Html::input( 'testname', 'testval', 'radio' ),
+                       'Input wrapper with type and value.'
+               );
+               $this->assertEquals(
+                       '<input name=testname>',
+                       Html::input( 'testname' ),
+                       'Input wrapper with all default values.'
+               );
+       }
+
+       public function testWrapperCheck() {
+               $this->assertEquals(
+                       '<input type=checkbox value=1 name=testname>',
+                       Html::check( 'testname' ),
+                       'Checkbox wrapper unchecked.'
+               );
+               $this->assertEquals(
+                       '<input checked type=checkbox value=1 name=testname>',
+                       Html::check( 'testname', true ),
+                       'Checkbox wrapper checked.'
+               );
+               $this->assertEquals(
+                       '<input type=checkbox value=testval name=testname>',
+                       Html::check( 'testname', false, array( 'value' => 'testval' ) ),
+                       'Checkbox wrapper with a value override.'
+               );
+       }
+
+       public function testWrapperRadio() {
+               $this->assertEquals(
+                       '<input type=radio value=1 name=testname>',
+                       Html::radio( 'testname' ),
+                       'Radio wrapper unchecked.'
+               );
+               $this->assertEquals(
+                       '<input checked type=radio value=1 name=testname>',
+                       Html::radio( 'testname', true ),
+                       'Radio wrapper checked.'
+               );
+               $this->assertEquals(
+                       '<input type=radio value=testval name=testname>',
+                       Html::radio( 'testname', false, array( 'value' => 'testval' ) ),
+                       'Radio wrapper with a value override.'
+               );
+       }
+
+       public function testWrapperLabel() {
+               $this->assertEquals(
+                       '<label for=testid>testlabel</label>',
+                       Html::label( 'testlabel', 'testid' ),
+                       'Label wrapper'
+               );
+       }
+}
+
+class HtmlTestValue {
+       function __toString() {
+               return 'stringValue';
+       }
 }