From 9a2dc2d05a0b73853cf317f9ecba8731a6572274 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 24 Oct 2011 17:45:45 +0000 Subject: [PATCH] Tests for r96188 features That revision let us pass an array of values to 'class', 'rel' and 'accesskey'. The revision requested some tests :) --- tests/phpunit/includes/HtmlTest.php | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 339e2da3d0..904958860a 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -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', + ))) + ); + } } -- 2.20.1