Tests for r96188 features
authorAntoine Musso <hashar@users.mediawiki.org>
Mon, 24 Oct 2011 17:45:45 +0000 (17:45 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Mon, 24 Oct 2011 17:45:45 +0000 (17:45 +0000)
That revision let us pass an array of values to 'class', 'rel'
and 'accesskey'. The revision requested some tests :)

tests/phpunit/includes/HtmlTest.php

index 339e2da..9049588 100644 (file)
@@ -143,4 +143,43 @@ class HtmlTest extends MediaWikiTestCase {
                        'Normalization should remove duplicates in string-lists in the array'
                );
        }
+
+       /**
+        * Test feature added by r96188, let pass attributes values as
+        * a PHP array. Restricted to class,rel, accesskey.
+        */
+       function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
+               $this->assertEquals(
+                       ' class="booltrue one"',
+                       Html::expandAttributes( array( 'class' => array(
+                               'booltrue' => true,
+                               'one' => 1,
+
+                               # Method use isset() internally, make sure we do discard
+                           # attributes values which have been assigned well known values
+                               'emptystring' => '',
+                               'boolfalse' => false,
+                               'zero' => 0,
+                               'null' => null,
+                       )))
+               );
+       }
+
+       /**
+        * How do we handle duplicate keys in HTML attributes expansion?
+        * We could pass a "class" the values: 'GREEN' and array( 'GREEN' => false )
+        * The later will take precedence.
+        *
+        * Feature added by r96188
+        */
+       function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
+               $this->assertEquals(
+                       ' class=""',
+                       HTML::expandAttributes( array( 'class' => array(
+                               'GREEN',
+                               'GREEN' => false,
+                               'GREEN',
+                       )))
+               );
+       }
 }