mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-07 10:11:17 +02:00
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).
69 lines
1.8 KiB
PHP
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 & 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>');
|
|
}
|
|
}
|