Ejemplo n.º 1
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Invalid row #1: "exception_message".
  */
 public function testErrorsInPhraseCreating()
 {
     $abstractLoaderMock = $this->getMockForAbstractClass('Magento\\Tools\\I18n\\Dictionary\\Loader\\File\\AbstractFile', [$this->_factoryMock], '', true, true, true, ['_openFile', '_readFile']);
     $abstractLoaderMock->expects($this->at(1))->method('_readFile')->will($this->returnValue(['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\Dictionary\Loader\File\AbstractFile $abstractLoaderMock */
     $this->assertEquals($this->_dictionaryMock, $abstractLoaderMock->load('test.csv'));
 }
Ejemplo n.º 2
0
 /**
  * @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\\Locale', [], [], '', 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);
 }
Ejemplo n.º 3
0
 /**
  * Generate language pack
  *
  * @param string $dictionaryPath
  * @param string $packPath
  * @param string $locale
  * @param string $mode One of const of WriterInterface::MODE_
  * @param bool $allowDuplicates
  * @return void
  * @throws \RuntimeException
  */
 public function generate($dictionaryPath, $packPath, $locale, $mode = WriterInterface::MODE_REPLACE, $allowDuplicates = false)
 {
     $locale = $this->factory->createLocale($locale);
     $dictionary = $this->dictionaryLoader->load($dictionaryPath);
     if (!count($dictionary->getPhrases())) {
         throw new \UnexpectedValueException('No phrases have been found by the specified path.');
     }
     if (!$allowDuplicates && ($duplicates = $dictionary->getDuplicates())) {
         throw new \RuntimeException("Duplicated translation is found, but it is not allowed.\n" . $this->createDuplicatesPhrasesError($duplicates));
     }
     $this->packWriter->write($dictionary, $packPath, $locale, $mode);
 }
Ejemplo n.º 4
0
 /**
  * @param string $outputFilename
  * @return WriterInterface
  */
 protected function getDictionaryWriter($outputFilename)
 {
     if (null === $this->writer) {
         $this->writer = $this->factory->createDictionaryWriter($outputFilename);
     }
     return $this->writer;
 }
Ejemplo n.º 5
0
 /**
  * @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);
 }
Ejemplo n.º 6
0
 /**
  * Create phrase
  *
  * @param array $data
  * @return \Magento\Tools\I18n\Dictionary\Phrase
  * @throws \RuntimeException
  */
 protected function _createPhrase($data)
 {
     try {
         return $this->_factory->createPhrase($data);
     } catch (\DomainException $e) {
         throw new \RuntimeException(sprintf('Invalid row #%d: "%s".', $this->_position, $e->getMessage()) . "\n" . 'Each row has to consist of 3 columns: original phrase, translation, context');
     }
 }
Ejemplo n.º 7
0
 public function testUsingRightParserWhileWithContextParsing()
 {
     $baseDir = 'right_parser2';
     $outputFilename = 'file.csv';
     $filesOptions = ['file1', 'file2'];
     $optionResolver = $this->getMock('Magento\\Tools\\I18n\\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\\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);
 }
Ejemplo n.º 8
0
 /**
  * @param string $expectedInstance
  * @param string $fileName
  * @dataProvider createDictionaryWriterDataProvider
  */
 public function testCreateDictionaryWriter($expectedInstance, $fileName)
 {
     $this->assertInstanceOf($expectedInstance, $this->factory->createDictionaryWriter($fileName));
 }