/**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Invalid row #1: "exception_message".
  */
 public function testErrorsInPhraseCreating()
 {
     $abstractLoaderMock = $this->getMockForAbstractClass('Magento\\Setup\\Module\\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\Setup\Module\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';
     $localeString = 'locale';
     $mode = 'mode';
     $allowDuplicates = true;
     $localeMock = $this->getMock('Magento\\Setup\\Module\\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, $localeString, $mode, $allowDuplicates);
 }
Ejemplo n.º 3
0
 /**
  * Generate language pack
  *
  * @param string $dictionaryPath
  * @param string $locale
  * @param string $mode One of const of WriterInterface::MODE_
  * @param bool $allowDuplicates
  * @return void
  * @throws \RuntimeException
  */
 public function generate($dictionaryPath, $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->writeDictionary($dictionary, $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
 /**
  * Create phrase
  *
  * @param array $data
  * @return \Magento\Setup\Module\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.º 6
0
 /**
  * @param array $options
  * @param array $phpFiles
  * @param array $jsFiles
  * @param array $phpMap
  * @param array $jsMap
  * @paran array $phraseFactoryMap
  * @param array $expectedResult
  * @dataProvider addPhraseDataProvider
  */
 public function testAddPhrase($options, $phpFiles, $jsFiles, $phpMap, $jsMap, $phraseFactoryMap, $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()->willReturnMap($phraseFactoryMap);
     //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.º 7
0
 public function testUsingRightParserWhileWithContextParsing()
 {
     $baseDir = 'right_parser2';
     $outputFilename = 'file.csv';
     $filesOptions = ['file1', 'file2'];
     $optionResolver = $this->getMock('Magento\\Setup\\Module\\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\\Setup\\Module\\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));
 }