public function testGetConfig() { $this->fileReader->expects($this->any())->method('readAll')->will($this->returnCallback(function ($file) { return $file . ' content'; })); $fileOne = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false); $fileOne->expects($this->once())->method('getFilename')->will($this->returnValue('some/full/relative/path/file_one.js')); $fileOne->expects($this->once())->method('getName')->will($this->returnValue('file_one.js')); $fileOne->expects($this->once())->method('getModule')->will($this->returnValue('Module_One')); $fileTwo = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false); $fileTwo->expects($this->once())->method('getFilename')->will($this->returnValue('some/full/relative/path/file_two.js')); $fileTwo->expects($this->once())->method('getName')->will($this->returnValue('file_two.js')); $theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface'); $this->design->expects($this->once())->method('getDesignTheme')->will($this->returnValue($theme)); $this->fileSource->expects($this->once())->method('getFiles')->with($theme, Config::CONFIG_FILE_NAME)->will($this->returnValue([$fileOne, $fileTwo])); $this->minificationMock->expects($this->atLeastOnce())->method('isEnabled')->with('js')->willReturn(true); $expected = <<<expected (function(require){ (function() { file_one.js content require.config(config); })(); (function() { file_two.js content require.config(config); })(); })(require); expected; $this->minifyAdapterMock->expects($this->once())->method('minify')->with($expected)->willReturnArgument(0); $actual = $this->object->getConfig(); $this->assertEquals($actual, $expected); }
public function testGetConfig() { $this->baseDir->expects($this->any())->method('getRelativePath')->will($this->returnCallback(function ($path) { return 'relative/' . $path; })); $this->baseDir->expects($this->any())->method('readFile')->will($this->returnCallback(function ($file) { return $file . ' content'; })); $fileOne = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false); $fileOne->expects($this->once())->method('getFilename')->will($this->returnValue('file_one.js')); $fileOne->expects($this->once())->method('getModule')->will($this->returnValue('Module_One')); $fileTwo = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false); $fileTwo->expects($this->once())->method('getFilename')->will($this->returnValue('file_two.js')); $theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface'); $this->design->expects($this->once())->method('getDesignTheme')->will($this->returnValue($theme)); $this->fileSource->expects($this->once())->method('getFiles')->with($theme, Config::CONFIG_FILE_NAME)->will($this->returnValue([$fileOne, $fileTwo])); $expected = <<<expected (function(require){ require.config({"baseUrl":""}); (function() { relative/file_one.js content require.config(config); })(); (function() { relative/file_two.js content require.config(config); })(); })(require); expected; $actual = $this->object->getConfig(); $this->assertStringMatchesFormat($expected, $actual); }
/** * Get aggregated distributed configuration * * @return string */ public function getConfig() { $distributedConfig = ''; $baseConfig = $this->getBaseConfig(); $customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME); foreach ($customConfigFiles as $file) { $config = $this->baseDir->readFile($this->baseDir->getRelativePath($file->getFilename())); $distributedConfig .= str_replace(['%config%', '%context%'], [$config, $file->getModule()], self::PARTIAL_CONFIG_TEMPLATE); } $fullConfig = str_replace(['%function%', '%base%', '%usages%'], [$distributedConfig, $baseConfig], self::FULL_CONFIG_TEMPLATE); return $fullConfig; }
/** * Get aggregated distributed configuration * * @return string */ public function getConfig() { $functionSource = __DIR__ . '/paths-updater.js'; $functionDeclaration = $this->baseDir->readFile($this->baseDir->getRelativePath($functionSource)); $distributedConfig = ''; $customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME); foreach ($customConfigFiles as $file) { $config = $this->baseDir->readFile($this->baseDir->getRelativePath($file->getFilename())); $distributedConfig .= str_replace(array('%config%', '%context%'), array($config, $file->getModule()), self::PARTIAL_CONFIG_TEMPLATE); } $fullConfig = str_replace(array('%function%', '%usages%'), array($functionDeclaration, $distributedConfig), self::FULL_CONFIG_TEMPLATE); return $fullConfig; }
/** * Get aggregated distributed configuration * * @return string */ public function getConfig() { $distributedConfig = ''; $customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME); foreach ($customConfigFiles as $file) { /** @var $fileReader \Magento\Framework\Filesystem\File\Read */ $fileReader = $this->readFactory->create($file->getFileName(), DriverPool::FILE); $config = $fileReader->readAll($file->getName()); $distributedConfig .= str_replace(['%config%', '%context%'], [$config, $file->getModule()], self::PARTIAL_CONFIG_TEMPLATE); } $fullConfig = str_replace(['%function%', '%usages%'], [$distributedConfig], self::FULL_CONFIG_TEMPLATE); if ($this->minification->isEnabled('js')) { $fullConfig = $this->minifyAdapter->minify($fullConfig); } return $fullConfig; }