/** * @param bool $isEnabled * @param string $requested * @param string $alternative * @param string $expected * @param string $resolvedOriginal * @param string $resolvedAlternative * @return void * @dataProvider resolveDataProvider */ public function testResolve($isEnabled, $requested, $alternative, $expected, $resolvedOriginal, $resolvedAlternative) { $this->assetMinificationMock->expects($this->any())->method('isEnabled')->willReturn($isEnabled); $this->assetMinificationMock->expects($this->any())->method('addMinifiedSign')->with($requested)->willReturn($alternative); $this->resolverMock->expects($this->any())->method('resolve')->willReturnMap([['', $requested, null, null, null, null, $resolvedOriginal], ['', $alternative, null, null, null, null, $resolvedAlternative]]); $this->assertEquals($expected, $this->minification->resolve('', $requested)); }
public function setUp() { $this->source = $this->getMock('Magento\\Framework\\View\\Asset\\Source', [], [], '', false); $this->context = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface'); $this->minificationMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\Minification')->disableOriginalConstructor()->getMock(); $this->minificationMock->expects($this->any())->method('addMinifiedSign')->willReturnArgument(0); $this->object = new File($this->source, $this->context, 'dir/file.css', 'Magento_Module', 'css', $this->minificationMock); }
/** * @param string $targetPath * @param string $originalPath * @param int $minifyCalls * @param int $setContentCalls * @param bool $isEnabled * @return void * @dataProvider processDataProvider */ public function testProcess($targetPath, $originalPath, $minifyCalls, $setContentCalls, $isEnabled) { $chainMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain')->disableOriginalConstructor()->getMock(); $chainMock->expects($this->any())->method('getTargetAssetPath')->willReturn($targetPath); $chainMock->expects($this->exactly($setContentCalls))->method('setContent')->with('minified content'); $chainMock->expects($this->any())->method('getContent')->willReturn('original content'); $chainMock->expects($this->any())->method('getOrigAssetPath')->willReturn($originalPath); $this->adapterMock->expects($this->exactly($minifyCalls))->method('minify')->with('original content')->willReturn('minified content'); $this->minificationMock->expects($this->any())->method('isEnabled')->willReturnMap([['css', $isEnabled]]); $this->minificationMock->expects($this->any())->method('isMinifiedFilename')->willReturnMap([['test.min.css', true], ['test.jpeg', false], ['test.css', false]]); $this->minify->process($chainMock); }
public function testResolveJsToNotFindMinifiedVersion() { $this->resolverMock ->expects($this->exactly(2)) ->method('resolve') ->willReturnMap( [ ['', 'test.js', null, null, null, null, '/var/test.js'], ['', 'test.min.js', null, null, null, null, false] ] ); $this->assetMinificationMock->expects($this->once()) ->method('isMinifiedFilename') ->willReturn(false); $this->assetMinificationMock->expects($this->once()) ->method('isEnabled') ->with('js') ->willReturn(true); $this->assetMinificationMock->expects($this->once()) ->method('addMinifiedSign') ->with('test.js') ->willReturn('test.min.js'); $this->assertEquals('/var/test.js', $this->minification->resolve('', 'test.js')); }
public function testGetMinResolverRelativePath() { $this->minificationMock->expects($this->any())->method('addMinifiedSign')->willReturnArgument(0); $this->context->expects($this->once())->method('getConfigPath')->will($this->returnValue('path')); $actual = $this->object->getMinResolverRelativePath(); $this->assertSame('path/requirejs-min-resolver.js', $actual); }
/** * @return void * @covers \Magento\Framework\View\Asset\Bundle::getAssetKey * @covers \Magento\Framework\View\Asset\Bundle::save */ public function testMinSuffix() { $this->minificationMock->expects($this->any())->method('addMinifiedSign')->withConsecutive(['onefile.js'], ['onefile.js'], ['/js/bundle/bundle0.js'])->willReturnOnConsecutiveCalls('onefile.min.js', 'onefile.min.js', '/js/bundle/bundle0.min.js'); $contextMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File\\FallbackContext')->disableOriginalConstructor()->getMock(); $contextMock->expects($this->any())->method('getAreaCode')->willReturn('area'); $contextMock->expects($this->any())->method('getThemePath')->willReturn('theme-path'); $contextMock->expects($this->any())->method('getLocale')->willReturn('locale'); $assetMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\LocalInterface')->setMethods(['getContentType', 'getContext'])->getMockForAbstractClass(); $assetMock->expects($this->any())->method('getContext')->willReturn($contextMock); $assetMock->expects($this->any())->method('getContentType')->willReturn('js'); $assetMock->expects($this->any())->method('getFilePath')->willReturn('onefile.js'); $writeMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\WriteInterface')->getMockForAbstractClass(); $writeMock->expects($this->once())->method('writeFile')->with('/js/bundle/bundle0.min.js', $this->stringContains('onefile.min.js')); $this->filesystemMock->expects($this->any())->method('getDirectoryWrite')->willReturn($writeMock); $this->bundle->addAsset($assetMock); $this->bundle->flush(); }
public function testSetLayout() { $this->bundleConfig->expects($this->once())->method('isBundlingJsFiles')->willReturn(true); $filePath = 'require_js_fie_path'; $asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface'); $asset->expects($this->atLeastOnce())->method('getFilePath')->willReturn($filePath); $requireJsAsset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface'); $requireJsAsset->expects($this->atLeastOnce())->method('getFilePath')->willReturn('/path/to/require/require.js'); $minResolverAsset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface'); $minResolverAsset->expects($this->atLeastOnce())->method('getFilePath')->willReturn('/path/to/require/require-min-resolver.js'); $this->fileManager->expects($this->once())->method('createRequireJsConfigAsset')->will($this->returnValue($requireJsAsset)); $this->fileManager->expects($this->once())->method('createRequireJsMixinsAsset')->will($this->returnValue($requireJsAsset)); $this->fileManager->expects($this->once())->method('createStaticJsAsset')->will($this->returnValue($requireJsAsset)); $this->fileManager->expects($this->once())->method('createBundleJsPool')->will($this->returnValue([$asset])); $this->fileManager->expects($this->once())->method('createMinResolverAsset')->will($this->returnValue($minResolverAsset)); $layout = $this->getMock('Magento\\Framework\\View\\LayoutInterface'); $assetCollection = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\GroupedCollection')->disableOriginalConstructor()->getMock(); $this->pageConfig->expects($this->atLeastOnce())->method('getAssetCollection')->willReturn($assetCollection); $assetCollection->expects($this->atLeastOnce())->method('insert')->willReturn(true); $this->minificationMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\Minification')->disableOriginalConstructor()->getMock(); $this->minificationMock->expects($this->any())->method('isEnabled')->with('js')->willReturn(true); $object = new Config($this->context, $this->config, $this->fileManager, $this->pageConfig, $this->bundleConfig, $this->minificationMock); $object->setLayout($layout); }