fix: link tag missing type="application/rss+xml"

This commit is contained in:
kenjis 2022-12-25 16:34:59 +09:00
parent fc63748222
commit 9654a8c00b
No known key found for this signature in database
GPG Key ID: BD254878922AF198
2 changed files with 51 additions and 6 deletions

View File

@ -222,13 +222,20 @@ if (! function_exists('link_tag')) {
/**
* Link
*
* Generates link to a CSS file
* Generates link tag
*
* @param array|string $href Stylesheet href or an array
* @param bool $indexPage should indexPage be added to the CSS path.
* @param array<string, bool|string>|string $href Stylesheet href or an array
* @param bool $indexPage should indexPage be added to the CSS path.
*/
function link_tag($href = '', string $rel = 'stylesheet', string $type = 'text/css', string $title = '', string $media = '', bool $indexPage = false, string $hreflang = ''): string
{
function link_tag(
$href = '',
string $rel = 'stylesheet',
string $type = 'text/css',
string $title = '',
string $media = '',
bool $indexPage = false,
string $hreflang = ''
): string {
$link = '<link ';
// extract fields if needed
@ -258,7 +265,7 @@ if (! function_exists('link_tag')) {
$link .= 'rel="' . $rel . '" ';
if (! in_array($rel, ['alternate', 'canonical'], true)) {
if ($type !== '' && $rel !== 'canonical') {
$link .= 'type="' . $type . '" ';
}

View File

@ -319,6 +319,44 @@ final class HTMLHelperTest extends CIUnitTestCase
$this->assertSame($expected, link_tag($target, 'banana', 'fruit', 'Go away', 'VHS'));
}
public function testLinkTagFavicon()
{
$tag = link_tag('favicon.ico', 'shortcut icon', 'image/ico');
$expected = '<link href="http://example.com/favicon.ico" rel="shortcut icon" type="image/ico" />';
$this->assertSame($expected, $tag);
}
public function testLinkTagRss()
{
$tag = link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');
$expected = '<link href="http://example.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />';
$this->assertSame($expected, $tag);
}
public function testLinkTagAlternate()
{
$tag = link_tag(
'http://sp.example.com/',
'alternate',
'',
'',
'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');
$expected = '<link href="http://www.example.com/" rel="canonical" />';
$this->assertSame($expected, $tag);
}
public function testLinkTagArray()
{
$parms = [