public function testGenerateWithNotAllowedDuplicatesAndDuplicatesExist() { $error = "Duplicated translation is found, but it is not allowed.\n" . "The phrase \"phrase1\" is translated in 1 places.\n" . "The phrase \"phrase2\" is translated in 1 places.\n"; $this->setExpectedException('\\RuntimeException', $error); $allowDuplicates = false; $phraseFirstMock = $this->getMock('Magento\\Setup\\Module\\I18n\\Dictionary\\Phrase', [], [], '', false); $phraseFirstMock->expects($this->once())->method('getPhrase')->will($this->returnValue('phrase1')); $phraseSecondMock = $this->getMock('Magento\\Setup\\Module\\I18n\\Dictionary\\Phrase', [], [], '', 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\\Setup\\Module\\I18n\\Dictionary\\Phrase', [], [], '', false)]; $this->dictionaryMock->expects($this->once())->method('getPhrases')->will($this->returnValue([$phrases])); $this->dictionaryMock->expects($this->once())->method('getDuplicates')->will($this->returnValue([[$phraseFirstMock], [$phraseSecondMock]])); $this->_generator->generate('dictionary_path', 'pack_path', 'locale', 'mode', $allowDuplicates); }
public function testLoad() { $abstractLoaderMock = $this->getMockForAbstractClass('Magento\\Setup\\Module\\I18n\\Dictionary\\Loader\\File\\AbstractFile', [$this->_factoryMock], '', true, true, true, ['_openFile', '_readFile', '_closeFile']); $abstractLoaderMock->expects($this->at(1))->method('_readFile')->will($this->returnValue(['phrase1', 'translation1'])); $abstractLoaderMock->expects($this->at(2))->method('_readFile')->will($this->returnValue(['phrase2', 'translation2', 'context_type2', 'context_value2'])); $phraseFirstMock = $this->getMock('Magento\\Setup\\Module\\I18n\\Dictionary\\Phrase', [], [], '', false); $phraseSecondMock = $this->getMock('Magento\\Setup\\Module\\I18n\\Dictionary\\Phrase', [], [], '', false); $this->_factoryMock->expects($this->once())->method('createDictionary')->will($this->returnValue($this->_dictionaryMock)); $this->_factoryMock->expects($this->at(1))->method('createPhrase')->with(['phrase' => 'phrase1', 'translation' => 'translation1', 'context_type' => '', 'context_value' => ''])->will($this->returnValue($phraseFirstMock)); $this->_factoryMock->expects($this->at(2))->method('createPhrase')->with(['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\Setup\Module\I18n\Dictionary\Loader\File\AbstractFile $abstractLoaderMock */ $this->assertEquals($this->_dictionaryMock, $abstractLoaderMock->load('test.csv')); }