Exemple #1
0
 public function testWriteWithoutContext()
 {
     $this->_phraseFirstMock->expects($this->once())->method('getPhrase')->will($this->returnValue('phrase1'));
     $this->_phraseFirstMock->expects($this->once())->method('getTranslation')->will($this->returnValue('translation1'));
     $this->_phraseFirstMock->expects($this->once())->method('getContextType')->will($this->returnValue(''));
     $this->_phraseSecondMock->expects($this->once())->method('getPhrase')->will($this->returnValue('phrase2'));
     $this->_phraseSecondMock->expects($this->once())->method('getTranslation')->will($this->returnValue('translation2'));
     $this->_phraseSecondMock->expects($this->once())->method('getContextType')->will($this->returnValue('context_type2'));
     $this->_phraseSecondMock->expects($this->once())->method('getContextValueAsString')->will($this->returnValue(''));
     $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
     /** @var \Magento\Tools\I18n\Code\Dictionary\Writer\Csv $writer */
     $writer = $objectManagerHelper->getObject('Magento\\Tools\\I18n\\Code\\Dictionary\\Writer\\Csv', array('outputFilename' => $this->_testFile));
     $writer->write($this->_phraseFirstMock);
     $writer->write($this->_phraseSecondMock);
     $expected = "phrase1,translation1\nphrase2,translation2\n";
     $this->assertEquals($expected, file_get_contents($this->_testFile));
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function write(Phrase $phrase)
 {
     $fields = array($phrase->getPhrase(), $phrase->getTranslation());
     $encloseQuote = $phrase->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE;
     $fields[0] = $this->compileString($fields[0], $encloseQuote);
     $fields[1] = $this->compileString($fields[1], $encloseQuote);
     if (($contextType = $phrase->getContextType()) && ($contextValue = $phrase->getContextValueAsString())) {
         $fields[] = $contextType;
         $fields[] = $contextValue;
     }
     fputcsv($this->_fileHandler, $fields, ',', '"');
 }
Exemple #3
0
 /**
  * @param \Magento\Tools\I18n\Code\Dictionary\Phrase $phrase
  * @param array $context
  * @return string
  */
 protected function buildFilePath($phrase, $context)
 {
     $path = $this->getContext()->buildPathToLocaleDirectoryByContext($phrase->getContextType(), $context);
     return \Magento\TestFramework\Utility\Files::init()->getPathToSource() . '/' . $path . \Magento\Tools\I18n\Code\Locale::DEFAULT_SYSTEM_LOCALE . '.' . \Magento\Tools\I18n\Code\Pack\Writer\File\Csv::FILE_EXTENSION;
 }
Exemple #4
0
 public function testGetKey()
 {
     $phrase = new Phrase('phrase', 'translation', 'context_type', 'context_value1');
     $this->assertEquals('phrase::context_type', $phrase->getKey());
 }
Exemple #5
0
 /**
  * Add phrase to pack container
  *
  * @param \Magento\Tools\I18n\Code\Dictionary\Phrase $phrase
  * @return void
  */
 public function addPhrase(Phrase $phrase)
 {
     $this->_phrases[] = $phrase;
     $this->_phrasesByKey[$phrase->getKey()][] = $phrase;
 }