/** * Resolver get template file name test * * @return void */ public function testGetTemplateFileName() { $template = 'template.phtml'; $this->_viewFileSystemMock->expects($this->once())->method('getTemplateFileName')->with($template)->will($this->returnValue('path_to' . $template)); $this->assertEquals('path_to' . $template, $this->_resolver->getTemplateFileName($template)); $this->assertEquals('path_to' . $template, $this->_resolver->getTemplateFileName($template)); }
public function testRender() { $template = 'test_template'; $result = 'result'; $path = 'path'; $this->viewInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Element\\UiComponentInterface'); $templateEngineMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\TemplateEngineInterface'); $this->templateEnginePoolMock->expects($this->once())->method('get')->willReturn($templateEngineMock); $this->filesystemMock->expects($this->once())->method('getTemplateFileName')->with($template)->willReturn($path); $templateEngineMock->expects($this->once())->method('render')->with($this->viewInterfaceMock, $path)->willReturn($result); $this->assertEquals($result, $this->html->render($this->viewInterfaceMock, $template)); }
/** * @param string $area * @param bool $forceReload * @param array $cachedData * @dataProvider dataProviderForTestLoadData * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testLoadData($area, $forceReload, $cachedData) { $this->expectsSetConfig('themeId'); $this->cache->expects($this->exactly($forceReload ? 0 : 1))->method('load')->will($this->returnValue(serialize($cachedData))); if (!$forceReload && $cachedData !== false) { $this->translate->loadData($area, $forceReload); $this->assertEquals($cachedData, $this->translate->getData()); return; } $this->directory->expects($this->any())->method('isExist')->will($this->returnValue(true)); // _loadModuleTranslation() $this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue(['name'])); $moduleData = ['module original' => 'module translated', 'module theme' => 'module-theme original translated', 'module pack' => 'module-pack original translated', 'module db' => 'module-db original translated']; $this->modulesReader->expects($this->any())->method('getModuleDir')->will($this->returnValue('/app/module')); $themeData = ['theme original' => 'theme translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'theme-pack translated overwrite', 'module db' => 'theme-db translated overwrite']; $this->csvParser->expects($this->any())->method('getDataPairs')->will($this->returnValueMap([['/app/module/en_US.csv', 0, 1, $moduleData], ['/app/module/en_GB.csv', 0, 1, $moduleData], ['/theme.csv', 0, 1, $themeData]])); // _loadThemeTranslation() $this->viewFileSystem->expects($this->any())->method('getLocaleFileName')->will($this->returnValue('/theme.csv')); // _loadPackTranslation $packData = ['pack original' => 'pack translated', 'module pack' => 'pack translated overwrite', 'module db' => 'pack-db translated overwrite']; $this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue($packData)); // _loadDbTranslation() $dbData = ['db original' => 'db translated', 'module db' => 'db translated overwrite']; $this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue($dbData)); $this->cache->expects($this->exactly(1))->method('save'); $this->translate->loadData($area, $forceReload); $expected = ['module original' => 'module translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'pack translated overwrite', 'module db' => 'db translated overwrite', 'theme original' => 'theme translated', 'pack original' => 'pack translated', 'db original' => 'db translated']; $this->assertEquals($expected, $this->translate->getData()); }
public function testGetWidgetSupportedTemplatesByContainersUnknownContainer() { $expectedConfigFile = __DIR__ . '/../_files/mappedConfigArray1.php'; $widget = (include $expectedConfigFile); $this->_widgetModelMock->expects($this->once())->method('getWidgetByClassType')->will($this->returnValue($widget)); $this->_viewFileSystemMock->expects($this->once())->method('getFilename')->will($this->returnValue('')); $expectedTemplates = []; $this->assertEquals($expectedTemplates, $this->_model->getWidgetSupportedTemplatesByContainer('unknown')); }
public function testToHtmlWithoutRatingData() { $this->registry->expects($this->any())->method('registry')->will($this->returnValue(false)); $this->systemStore->expects($this->any())->method('getStoreCollection')->will($this->returnValue(['0' => $this->store])); $this->formFactory->expects($this->any())->method('create')->will($this->returnValue($this->form)); $this->viewFileSystem->expects($this->any())->method('getTemplateFileName')->will($this->returnValue('template_file_name.html')); $this->fileSystem->expects($this->any())->method('getDirectoryRead')->will($this->returnValue($this->directoryReadInterface)); $this->block->toHtml(); }
public function testGetViewConfig() { $themeMock = $this->getMock('Magento\\Theme\\Model\\Theme', ['getId', 'getCustomization', 'getCustomViewConfigPath'], [], '', false); $themeMock->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(2)); $themeMock->expects($this->once())->method('getCustomization')->will($this->returnSelf()); $themeMock->expects($this->once())->method('getCustomViewConfigPath')->will($this->returnValue('')); $params = ['themeModel' => $themeMock]; $configFile = 'config.xml'; $this->repositoryMock->expects($this->atLeastOnce())->method('updateDesignParams')->with($this->equalTo($params))->will($this->returnSelf()); $iterator = $this->getMock('Magento\\Framework\\Config\\FileIterator', [], [], '', false); $iterator->expects($this->once())->method('toArray')->will($this->returnValue([])); $this->readerMock->expects($this->once())->method('getConfigurationFiles')->with($this->equalTo(basename(\Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME)))->will($this->returnValue($iterator)); $this->directoryReadMock->expects($this->once())->method('isExist')->with($this->anything())->will($this->returnValue(true)); $this->fileSystemMock->expects($this->once())->method('getFilename')->with($this->equalTo(\Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME), $params)->will($this->returnValue($configFile)); $this->directoryReadMock->expects($this->any())->method('getRelativePath')->with($this->equalTo($configFile))->will($this->returnArgument(0)); $xmlData = '<view><vars module="Magento_Catalog"><var name="test">1</var></vars></view>'; $this->directoryReadMock->expects($this->once())->method('readFile')->with($this->equalTo($configFile))->will($this->returnValue($xmlData)); $this->assertInstanceOf('Magento\\Framework\\Config\\View', $this->config->getViewConfig($params)); // lazy load test $this->assertInstanceOf('Magento\\Framework\\Config\\View', $this->config->getViewConfig($params)); }
protected function setUp() { $this->_viewFileSystem = $this->getMock('Magento\\Framework\\View\\FileSystem', array('getLocaleFileName', 'getDesignTheme'), array(), '', false); $this->_viewFileSystem->expects($this->any())->method('getLocaleFileName')->will($this->returnValue(dirname(__DIR__) . '/Core/Model/_files/design/frontend/test_default/i18n/en_US.csv')); $theme = $this->getMock('\\Magento\\Framework\\View\\Design\\ThemeInterface', array()); $theme->expects($this->any())->method('getId')->will($this->returnValue(10)); $this->_viewFileSystem->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme)); $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->addSharedInstance($this->_viewFileSystem, 'Magento\\Framework\\View\\FileSystem'); /** @var $moduleReader \Magento\Framework\Module\Dir\Reader */ $moduleReader = $objectManager->get('Magento\\Framework\\Module\\Dir\\Reader'); $moduleReader->setModuleDir('Magento_Core', 'i18n', dirname(__DIR__) . '/Core/Model/_files/Magento/Core/i18n'); $moduleReader->setModuleDir('Magento_Catalog', 'i18n', dirname(__DIR__) . '/Core/Model/_files/Magento/Catalog/i18n'); /** @var \Magento\Core\Model\View\Design _designModel */ $this->_designModel = $this->getMock('Magento\\Core\\Model\\View\\Design', array('getDesignTheme'), array($objectManager->get('Magento\\Framework\\StoreManagerInterface'), $objectManager->get('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory'), $objectManager->get('Magento\\Framework\\App\\Config\\ScopeConfigInterface'), $objectManager->get('Magento\\Core\\Model\\ThemeFactory'), $objectManager->get('Magento\\Framework\\Locale\\ResolverInterface'), $objectManager->get('Magento\\Framework\\App\\State'), array('frontend' => 'test_default'))); $this->_designModel->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme)); $objectManager->addSharedInstance($this->_designModel, 'Magento\\Core\\Model\\View\\Design\\Proxy'); $this->_model = $objectManager->create('Magento\\Framework\\Translate'); $objectManager->addSharedInstance($this->_model, 'Magento\\Framework\\Translate'); $objectManager->removeSharedInstance('Magento\\Framework\\Phrase\\Renderer\\Composite'); $objectManager->removeSharedInstance('Magento\\Framework\\Phrase\\Renderer\\Translate'); \Magento\Framework\Phrase::setRenderer($objectManager->get('Magento\\Framework\\Phrase\\RendererInterface')); $this->_model->loadData(\Magento\Framework\App\Area::AREA_FRONTEND); }
/** * Ensure that the getTemplateFilename method can be called without design params */ public function testGetTemplateFilenameWithNoParams() { $this->viewFileSystem->expects($this->once())->method('getEmailTemplateFileName')->with('one.html', ['area' => $this->designParams['area'], 'module' => $this->designParams['module']], 'Fixture_ModuleOne')->will($this->returnValue('_files/Fixture/ModuleOne/view/frontend/email/one.html')); $actualResult = $this->model->getTemplateFilename('template_one'); $this->assertEquals('_files/Fixture/ModuleOne/view/frontend/email/one.html', $actualResult); }
public function testGetTemplateFile() { $params = array('module' => 'Fixture_Module', 'area' => 'frontend'); $this->_viewFileSystem->expects($this->once())->method('getTemplateFileName')->with('template.phtml', $params); $this->_block->getTemplateFile(); }