public function testGetDictionary() { $dir = ['Foo/en_AU/language.xml', 'Bar/en_GB/language.xml', 'Baz/en_GB/language.xml', 'Bar/en_US/language.xml']; $xmlMap = [[$dir[0], null, null, '<?xml version="1.0"?> <language> <code>en_AU</code> <vendor>Foo</vendor> <use vendor="Bar" code="en_GB"/> <use vendor="Baz" code="en_GB"/> </language>'], [$dir[1], null, null, '<?xml version="1.0"?> <language> <code>en_GB</code> <vendor>Bar</vendor> <sort_order>100</sort_order> <use vendor="Bar" code="en_US"/> </language>'], [$dir[2], null, null, '<?xml version="1.0"?> <language> <code>en_GB</code> <vendor>Baz</vendor> <sort_order>50</sort_order> </language>'], [$dir[3], null, null, '<?xml version="1.0"?> <language> <code>en_US</code> <vendor>Bar</vendor> </language>']]; $csvMap = [['Bar/en_US/*.csv', null, ['Bar/en_US/b.csv', 'Bar/en_US/a.csv']], ['Baz/en_GB/*.csv', null, ['Baz/en_GB/1.csv']], ['Bar/en_GB/*.csv', null, ['Bar/en_GB/1.csv']], ['Foo/en_AU/*.csv', null, ['Foo/en_AU/1.csv', 'Foo/en_AU/2.csv']]]; $dictionaryMap = [['Bar/en_US/a.csv', $this->getCsvMock([['one', '1'], ['two', '2']])], ['Bar/en_US/b.csv', $this->getCsvMock([['three', '3'], ['four', '4']])], ['Baz/en_GB/1.csv', $this->getCsvMock([['four and 5/10', '4.5']])], ['Bar/en_GB/1.csv', $this->getCsvMock([['four and 75/100', '4.75'], ['four and 5/10', '4.50']])], ['Foo/en_AU/1.csv', $this->getCsvMock([['one', '1.0'], ['five', '5.0']])], ['Foo/en_AU/2.csv', $this->getCsvMock([['six', '6.0']])]]; $this->dir->expects($this->any())->method('search')->will($this->returnValueMap(array_merge([['*/*/language.xml', null, $dir]], $csvMap))); $this->dir->expects($this->any())->method('readFile')->will($this->returnValueMap($xmlMap)); $this->dir->expects($this->any())->method('openFile')->will($this->returnValueMap($dictionaryMap)); $result = $this->model->getDictionary('en_AU'); $this->assertSame(['one' => '1.0', 'two' => '2', 'three' => '3', 'four' => '4', 'four and 5/10' => '4.50', 'four and 75/100' => '4.75', 'five' => '5.0', 'six' => '6.0'], $result); }
public function testDictionaryGetter() { $csvFileName = 'abc.csv'; $data = [['one', '1'], ['two', '2']]; $expected = []; foreach ($data as $item) { $expected[$item[0]] = $item[1]; } $file = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\File\\ReadInterface'); for ($i = 0; $i < count($data); $i++) { $file->expects($this->at($i))->method('readCsv')->will($this->returnValue($data[$i])); } $file->expects($this->at($i))->method('readCsv')->will($this->returnValue(false)); $readMock = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $readMock->expects($this->any())->method('readFile')->willReturnMap([['language.xml', $readMock], [$csvFileName, $file]]); $readMock->expects($this->any())->method('openFile')->willReturn($file); $readMock->expects($this->any())->method('isExist')->willReturn(true); $readMock->expects($this->any())->method('search')->willReturn([$csvFileName]); $this->componentRegistrar->expects($this->once())->method('getPaths')->willReturn(['foo/en_us']); $this->componentRegistrar->expects($this->once())->method('getPath')->willReturn('foo/en_us'); $this->readFactory->expects($this->any())->method("create")->willReturn($readMock); $languageConfig = $this->getMock('\\Magento\\Framework\\App\\Language\\Config', [], [], '', false); $languageConfig->expects($this->any())->method('getCode')->will($this->returnValue('en_US')); $languageConfig->expects($this->any())->method('getVendor')->will($this->returnValue('foo')); $languageConfig->expects($this->any())->method('getPackage')->will($this->returnValue('en_us')); $languageConfig->expects($this->any())->method('getSortOrder')->will($this->returnValue(0)); $languageConfig->expects($this->any())->method('getUses')->will($this->returnValue([])); $this->configFactory->expects($this->any())->method('create')->willReturn($languageConfig); $result = $this->model->getDictionary("en_US"); $this->assertSame($expected, $result); }
/** * @param string $file * @param string $expectedVendor * @param string $expectedCode * @dataProvider declaredConsistentlyDataProvider */ public function testDeclaredConsistently($file, $expectedVendor, $expectedCode) { $dom = new \DOMDocument(); $dom->load($file); $root = $dom->documentElement; \Magento\Framework\App\Language\Dictionary::assertVendor($expectedVendor, $root); \Magento\Framework\App\Language\Dictionary::assertCode($expectedCode, $root); }
public function testLoadDataNoTheme() { $forceReload = true; $this->expectsSetConfig(null, null); $this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue([])); $this->appState->expects($this->once())->method('getAreaCode')->will($this->returnValue('frontend')); $this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue([])); $this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue([])); $this->assertEquals($this->translate, $this->translate->loadData(null, $forceReload)); }
/** * @param array $languagesData * @param array $csvMap * @param array $dictionaryMap * @param $languageCode * @param array $expectation * @dataProvider dictionaryDataProvider */ public function testDictionaryGetter($languagesData, $csvMap, $dictionaryMap, $languageCode, $expectation) { $languagePaths = array_keys($languagesData); $this->dir->expects($this->any())->method('search')->will($this->returnValueMap(array_merge([['*/*/language.xml', null, $languagePaths]], $csvMap))); // Return first argument to mark content for configuration factory mock $this->dir->expects($this->any())->method('readFile')->will($this->returnArgument(0)); $configCallback = $this->returnCallback(function ($arguments) use($languagesData) { return $this->getLanguageConfigMock($languagesData[$arguments['source']]); }); $this->configFactory->expects($this->any())->method('create')->will($configCallback); // Covers data from dataProvider $dictionaryMap = array_map(function ($data) { list($path, $result) = $data; return [$path, $this->getCsvMock($result)]; }, $dictionaryMap); $this->dir->expects($this->any())->method('openFile')->will($this->returnValueMap($dictionaryMap)); $result = $this->model->getDictionary($languageCode); $this->assertSame($expectation, $result); }
/** * Load translation dictionary from language packages * * @return void */ protected function _loadPackTranslation() { $data = $this->packDictionary->getDictionary($this->getLocale()); $this->_addData($data); }
/** * @param string $languageCode * @param array $expectation * @dataProvider dictionaryDataProvider * @magentoComponentsDir Magento/Framework/App/Language/_files */ public function testDictionaryGetter($languageCode, $expectation) { $this->model = $this->objectManager->create('Magento\\Framework\\App\\Language\\Dictionary', ['directoryReadFactory' => $this->directoryFactory, 'configFactory' => $this->configFactory]); $result = $this->model->getDictionary($languageCode); $this->assertSame($expectation, $result); }
/** * Load translation dictionary from language packages * * @param bool $forceReload * @return void */ protected function _loadPackTranslation($forceReload = false) { $data = $this->packDictionary->getDictionary($this->getLocale()); $this->_addData($data, 'language_pack', $forceReload); }