Skip to content

Commit 9654a8c

Browse files
committed
fix: link tag missing type="application/rss+xml"
1 parent fc63748 commit 9654a8c

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

system/Helpers/html_helper.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,20 @@ function script_tag($src = '', bool $indexPage = false): string
222222
/**
223223
* Link
224224
*
225-
* Generates link to a CSS file
225+
* Generates link tag
226226
*
227-
* @param array|string $href Stylesheet href or an array
228-
* @param bool $indexPage should indexPage be added to the CSS path.
227+
* @param array<string, bool|string>|string $href Stylesheet href or an array
228+
* @param bool $indexPage should indexPage be added to the CSS path.
229229
*/
230-
function link_tag($href = '', string $rel = 'stylesheet', string $type = 'text/css', string $title = '', string $media = '', bool $indexPage = false, string $hreflang = ''): string
231-
{
230+
function link_tag(
231+
$href = '',
232+
string $rel = 'stylesheet',
233+
string $type = 'text/css',
234+
string $title = '',
235+
string $media = '',
236+
bool $indexPage = false,
237+
string $hreflang = ''
238+
): string {
232239
$link = '<link ';
233240

234241
// extract fields if needed
@@ -258,7 +265,7 @@ function link_tag($href = '', string $rel = 'stylesheet', string $type = 'text/c
258265

259266
$link .= 'rel="' . $rel . '" ';
260267

261-
if (! in_array($rel, ['alternate', 'canonical'], true)) {
268+
if ($type !== '' && $rel !== 'canonical') {
262269
$link .= 'type="' . $type . '" ';
263270
}
264271

tests/system/Helpers/HTMLHelperTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,44 @@ public function testLinkTagComplete()
319319
$this->assertSame($expected, link_tag($target, 'banana', 'fruit', 'Go away', 'VHS'));
320320
}
321321

322+
public function testLinkTagFavicon()
323+
{
324+
$tag = link_tag('favicon.ico', 'shortcut icon', 'image/ico');
325+
326+
$expected = '<link href="http://example.com/favicon.ico" rel="shortcut icon" type="image/ico" />';
327+
$this->assertSame($expected, $tag);
328+
}
329+
330+
public function testLinkTagRss()
331+
{
332+
$tag = link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');
333+
334+
$expected = '<link href="http://example.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />';
335+
$this->assertSame($expected, $tag);
336+
}
337+
338+
public function testLinkTagAlternate()
339+
{
340+
$tag = link_tag(
341+
'http://sp.example.com/',
342+
'alternate',
343+
'',
344+
'',
345+
'only screen and (max-width: 640px)'
346+
);
347+
348+
$expected = '<link href="http://sp.example.com/" rel="alternate" media="only screen and (max-width: 640px)" />';
349+
$this->assertSame($expected, $tag);
350+
}
351+
352+
public function testLinkTagCanonical()
353+
{
354+
$tag = link_tag('http://www.example.com/', 'canonical');
355+
356+
$expected = '<link href="http://www.example.com/" rel="canonical" />';
357+
$this->assertSame($expected, $tag);
358+
}
359+
322360
public function testLinkTagArray()
323361
{
324362
$parms = [

0 commit comments

Comments
 (0)