Skip to content

Commit 15af170

Browse files
ENGCOM-6239: Fix loose switch comparison when adding links without content types #25473
2 parents 6dd8ddf + 3124e73 commit 15af170

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

lib/internal/Magento/Framework/View/Page/Config/Renderer.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,19 +349,18 @@ protected function getGroupAttributes($group)
349349
*/
350350
protected function addDefaultAttributes($contentType, $attributes)
351351
{
352-
switch ($contentType) {
353-
case 'js':
354-
$attributes = ' type="text/javascript" ' . $attributes;
355-
break;
352+
if ($contentType === 'js') {
353+
return ' type="text/javascript" ' . $attributes;
354+
}
356355

357-
case 'css':
358-
$attributes = ' rel="stylesheet" type="text/css" ' . ($attributes ?: ' media="all"');
359-
break;
356+
if ($contentType === 'css') {
357+
return ' rel="stylesheet" type="text/css" ' . ($attributes ?: ' media="all"');
358+
}
360359

361-
case $this->canTypeBeFont($contentType):
362-
$attributes = 'rel="preload" as="font" crossorigin="anonymous"';
363-
break;
360+
if ($this->canTypeBeFont($contentType)) {
361+
return 'rel="preload" as="font" crossorigin="anonymous"';
364362
}
363+
365364
return $attributes;
366365
}
367366

lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,4 +427,48 @@ public function dataProviderRenderAssets()
427427
],
428428
];
429429
}
430+
431+
public function testRenderAssetWithNoContentType() : void
432+
{
433+
$type = '';
434+
435+
$assetMockOne = $this->createMock(\Magento\Framework\View\Asset\AssetInterface::class);
436+
$assetMockOne->expects($this->exactly(1))
437+
->method('getUrl')
438+
->willReturn('url');
439+
440+
$assetMockOne->expects($this->atLeastOnce())->method('getContentType')->willReturn($type);
441+
442+
$groupAssetsOne = [$assetMockOne];
443+
444+
$groupMockOne = $this->getMockBuilder(\Magento\Framework\View\Asset\PropertyGroup::class)
445+
->disableOriginalConstructor()
446+
->getMock();
447+
$groupMockOne->expects($this->once())
448+
->method('getAll')
449+
->willReturn($groupAssetsOne);
450+
$groupMockOne->expects($this->any())
451+
->method('getProperty')
452+
->willReturnMap(
453+
[
454+
[GroupedCollection::PROPERTY_CAN_MERGE, true],
455+
[GroupedCollection::PROPERTY_CONTENT_TYPE, $type],
456+
['attributes', 'rel="some-rel"'],
457+
['ie_condition', null],
458+
]
459+
);
460+
461+
$this->pageConfigMock->expects($this->once())
462+
->method('getAssetCollection')
463+
->willReturn($this->assetsCollection);
464+
465+
$this->assetsCollection->expects($this->once())
466+
->method('getGroups')
467+
->willReturn([$groupMockOne]);
468+
469+
$this->assertEquals(
470+
'<link rel="some-rel" href="url" />' . "\n",
471+
$this->renderer->renderAssets($this->renderer->getAvailableResultGroups())
472+
);
473+
}
430474
}

0 commit comments

Comments
 (0)