/** * Convert module notation to a path relative to the specified asset * * For example, the asset is Foo_Bar/styles/style.css and it refers to Bar_Baz::images/logo.gif * (i.e. url(Bar_Baz::images/logo.gif)) * The result will be ../../Bar_Baz/images/logo.gif * * @param Asset\LocalInterface $thisAsset * @param string $relatedFileId * @return string */ public function convertModuleNotationToPath(Asset\LocalInterface $thisAsset, $relatedFileId) { if (false === strpos($relatedFileId, Asset\Repository::FILE_ID_SEPARATOR)) { return $relatedFileId; } $thisPath = $thisAsset->getPath(); $relatedAsset = $this->assetRepo->createSimilar($relatedFileId, $thisAsset); $relatedPath = $relatedAsset->getPath(); $offset = FileSystem::offsetPath($relatedPath, $thisPath); return FileSystem::normalizePath($offset . '/' . basename($relatedPath)); }
/** * @param string $fileId * @param string $similarToModule * @param string $expectedPath * @param string $expectedType * @param string $expectedModule * @dataProvider createSimilarDataProvider */ public function testCreateSimilar($fileId, $similarToModule, $expectedPath, $expectedType, $expectedModule) { $similarTo = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface'); $context = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface'); $similarTo->expects($this->once())->method('getContext')->will($this->returnValue($context)); $similarTo->expects($this->any())->method('getModule')->will($this->returnValue($similarToModule)); $asset = $this->object->createSimilar($fileId, $similarTo); $this->assertInstanceOf('\\Magento\\Framework\\View\\Asset\\File', $asset); $this->assertSame($context, $asset->getContext()); $this->assertEquals($expectedPath, $asset->getFilePath()); $this->assertEquals($expectedType, $asset->getContentType()); $this->assertEquals($expectedModule, $asset->getModule()); }