/** * @expectedException \RuntimeException * @expectedExceptionMessage Invalid row #1: "exception_message". */ public function testErrorsInPhraseCreating() { $abstractLoaderMock = $this->getMockForAbstractClass('Magento\\Tools\\I18n\\Code\\Dictionary\\Loader\\File\\AbstractFile', array($this->_factoryMock), '', true, true, true, array('_openFile', '_readFile')); $abstractLoaderMock->expects($this->at(1))->method('_readFile')->will($this->returnValue(array('phrase1', 'translation1'))); $this->_factoryMock->expects($this->once())->method('createDictionary')->will($this->returnValue($this->_dictionaryMock)); $this->_factoryMock->expects($this->at(1))->method('createPhrase')->will($this->throwException(new \DomainException('exception_message'))); /** @var \Magento\Tools\I18n\Code\Dictionary\Loader\File\AbstractFile $abstractLoaderMock */ $this->assertEquals($this->_dictionaryMock, $abstractLoaderMock->load('test.csv')); }
/** * @param array $options * @param array $phpFiles * @param array $jsFiles * @param array $phpMap * @param array $jsMap * @param array $expectedResult * @dataProvider addPhraseDataProvider */ public function testAddPhrase($options, $phpFiles, $jsFiles, $phpMap, $jsMap, $expectedResult) { // 1. Create mocks $phpAdapter = new AdapterStub(); $jsAdapter = new AdapterStub(); // 2. Set mocks $this->parser->addAdapter('php', $phpAdapter); $this->parser->addAdapter('js', $jsAdapter); //3. Set fixtures $phpAdapter->setValueMap($phpMap); $jsAdapter->setValueMap($jsMap); $this->factory->expects($this->any())->method('createPhrase')->with()->will($this->returnValueMap([[['phrase' => 'php phrase111', 'translation' => 'php phrase111', 'quote' => "'"], 'php phrase111'], [['phrase' => 'php phrase112', 'translation' => 'php phrase112', 'quote' => '"'], 'php phrase112'], [['phrase' => 'php phrase121', 'translation' => 'php phrase121', 'quote' => "'"], 'php phrase121'], [['phrase' => 'php phrase122', 'translation' => 'php phrase122', 'quote' => '"'], 'php phrase122'], [['phrase' => 'js phrase111', 'translation' => 'js phrase111', 'quote' => "'"], 'js phrase111'], [['phrase' => 'js phrase112', 'translation' => 'js phrase112', 'quote' => '"'], 'js phrase112'], [['phrase' => 'js phrase121', 'translation' => 'js phrase121', 'quote' => "'"], 'js phrase121'], [['phrase' => 'js phrase122', 'translation' => 'js phrase122', 'quote' => '"'], 'js phrase122']])); //4. Set expectations $this->filesCollector->expects($this->any())->method('getFiles')->will($this->returnValueMap([[$options[0]['paths'], '', $phpFiles], [$options[1]['paths'], '', $jsFiles]])); $result = $this->parser->parse($options); $this->assertEquals($expectedResult, $result); }
/** * @expectedExceptionMessage No phrases have been found by the specified path. * @expectedException \UnexpectedValueException */ public function testGenerateEmptyFile() { $dictionaryPath = 'dictionary_path'; $packPath = 'pack_path'; $localeString = 'locale'; $mode = 'mode'; $allowDuplicates = true; $localeMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Locale', array(), array(), '', false); $this->factoryMock->expects($this->once())->method('createLocale')->with($localeString)->will($this->returnValue($localeMock)); $this->dictionaryLoaderMock->expects($this->once())->method('load')->with($dictionaryPath)->will($this->returnValue($this->dictionaryMock)); $this->_generator->generate($dictionaryPath, $packPath, $localeString, $mode, $allowDuplicates); }
public function testUsingRightParserWhileWithContextParsing() { $baseDir = 'right_parser2'; $outputFilename = 'file.csv'; $filesOptions = array('file1', 'file2'); $optionResolver = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Options\\Resolver', [], [], '', false); $optionResolver->expects($this->once())->method('getOptions')->will($this->returnValue($filesOptions)); $this->optionsResolverFactory->expects($this->once())->method('create')->with($this->equalTo($baseDir), $this->equalTo(true))->will($this->returnValue($optionResolver)); $this->contextualParserMock->expects($this->once())->method('parse')->with($filesOptions); $phrase = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', [], [], '', false); $this->contextualParserMock->expects($this->once())->method('getPhrases')->will($this->returnValue([$phrase])); $this->factoryMock->expects($this->once())->method('createDictionaryWriter')->with($outputFilename)->will($this->returnSelf()); $this->generator->generate($baseDir, $outputFilename, true); }