X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FHtmlTest.php;h=47217939bf39d87e1adbe8afe5ccdc9a1f71ebab;hb=5f1a4a3dfc049a742184d5690d211fb0321c9b9d;hp=6c92b8cb817bf92341c84243315f9a278cd8eae4;hpb=816e6ded007382f35df38ea8f4b5a32e8e256b78;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 6c92b8cb81..47217939bf 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -7,7 +7,6 @@ class HtmlTest extends MediaWikiTestCase { parent::setUp(); $this->setMwGlobals( [ - 'wgWellFormedXml' => false, 'wgUseMediaWikiUIEverywhere' => false, ] ); @@ -45,9 +44,9 @@ class HtmlTest extends MediaWikiTestCase { */ public function testElementBasics() { $this->assertEquals( - '', + '', Html::element( 'img', null, '' ), - 'No close tag for short-tag elements' + 'Self-closing tag for short-tag elements' ); $this->assertEquals( @@ -61,14 +60,6 @@ class HtmlTest extends MediaWikiTestCase { Html::element( 'element', [], '' ), 'Close tag for empty element (array, string)' ); - - $this->setMwGlobals( 'wgWellFormedXml', true ); - - $this->assertEquals( - '', - Html::element( 'img', null, '' ), - 'Self-closing tag for short-tag elements (wgWellFormedXml = true)' - ); } public function dataXmlMimeType() { @@ -134,23 +125,15 @@ class HtmlTest extends MediaWikiTestCase { ); $this->assertEquals( - ' selected', + ' selected=""', Html::expandAttributes( [ 'selected' => true ] ), 'Boolean attributes have no value when value is true' ); $this->assertEquals( - ' selected', + ' selected=""', Html::expandAttributes( [ 'selected' ] ), 'Boolean attributes have no value when value is true (passed as numerical array)' ); - - $this->setMwGlobals( 'wgWellFormedXml', true ); - - $this->assertEquals( - ' selected=""', - Html::expandAttributes( [ 'selected' => true ] ), - 'Boolean attributes have empty string value when value is true (wgWellFormedXml)' - ); } /** @@ -158,12 +141,12 @@ class HtmlTest extends MediaWikiTestCase { */ public function testExpandAttributesForNumbers() { $this->assertEquals( - ' value=1', + ' value="1"', Html::expandAttributes( [ 'value' => 1 ] ), 'Integer value is cast to a string' ); $this->assertEquals( - ' value=1.1', + ' value="1.1"', Html::expandAttributes( [ 'value' => 1.1 ] ), 'Float value is cast to a string' ); @@ -174,7 +157,7 @@ class HtmlTest extends MediaWikiTestCase { */ public function testExpandAttributesForObjects() { $this->assertEquals( - ' value=stringValue', + ' value="stringValue"', Html::expandAttributes( [ 'value' => new HtmlTestValue() ] ), 'Object value is converted to a string' ); @@ -193,43 +176,21 @@ class HtmlTest extends MediaWikiTestCase { 'Empty string is always quoted' ); $this->assertEquals( - ' key=value', + ' key="value"', Html::expandAttributes( [ 'key' => 'value' ] ), 'Simple string value needs no quotes' ); $this->assertEquals( - ' one=1', + ' one="1"', Html::expandAttributes( [ 'one' => 1 ] ), 'Number 1 value needs no quotes' ); $this->assertEquals( - ' zero=0', + ' zero="0"', Html::expandAttributes( [ 'zero' => 0 ] ), 'Number 0 value needs no quotes' ); - $this->setMwGlobals( 'wgWellFormedXml', true ); - - $this->assertEquals( - ' empty_string=""', - Html::expandAttributes( [ 'empty_string' => '' ] ), - 'Attribute values are always quoted (wgWellFormedXml): Empty string' - ); - $this->assertEquals( - ' key="value"', - Html::expandAttributes( [ 'key' => 'value' ] ), - 'Attribute values are always quoted (wgWellFormedXml): Simple string' - ); - $this->assertEquals( - ' one="1"', - Html::expandAttributes( [ 'one' => 1 ] ), - 'Attribute values are always quoted (wgWellFormedXml): Number 1' - ); - $this->assertEquals( - ' zero="0"', - Html::expandAttributes( [ 'zero' => 0 ] ), - 'Attribute values are always quoted (wgWellFormedXml): Number 0' - ); } /** @@ -346,48 +307,48 @@ class HtmlTest extends MediaWikiTestCase { */ public function testNamespaceSelector() { $this->assertEquals( - '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . '', Html::namespaceSelector(), 'Basic namespace selector without custom options' ); $this->assertEquals( - ' ' . - '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . '', Html::namespaceSelector( [ 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ], @@ -397,24 +358,24 @@ class HtmlTest extends MediaWikiTestCase { ); $this->assertEquals( - ' ' . - '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . '', Html::namespaceSelector( [ 'label' => 'Select a namespace:' ] @@ -425,18 +386,18 @@ class HtmlTest extends MediaWikiTestCase { public function testCanFilterOutNamespaces() { $this->assertEquals( - '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . '', Html::namespaceSelector( [ 'exclude' => [ 0, 1, 3, 100, 101 ] ] @@ -447,23 +408,23 @@ class HtmlTest extends MediaWikiTestCase { public function testCanDisableANamespaces() { $this->assertEquals( - '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . '', Html::namespaceSelector( [ 'disable' => [ 0, 1, 2, 3, 4 ] @@ -478,7 +439,7 @@ class HtmlTest extends MediaWikiTestCase { */ public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) { $this->assertEquals( - '', + '', Html::element( 'input', [ 'type' => $HTML5InputType ] ), 'In HTML5, Html::element() should accept type="' . $HTML5InputType . '"' ); @@ -528,14 +489,14 @@ class HtmlTest extends MediaWikiTestCase { $cases = []; # ## Generic cases, match $attribDefault static array - $cases[] = [ '', + $cases[] = [ '', 'area', [ 'shape' => 'rect' ] ]; - $cases[] = [ '', + $cases[] = [ '', 'button', [ 'formaction' => 'GET' ] ]; - $cases[] = [ '', + $cases[] = [ '', 'button', [ 'formenctype' => 'application/x-www-form-urlencoded' ] ]; @@ -553,7 +514,7 @@ class HtmlTest extends MediaWikiTestCase { 'canvas', [ 'width' => 300 ] ]; - $cases[] = [ '', + $cases[] = [ '', 'command', [ 'type' => 'command' ] ]; @@ -567,18 +528,18 @@ class HtmlTest extends MediaWikiTestCase { 'form', [ 'enctype' => 'application/x-www-form-urlencoded' ] ]; - $cases[] = [ '', + $cases[] = [ '', 'input', [ 'formaction' => 'GET' ] ]; - $cases[] = [ '', + $cases[] = [ '', 'input', [ 'type' => 'text' ] ]; - $cases[] = [ '', + $cases[] = [ '', 'keygen', [ 'keytype' => 'rsa' ] ]; - $cases[] = [ '', + $cases[] = [ '', 'link', [ 'media' => 'all' ] ]; @@ -604,44 +565,44 @@ class HtmlTest extends MediaWikiTestCase { # ## SPECIFIC CASES # - $cases[] = [ '', + $cases[] = [ '', 'link', [ 'type' => 'text/css' ] ]; # specific handling - $cases[] = [ '', + $cases[] = [ '', 'input', [ 'type' => 'checkbox', 'value' => 'on' ], 'Default value "on" is stripped of checkboxes', ]; - $cases[] = [ '', + $cases[] = [ '', 'input', [ 'type' => 'radio', 'value' => 'on' ], 'Default value "on" is stripped of radio buttons', ]; - $cases[] = [ '', + $cases[] = [ '', 'input', [ 'type' => 'submit', 'value' => 'Submit' ], 'Default value "Submit" is kept on submit buttons (for possible l10n issues)', ]; - $cases[] = [ '', + $cases[] = [ '', 'input', [ 'type' => 'color', 'value' => '' ], ]; - $cases[] = [ '', + $cases[] = [ '', 'input', [ 'type' => 'range', 'value' => '' ], ]; # ', + $cases[] = [ '', 'button', [ 'type' => 'submit' ], 'According to standard the default type is "submit". ' . 'Depending on compatibility mode IE might use "button", instead.', ]; # ', + $cases[] = [ '', 'select', [ 'size' => '4', 'multiple' => true ], ]; # .. with numeric value - $cases[] = [ '', + $cases[] = [ '', 'select', [ 'size' => 4, 'multiple' => true ], ]; $cases[] = [ '', @@ -693,7 +654,7 @@ class HtmlTest extends MediaWikiTestCase { 'Blacklist form validation attributes.' ); $this->assertEquals( - ' step=any', + ' step="any"', Html::expandAttributes( [ 'min' => 1, @@ -709,12 +670,12 @@ class HtmlTest extends MediaWikiTestCase { public function testWrapperInput() { $this->assertEquals( - '', + '', Html::input( 'testname', 'testval', 'radio' ), 'Input wrapper with type and value.' ); $this->assertEquals( - '', + '', Html::input( 'testname' ), 'Input wrapper with all default values.' ); @@ -722,17 +683,17 @@ class HtmlTest extends MediaWikiTestCase { public function testWrapperCheck() { $this->assertEquals( - '', + '', Html::check( 'testname' ), 'Checkbox wrapper unchecked.' ); $this->assertEquals( - '', + '', Html::check( 'testname', true ), 'Checkbox wrapper checked.' ); $this->assertEquals( - '', + '', Html::check( 'testname', false, [ 'value' => 'testval' ] ), 'Checkbox wrapper with a value override.' ); @@ -740,17 +701,17 @@ class HtmlTest extends MediaWikiTestCase { public function testWrapperRadio() { $this->assertEquals( - '', + '', Html::radio( 'testname' ), 'Radio wrapper unchecked.' ); $this->assertEquals( - '', + '', Html::radio( 'testname', true ), 'Radio wrapper checked.' ); $this->assertEquals( - '', + '', Html::radio( 'testname', false, [ 'value' => 'testval' ] ), 'Radio wrapper with a value override.' ); @@ -758,7 +719,7 @@ class HtmlTest extends MediaWikiTestCase { public function testWrapperLabel() { $this->assertEquals( - '', + '', Html::label( 'testlabel', 'testid' ), 'Label wrapper' );