silverstripe-framework/tests/php/View/HTMLTest.php
Garion Herman 0d27f32cc9 FIX Add 'legal empty attributes' to allow empty alt values on imgs
In some situations, a caption is used in place of a value in the alt
attribute, and in others an image may be cosmetic and not in need of an
alt attribute value (though the alt attribute must still be rendered in
this case).
2019-09-24 11:44:12 +12:00

69 lines
1.8 KiB
PHP

<?php
namespace SilverStripe\View\Tests;
use InvalidArgumentException;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\HTML;
class HTMLTest extends SapphireTest
{
public function testCreateVoidTag()
{
$tag = HTML::createTag('meta', [
'name' => 'description',
'content' => 'test tag',
]);
$this->assertEquals('<meta name="description" content="test tag" />', $tag);
}
public function testEmptyAttributes()
{
$tag = HTML::createTag('meta', [
'value' => 0,
'content' => '',
'max' => 3,
'details' => null,
'disabled' => false,
'readonly' => true,
]);
$this->assertEquals('<meta value="0" max="3" readonly="1" />', $tag);
}
public function testNormalTag()
{
$tag = HTML::createTag('a', [
'title' => 'Some link',
'nullattr' => null,
]);
$this->assertEquals('<a title="Some link"></a>', $tag);
$tag = HTML::createTag('a', [
'title' => 'HTML & Text',
'nullattr' => null,
], 'Some <strong>content!</strong>');
$this->assertEquals('<a title="HTML &amp; Text">Some <strong>content!</strong></a>', $tag);
}
public function testImgTag()
{
$tag = HTML::createTag('img', [
'src' => 'example.png',
'alt' => '',
]);
$this->assertEquals('<img src="example.png" alt="" />', $tag);
}
public function testVoidContentError()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("Void element \"link\" cannot have content");
HTML::createTag('link', [
'title' => 'HTML & Text',
'nullattr' => null,
], 'Some <strong>content!</strong>');
}
}