コード例 #1
0
 /**
  * Make sure the aggregated configuration is materialized
  *
  * By default write the file if it doesn't exist, but in developer mode always do it.
  *
  * @param string $relPath
  * @return void
  */
 private function ensureSourceFile($relPath)
 {
     $dir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     if ($this->appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER || !$dir->isExist($relPath)) {
         $dir->writeFile($relPath, $this->config->getConfig());
     }
 }
コード例 #2
0
 public function testCreateRequireJsAssetDevMode()
 {
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
     $this->dir->expects($this->never())->method('isExist');
     $data = 'requirejs config data';
     $this->config->expects($this->once())->method('getConfig')->will($this->returnValue($data));
     $this->dir->expects($this->once())->method('writeFile')->with('requirejs/file.js', $data);
     $this->assertSame($this->asset, $this->object->createRequireJsAsset());
 }
コード例 #3
0
 public function testCreateRequireJsAssetDevMode()
 {
     $this->config->expects($this->once())->method('getConfigFileRelativePath')->will($this->returnValue('requirejs/file.js'));
     $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir));
     $this->assetRepo->expects($this->once())->method('createArbitrary')->with('requirejs/file.js', '')->will($this->returnValue($this->asset));
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
     $this->dir->expects($this->never())->method('isExist');
     $data = 'requirejs config data';
     $this->config->expects($this->once())->method('getConfig')->will($this->returnValue($data));
     $this->dir->expects($this->once())->method('writeFile')->with('requirejs/file.js', $data);
     $this->assertSame($this->asset, $this->object->createRequireJsConfigAsset());
 }
コード例 #4
0
    public function testToHtml()
    {
        $this->context->expects($this->once())->method('getEventManager')->will($this->returnValue($this->getMockForAbstractClass('\\Magento\\Framework\\Event\\ManagerInterface')));
        $this->context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($this->getMockForAbstractClass('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface')));
        $this->config->expects($this->once())->method('getBaseConfig')->will($this->returnValue('the config data'));
        $object = new Config($this->context, $this->config, $this->fileManager, $this->pageConfig);
        $html = $object->toHtml();
        $expectedFormat = <<<expected
<script type="text/javascript">
the config data</script>
expected;
        $this->assertStringMatchesFormat($expectedFormat, $html);
    }
コード例 #5
0
 /**
  * Make sure the '.min' assets resolver is materialized
  *
  * @param string $relPath
  * @return void
  */
 private function ensureMinResolverFile($relPath)
 {
     $dir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     if ($this->appState->getMode() == AppState::MODE_DEVELOPER || !$dir->isExist($relPath)) {
         $dir->writeFile($relPath, $this->config->getMinResolverCode());
     }
 }
コード例 #6
0
 public function testCreateRequireJsMixinsAsset()
 {
     $path = 'relative path';
     $this->configMock->expects($this->once())->method('getMixinsFileRelativePath')->will($this->returnValue($path));
     $this->assetRepoMock->expects($this->once())->method('createArbitrary')->with($path, '')->willReturn($this->asset);
     $this->assertSame($this->asset, $this->object->createRequireJsMixinsAsset());
 }
コード例 #7
0
ファイル: FileManagerTest.php プロジェクト: Coplex/magento2
 public function testCreateMinResolverAsset()
 {
     $this->configMock->expects($this->any())->method('getMinResolverRelativePath')->willReturn('relative path');
     $this->assetRepoMock->expects($this->once())->method('createArbitrary')->with('relative path');
     $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir));
     $this->object->createMinResolverAsset();
 }
コード例 #8
0
    public function testGetBaseConfig()
    {
        $this->context->expects($this->once())->method('getPath')->will($this->returnValue('area/theme/locale'));
        $this->context->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://base.url/'));
        $expected = <<<expected
require.config({"baseUrl":"http://base.url/area/theme/locale"});
expected;
        $actual = $this->object->getBaseConfig();
        $this->assertSame($expected, $actual);
    }
コード例 #9
0
 /**
  * Include base RequireJs configuration necessary for working with Magento application
  *
  * @return string|void
  */
 protected function _toHtml()
 {
     return "<script type=\"text/javascript\">\n" . $this->config->getBaseConfig() . "</script>\n";
 }