Skip to content

Commit fb76493

Browse files
committed
fix: fix incorrect test and support other patterns
1 parent 2822292 commit fb76493

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

system/Helpers/html_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function link_tag(
265265

266266
$link .= 'rel="' . $rel . '" ';
267267

268-
if ($type !== '' && $rel !== 'canonical' && $hreflang === '') {
268+
if ($type !== '' && $rel !== 'canonical' && $hreflang === '' && ! ($rel === 'alternate' && $media !== '')) {
269269
$link .= 'type="' . $type . '" ';
270270
}
271271

tests/system/Helpers/HTMLHelperTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,21 @@ public function testLinkTag()
312312
$this->assertSame($expected, link_tag($target));
313313
}
314314

315-
public function testLinkTagComplete()
315+
public function testLinkTagMedia()
316316
{
317-
$target = 'https://styles.com/css/mystyles.css';
318-
$expected = '<link href="https://styles.com/css/mystyles.css" rel="banana" type="fruit" media="VHS" title="Go away" />';
319-
$this->assertSame($expected, link_tag($target, 'banana', 'fruit', 'Go away', 'VHS'));
317+
$target = 'https://styles.com/css/mystyles.css';
318+
$tag = link_tag($target, 'stylesheet', 'text/css', '', 'print');
319+
320+
$expected = '<link href="https://styles.com/css/mystyles.css" rel="stylesheet" type="text/css" media="print" />';
321+
$this->assertSame($expected, $tag);
322+
}
323+
324+
public function testLinkTagTitle()
325+
{
326+
$tag = link_tag('default.css', 'stylesheet', 'text/css', 'Default Style');
327+
328+
$expected = '<link href="http://example.com/default.css" rel="stylesheet" type="text/css" title="Default Style" />';
329+
$this->assertSame($expected, $tag);
320330
}
321331

322332
public function testLinkTagFavicon()
@@ -349,6 +359,18 @@ public function testLinkTagAlternate()
349359
$this->assertSame($expected, $tag);
350360
}
351361

362+
public function testLinkTagArrayAlternate()
363+
{
364+
$tag = link_tag([
365+
'href' => 'http://sp.example.com/',
366+
'rel' => 'alternate',
367+
'media' => 'only screen and (max-width: 640px)',
368+
]);
369+
370+
$expected = '<link href="http://sp.example.com/" rel="alternate" media="only screen and (max-width: 640px)" />';
371+
$this->assertSame($expected, $tag);
372+
}
373+
352374
public function testLinkTagCanonical()
353375
{
354376
$tag = link_tag('http://www.example.com/', 'canonical');

0 commit comments

Comments
 (0)