Example #1
0
 public function testGetDuplicates()
 {
     $phraseFirstMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $phraseFirstMock->expects($this->once())->method('getKey')->will($this->returnValue('key_1'));
     $phraseSecondMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $phraseSecondMock->expects($this->once())->method('getKey')->will($this->returnValue('key_1'));
     $phraseThirdMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $phraseThirdMock->expects($this->once())->method('getKey')->will($this->returnValue('key_3'));
     $this->_dictionary->addPhrase($phraseFirstMock);
     $this->_dictionary->addPhrase($phraseSecondMock);
     $this->_dictionary->addPhrase($phraseThirdMock);
     $this->assertEquals(array(array($phraseFirstMock, $phraseSecondMock)), $this->_dictionary->getDuplicates());
 }
Example #2
0
 public function testLoad()
 {
     $abstractLoaderMock = $this->getMockForAbstractClass('Magento\\Tools\\I18n\\Code\\Dictionary\\Loader\\File\\AbstractFile', array($this->_factoryMock), '', true, true, true, array('_openFile', '_readFile', '_closeFile'));
     $abstractLoaderMock->expects($this->at(1))->method('_readFile')->will($this->returnValue(array('phrase1', 'translation1')));
     $abstractLoaderMock->expects($this->at(2))->method('_readFile')->will($this->returnValue(array('phrase2', 'translation2', 'context_type2', 'context_value2')));
     $phraseFirstMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $phraseSecondMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $this->_factoryMock->expects($this->once())->method('createDictionary')->will($this->returnValue($this->_dictionaryMock));
     $this->_factoryMock->expects($this->at(1))->method('createPhrase')->with(array('phrase' => 'phrase1', 'translation' => 'translation1', 'context_type' => '', 'context_value' => ''))->will($this->returnValue($phraseFirstMock));
     $this->_factoryMock->expects($this->at(2))->method('createPhrase')->with(array('phrase' => 'phrase2', 'translation' => 'translation2', 'context_type' => 'context_type2', 'context_value' => 'context_value2'))->will($this->returnValue($phraseSecondMock));
     $this->_dictionaryMock->expects($this->at(0))->method('addPhrase')->with($phraseFirstMock);
     $this->_dictionaryMock->expects($this->at(1))->method('addPhrase')->with($phraseSecondMock);
     /** @var \Magento\Tools\I18n\Code\Dictionary\Loader\File\AbstractFile $abstractLoaderMock */
     $this->assertEquals($this->_dictionaryMock, $abstractLoaderMock->load('test.csv'));
 }
Example #3
0
 public function testGenerateWithNotAllowedDuplicatesAndDuplicatesExist()
 {
     $error = "Duplicated translation is found, but it is not allowed.\n" . "The phrase \"phrase1\" is translated differently in 1 places.\n" . "The phrase \"phrase2\" is translated differently in 1 places.\n";
     $this->setExpectedException('\\RuntimeException', $error);
     $allowDuplicates = false;
     $phraseFirstMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $phraseFirstMock->expects($this->once())->method('getPhrase')->will($this->returnValue('phrase1'));
     $phraseSecondMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $phraseSecondMock->expects($this->once())->method('getPhrase')->will($this->returnValue('phrase2'));
     $this->dictionaryLoaderMock->expects($this->any())->method('load')->will($this->returnValue($this->dictionaryMock));
     $phrases = [$this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', [], [], '', false)];
     $this->dictionaryMock->expects($this->once())->method('getPhrases')->will($this->returnValue([$phrases]));
     $this->dictionaryMock->expects($this->once())->method('getDuplicates')->will($this->returnValue(array(array($phraseFirstMock), array($phraseSecondMock))));
     $this->_generator->generate('dictionary_path', 'pack_path', 'locale', 'mode', $allowDuplicates);
 }
Example #4
0
 /**
  * Build pack files data
  *
  * @param Dictionary $dictionary
  * @return array
  * @throws \RuntimeException
  */
 protected function _buildPackFilesData(Dictionary $dictionary)
 {
     $files = array();
     foreach ($dictionary->getPhrases() as $key => $phrase) {
         if (!$phrase->getContextType() || !$phrase->getContextValue()) {
             throw new \RuntimeException(sprintf('Missed context in row #%d.', $key + 1) . "\n" . 'Each row has to consist of 3 columns: original phrase, translation, context');
         }
         foreach ($phrase->getContextValue() as $context) {
             try {
                 $path = $this->_context->buildPathToLocaleDirectoryByContext($phrase->getContextType(), $context);
             } catch (\InvalidArgumentException $e) {
                 throw new \InvalidArgumentException($e->getMessage() . ' Row #' . ($key + 1) . '.');
             }
             $filename = $this->_packPath . $path . $this->_locale . '.' . $this->_getFileExtension();
             $files[$filename][$phrase->getPhrase()] = $phrase;
         }
     }
     return $files;
 }