示例#1
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'));
 }
示例#2
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);
 }