/** * @param string $origFile * @param string $origPath * @param string $origContent * @param bool $isMaterialization * @param bool $isExist * * @dataProvider getFileDataProvider */ public function testGetFile($origFile, $origPath, $origContent, $isMaterialization, $isExist) { $filePath = 'some/file.ext'; $read = $this->getMock('Magento\Framework\Filesystem\Directory\Read', [], [], '', false); $read->expects($this->at(0))->method('readFile')->with($origPath)->willReturn($origContent); $this->readFactory->expects($this->atLeastOnce())->method('create')->willReturn($read); $this->viewFileResolution->expects($this->once()) ->method('getFile') ->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module') ->willReturn($origFile); $this->preProcessorPool->expects($this->once()) ->method('process') ->with($this->chain); $this->staticDirRead->expects($this->any()) ->method('isExist') ->willReturn($isExist); if ($isMaterialization || !$isExist) { $this->chain ->expects($this->once()) ->method('isChanged') ->willReturn(true); $this->chain ->expects($this->once()) ->method('getContent') ->willReturn('processed'); $this->chain ->expects($this->once()) ->method('getTargetAssetPath') ->willReturn($filePath); $this->varDir->expects($this->once()) ->method('writeFile') ->with('view_preprocessed/source/some/file.ext', 'processed'); $this->varDir->expects($this->once()) ->method('getAbsolutePath') ->willReturn('var'); $read->expects($this->once()) ->method('getAbsolutePath') ->with('view_preprocessed/source/some/file.ext') ->willReturn('result'); } else { $this->varDir->expects($this->never())->method('writeFile'); $read->expects($this->at(1)) ->method('getAbsolutePath') ->with('file.ext') ->willReturn('result'); } $this->assertSame('result', $this->object->getFile($this->getAsset())); }
/** * Get image URL of WYSIWYG placeholder image * * @param string $type * @return string */ public function getPlaceholderImageUrl($type) { $placeholder = false; $widget = $this->getWidgetByClassType($type); if (is_array($widget) && isset($widget['placeholder_image'])) { $placeholder = (string) $widget['placeholder_image']; } if ($placeholder) { $asset = $this->assetRepo->createAsset($placeholder); $placeholder = $this->assetSource->getFile($asset); if ($placeholder) { return $asset->getUrl(); } } return $this->assetRepo->getUrl('Magento_Widget::placeholder.gif'); }
/** * @param $origFile * @param $origPath * @param $origContent * @param $isMaterialization * * @dataProvider getFileDataProvider */ public function testGetFile($origFile, $origPath, $origContent, $isMaterialization) { $filePath = 'some/file.ext'; $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->rootDirRead->expects($this->once())->method('readFile')->with($origPath)->will($this->returnValue($origContent)); $this->preProcessorPool->expects($this->once())->method('process')->with($this->chain); if ($isMaterialization) { $this->chain->expects($this->once())->method('isChanged')->willReturn(true); $this->chain->expects($this->once())->method('getContent')->willReturn('processed'); $this->chain->expects($this->once())->method('getTargetAssetPath')->willReturn($filePath); $this->varDir->expects($this->once())->method('writeFile')->with('view_preprocessed/source/some/file.ext', 'processed'); $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->rootDirRead->expects($this->once())->method('getAbsolutePath')->with('source/some/file.ext')->will($this->returnValue('result')); } $this->assertSame('result', $this->object->getFile($this->getAsset())); }
/** * @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([$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([DirectoryList::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([DirectoryList::ROOT, '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())); }