public function testMergeCss() { $this->resultAsset->expects($this->exactly(3))->method('getPath')->will($this->returnValue('foo/result')); $this->resultAsset->expects($this->any())->method('getContentType')->will($this->returnValue('css')); $assets = $this->prepareAssetsToMerge(['one', 'two']); $this->cssUrlResolver->expects($this->exactly(2))->method('relocateRelativeUrls')->will($this->onConsecutiveCalls('1', '2')); $this->cssUrlResolver->expects($this->once())->method('aggregateImportDirectives')->with('12')->will($this->returnValue('1020')); $this->writeDir->expects($this->once())->method('writeFile')->with('foo/result', '1020'); $this->object->merge($assets, $this->resultAsset); }
protected function prepareAttemptToMinifyMock($fileExists, $rootDirExpectations = true, $originalExists = true) { $this->asset->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue('test/admin.js')); $this->asset->expects($this->atLeastOnce())->method('getSourceFile')->will($this->returnValue('/foo/bar/test/admin.js')); if ($rootDirExpectations) { $this->rootDir->expects($this->once())->method('getRelativePath')->with('/foo/bar/test/admin.min.js')->will($this->returnValue('test/admin.min.js')); $this->rootDir->expects($this->once())->method('isExist')->with('test/admin.min.js')->will($this->returnValue(false)); } $this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/')); $this->staticViewDir->expects($this->exactly(2 - intval($originalExists)))->method('isExist')->will($this->returnValue($fileExists)); }
public function testAddAsset() { $dirRead = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->disableOriginalConstructor()->getMock(); $context = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File\\FallbackContext')->disableOriginalConstructor()->getMock(); $configView = $this->getMockBuilder('Magento\\Framework\\Config\\View')->disableOriginalConstructor()->getMock(); $this->filesystem->expects($this->once())->method('getDirectoryRead')->with(\Magento\Framework\App\Filesystem\DirectoryList::APP)->willReturn($dirRead); $this->asset->expects($this->atLeastOnce())->method('getSourceFile')->willReturn('/path/to/source/file.min.js'); $this->asset->expects($this->atLeastOnce())->method('getContentType')->willReturn('js'); $this->asset->expects($this->once())->method('getPath')->willReturn('/path/to/file.js'); $this->asset->expects($this->atLeastOnce())->method('getContext')->willReturn($context); $this->bundleConfig->expects($this->atLeastOnce())->method('getConfig')->with($context)->willReturn($configView); $configView->expects($this->once())->method('getExcludedFiles')->willReturn([]); $configView->expects($this->once())->method('getExcludedDir')->willReturn([]); $this->bundle->expects($this->once())->method('addAsset')->with($this->asset); $this->assertTrue($this->manager->addAsset($this->asset)); }
/** * @param int $mtimeOrig * @param int $mtimeMinified * @param bool $isMinifyExpected * @dataProvider minifyMtimeDataProvider */ public function testMinifyMtime($mtimeOrig, $mtimeMinified, $isMinifyExpected) { $this->prepareAttemptToMinifyMock(true, false); $model = new Minified($this->_asset, $this->_logger, $this->_filesystem, $this->_baseUrl, $this->_adapter, Minified::MTIME); $this->_rootDir->expects($this->any())->method('getRelativePath')->will($this->returnValueMap([['/foo/bar/test/library.min.js', 'test/library.min.js'], ['/foo/bar/test/library.js', 'test/library.js']])); $this->_rootDir->expects($this->once())->method('isExist')->with('test/library.min.js')->will($this->returnValue(false)); $this->_rootDir->expects($this->once())->method('stat')->with('test/library.js')->will($this->returnValue(['mtime' => $mtimeOrig])); $this->_staticViewDir->expects($this->once())->method('stat')->with($this->anything())->will($this->returnValue(['mtime' => $mtimeMinified])); if ($isMinifyExpected) { $this->_asset->expects($this->once())->method('getContent')->will($this->returnValue('content')); $this->_adapter->expects($this->once())->method('minify')->with('content')->will($this->returnValue('mini')); $this->_staticViewDir->expects($this->once())->method('writeFile')->with($this->anything(), 'mini'); } else { $this->_adapter->expects($this->never())->method('minify'); } $this->assertStringMatchesFormat('%s_library.min.js', $model->getFilePath()); }
public function testAddAsset() { $context = $this->getMockBuilder('Magento\Framework\View\Asset\File\FallbackContext') ->disableOriginalConstructor() ->getMock(); $configView = $this->getMockBuilder('Magento\Framework\Config\View') ->disableOriginalConstructor() ->getMock(); $this->asset->expects($this->atLeastOnce()) ->method('getContentType') ->willReturn('js'); $this->asset->expects($this->once()) ->method('getSourceFile') ->willReturn('/source/file'); $this->asset->expects($this->atLeastOnce()) ->method('getFilePath') ->willReturn('file/path.js'); $this->assetConfig->expects($this->once()) ->method('isAssetMinification') ->willReturn(false); $this->asset->expects($this->atLeastOnce()) ->method('getContext') ->willReturn($context); $this->bundleConfig ->expects($this->atLeastOnce()) ->method('getConfig') ->with($context) ->willReturn($configView); $configView->expects($this->once()) ->method('getExcludedFiles') ->willReturn([]); $configView->expects($this->once()) ->method('getExcludedDir') ->willReturn([]); $this->bundle->expects($this->once()) ->method('addAsset') ->with($this->asset); $this->assertTrue($this->manager->addAsset($this->asset)); }
protected function setUp() { $this->asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface'); $this->asset->expects($this->once())->method('getContentType')->will($this->returnValue('assetType')); $this->object = new Chain($this->asset, 'origContent', 'origType'); }