fix: fix incorrect test and support other patterns

This commit is contained in:
kenjis 2022-12-25 17:27:06 +09:00
parent 28222928de
commit fb7649386f
No known key found for this signature in database
GPG Key ID: BD254878922AF198
2 changed files with 27 additions and 5 deletions

View File

@ -265,7 +265,7 @@ if (! function_exists('link_tag')) {
$link .= 'rel="' . $rel . '" ';
if ($type !== '' && $rel !== 'canonical' && $hreflang === '') {
if ($type !== '' && $rel !== 'canonical' && $hreflang === '' && ! ($rel === 'alternate' && $media !== '')) {
$link .= 'type="' . $type . '" ';
}

View File

@ -312,11 +312,21 @@ final class HTMLHelperTest extends CIUnitTestCase
$this->assertSame($expected, link_tag($target));
}
public function testLinkTagComplete()
public function testLinkTagMedia()
{
$target = 'https://styles.com/css/mystyles.css';
$expected = '<link href="https://styles.com/css/mystyles.css" rel="banana" type="fruit" media="VHS" title="Go away" />';
$this->assertSame($expected, link_tag($target, 'banana', 'fruit', 'Go away', 'VHS'));
$target = 'https://styles.com/css/mystyles.css';
$tag = link_tag($target, 'stylesheet', 'text/css', '', 'print');
$expected = '<link href="https://styles.com/css/mystyles.css" rel="stylesheet" type="text/css" media="print" />';
$this->assertSame($expected, $tag);
}
public function testLinkTagTitle()
{
$tag = link_tag('default.css', 'stylesheet', 'text/css', 'Default Style');
$expected = '<link href="http://example.com/default.css" rel="stylesheet" type="text/css" title="Default Style" />';
$this->assertSame($expected, $tag);
}
public function testLinkTagFavicon()
@ -349,6 +359,18 @@ final class HTMLHelperTest extends CIUnitTestCase
$this->assertSame($expected, $tag);
}
public function testLinkTagArrayAlternate()
{
$tag = link_tag([
'href' => 'http://sp.example.com/',
'rel' => 'alternate',
'media' => 'only screen and (max-width: 640px)',
]);
$expected = '<link href="http://sp.example.com/" rel="alternate" media="only screen and (max-width: 640px)" />';
$this->assertSame($expected, $tag);
}
public function testLinkTagCanonical()
{
$tag = link_tag('http://www.example.com/', 'canonical');