/** * {@inheritdoc} * @throws File\NotFoundException if file cannot be resolved */ public function getSourceFile() { if (null === $this->resolvedFile) { $this->resolvedFile = $this->source->getFile($this); if (false === $this->resolvedFile) { throw new File\NotFoundException("Unable to resolve the source file for '{$this->getPath()}'"); } } return $this->resolvedFile; }
/** * @param string $origFile * @param string $origPath * @param string $origContentType * @param string $origContent * @param string $isMaterialization * @dataProvider getFileDataProvider */ public function testGetFile($origFile, $origPath, $origContentType, $origContent, $isMaterialization) { $filePath = 'some/file.ext'; $cacheValue = "{$origPath}:{$filePath}"; $this->viewFileResolution->expects($this->once())->method('getFile')->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module')->will($this->returnValue($origFile)); $this->rootDirRead->expects($this->once())->method('getRelativePath')->with($origFile)->will($this->returnValue($origPath)); $this->cache->expects($this->once())->method('load')->will($this->returnValue(false)); $this->rootDirRead->expects($this->once())->method('readFile')->with($origPath)->will($this->returnValue($origContent)); $processor = $this->getMockForAbstractClass('Magento\\Framework\\View\\Asset\\PreProcessorInterface'); $this->preProcessorPool->expects($this->once())->method('getPreProcessors')->with($origContentType, 'ext')->will($this->returnValue([$processor])); $processor->expects($this->once())->method('process')->will($this->returnCallback(array($this, 'chainTestCallback'))); if ($isMaterialization) { $this->varDir->expects($this->once())->method('writeFile')->with('view_preprocessed/source/some/file.ext', 'processed'); $this->cache->expects($this->once())->method('save')->with(serialize([\Magento\Framework\App\Filesystem::VAR_DIR, 'view_preprocessed/source/some/file.ext']), $cacheValue); $this->varDir->expects($this->once())->method('getAbsolutePath')->with('view_preprocessed/source/some/file.ext')->will($this->returnValue('result')); } else { $this->varDir->expects($this->never())->method('writeFile'); $this->cache->expects($this->once())->method('save')->with(serialize([\Magento\Framework\App\Filesystem::ROOT_DIR, 'source/some/file.ext']), $cacheValue); $this->rootDirRead->expects($this->once())->method('getAbsolutePath')->with('source/some/file.ext')->will($this->returnValue('result')); } $this->assertSame('result', $this->object->getFile($this->getAsset())); }