diff --git a/lib/internal/Magento/Framework/View/Page/Config/Metadata/MsApplicationTileImage.php b/lib/internal/Magento/Framework/View/Page/Config/Metadata/MsApplicationTileImage.php new file mode 100644 index 0000000000000..ae6401334a251 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Page/Config/Metadata/MsApplicationTileImage.php @@ -0,0 +1,52 @@ +assetRepo = $assetRepo; + } + + /** + * Get asset URL from given metadata content + * + * @param string $content + * + * @return string + */ + public function getUrl(string $content): string + { + if (!parse_url($content, PHP_URL_SCHEME)) { + return $this->assetRepo->getUrl($content); + } + + return $content; + } +} diff --git a/lib/internal/Magento/Framework/View/Page/Config/Renderer.php b/lib/internal/Magento/Framework/View/Page/Config/Renderer.php index b7a1e0b707013..eae6126fa39c0 100644 --- a/lib/internal/Magento/Framework/View/Page/Config/Renderer.php +++ b/lib/internal/Magento/Framework/View/Page/Config/Renderer.php @@ -9,6 +9,7 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Asset\GroupedCollection; use Magento\Framework\View\Page\Config; +use Magento\Framework\View\Page\Config\Metadata\MsApplicationTileImage; /** * Page config Renderer model @@ -74,6 +75,11 @@ class Renderer implements RendererInterface */ protected $urlBuilder; + /** + * @var MsApplicationTileImage + */ + private $msApplicationTileImage; + /** * @param Config $pageConfig * @param \Magento\Framework\View\Asset\MergeService $assetMergeService @@ -81,6 +87,7 @@ class Renderer implements RendererInterface * @param \Magento\Framework\Escaper $escaper * @param \Magento\Framework\Stdlib\StringUtils $string * @param \Psr\Log\LoggerInterface $logger + * @param MsApplicationTileImage|null $msApplicationTileImage */ public function __construct( Config $pageConfig, @@ -88,7 +95,8 @@ public function __construct( \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\Escaper $escaper, \Magento\Framework\Stdlib\StringUtils $string, - \Psr\Log\LoggerInterface $logger + \Psr\Log\LoggerInterface $logger, + MsApplicationTileImage $msApplicationTileImage = null ) { $this->pageConfig = $pageConfig; $this->assetMergeService = $assetMergeService; @@ -96,6 +104,8 @@ public function __construct( $this->escaper = $escaper; $this->string = $string; $this->logger = $logger; + $this->msApplicationTileImage = $msApplicationTileImage ?: + \Magento\Framework\App\ObjectManager::getInstance()->get(MsApplicationTileImage::class); } /** @@ -179,6 +189,10 @@ protected function processMetadataContent($name, $content) if (method_exists($this->pageConfig, $method)) { $content = $this->pageConfig->$method(); } + if ($content && $name === $this->msApplicationTileImage::META_NAME) { + $content = $this->msApplicationTileImage->getUrl($content); + } + return $content; } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php index 1f110a9ec19b5..a702ea5458a87 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php @@ -8,6 +8,7 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\View\Asset\GroupedCollection; +use Magento\Framework\View\Page\Config\Metadata\MsApplicationTileImage; use Magento\Framework\View\Page\Config\Renderer; use Magento\Framework\View\Page\Config\Generator; @@ -58,6 +59,11 @@ class RendererTest extends \PHPUnit\Framework\TestCase */ protected $loggerMock; + /** + * @var MsApplicationTileImage|\PHPUnit_Framework_MockObject_MockObject + */ + protected $msApplicationTileImageMock; + /** * @var \Magento\Framework\View\Asset\GroupedCollection|\PHPUnit_Framework_MockObject_MockObject */ @@ -99,6 +105,10 @@ protected function setUp() $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class) ->getMock(); + $this->msApplicationTileImageMock = $this->getMockBuilder(MsApplicationTileImage::class) + ->disableOriginalConstructor() + ->getMock(); + $this->assetsCollection = $this->getMockBuilder(\Magento\Framework\View\Asset\GroupedCollection::class) ->setMethods(['getGroups']) ->disableOriginalConstructor() @@ -120,7 +130,8 @@ protected function setUp() 'urlBuilder' => $this->urlBuilderMock, 'escaper' => $this->escaperMock, 'string' => $this->stringMock, - 'logger' => $this->loggerMock + 'logger' => $this->loggerMock, + 'msApplicationTileImage' => $this->msApplicationTileImageMock ] ); } @@ -147,7 +158,8 @@ public function testRenderMetadata() 'content_type' => 'content_type_value', 'x_ua_compatible' => 'x_ua_compatible_value', 'media_type' => 'media_type_value', - 'og:video:secure_url' => 'secure_url' + 'og:video:secure_url' => 'secure_url', + 'msapplication-TileImage' => 'https://site.domain/ms-tile.jpg' ]; $metadataValueCharset = 'newCharsetValue'; @@ -155,7 +167,8 @@ public function testRenderMetadata() . '' . "\n" . '' . "\n" . '' . "\n" - . '' . "\n"; + . '' . "\n" + . '' . "\n"; $this->stringMock->expects($this->at(0)) ->method('upperCaseWords') @@ -171,6 +184,37 @@ public function testRenderMetadata() ->method('getMetadata') ->will($this->returnValue($metadata)); + $this->msApplicationTileImageMock + ->expects($this->once()) + ->method('getUrl') + ->with('https://site.domain/ms-tile.jpg') + ->will($this->returnValue('https://site.domain/ms-tile.jpg')); + + $this->assertEquals($expected, $this->renderer->renderMetadata()); + } + + /** + * Test renderMetadata when it has 'msapplication-TileImage' meta passed + */ + public function testRenderMetadataWithMsApplicationTileImageAsset() + { + $metadata = [ + 'msapplication-TileImage' => 'images/ms-tile.jpg' + ]; + $expectedMetaUrl = 'https://site.domain/images/ms-tile.jpg'; + $expected = '' . "\n"; + + $this->pageConfigMock + ->expects($this->once()) + ->method('getMetadata') + ->will($this->returnValue($metadata)); + + $this->msApplicationTileImageMock + ->expects($this->once()) + ->method('getUrl') + ->with('images/ms-tile.jpg') + ->will($this->returnValue($expectedMetaUrl)); + $this->assertEquals($expected, $this->renderer->renderMetadata()); } @@ -277,12 +321,14 @@ public function testRenderAssets($groupOne, $groupTwo, $expectedResult) ->willReturn($groupAssetsOne); $groupMockOne->expects($this->any()) ->method('getProperty') - ->willReturnMap([ - [GroupedCollection::PROPERTY_CAN_MERGE, true], - [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupOne['type']], - ['attributes', $groupOne['attributes']], - ['ie_condition', $groupOne['condition']], - ]); + ->willReturnMap( + [ + [GroupedCollection::PROPERTY_CAN_MERGE, true], + [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupOne['type']], + ['attributes', $groupOne['attributes']], + ['ie_condition', $groupOne['condition']], + ] + ); $assetMockTwo = $this->createMock(\Magento\Framework\View\Asset\AssetInterface::class); $assetMockTwo->expects($this->once()) @@ -300,12 +346,14 @@ public function testRenderAssets($groupOne, $groupTwo, $expectedResult) ->willReturn($groupAssetsTwo); $groupMockTwo->expects($this->any()) ->method('getProperty') - ->willReturnMap([ - [GroupedCollection::PROPERTY_CAN_MERGE, true], - [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupTwo['type']], - ['attributes', $groupTwo['attributes']], - ['ie_condition', $groupTwo['condition']], - ]); + ->willReturnMap( + [ + [GroupedCollection::PROPERTY_CAN_MERGE, true], + [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupTwo['type']], + ['attributes', $groupTwo['attributes']], + ['ie_condition', $groupTwo['condition']], + ] + ); $this->pageConfigMock->expects($this->once()) ->method('getAssetCollection')