Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function _parse()
 {
     $this->_phraseCollector->parse($this->_file);
     foreach ($this->_phraseCollector->getPhrases() as $phrase) {
         $this->_addPhrase($phrase['phrase'], $phrase['line']);
     }
 }
 /**
  * @covers \Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector::parse
  */
 public function testParse()
 {
     $file = __DIR__ . '/_files/objectsCode.php.txt';
     $this->phraseCollector->setIncludeObjects();
     $this->phraseCollector->parse($file);
     $expectation = [['phrase' => '\'Testing\'', 'arguments' => 0, 'file' => $file, 'line' => 3], ['phrase' => '\'More testing\'', 'arguments' => 0, 'file' => $file, 'line' => 4]];
     $this->assertEquals($expectation, $this->phraseCollector->getPhrases());
 }
Exemplo n.º 3
0
 /**
  * Returns an array of phrases that can be used by JS files.
  *
  * @return string[]
  */
 protected function _getRegisteredPhrases()
 {
     $jsHelperFile = realpath(__DIR__ . '/../../../../../../../../app/code/Magento/Translation/Model/Js/DataProvider.php');
     $this->_phraseCollector->parse($jsHelperFile);
     $result = [];
     foreach ($this->_phraseCollector->getPhrases() as $phrase) {
         $result[] = stripcslashes(trim($phrase['phrase'], "'"));
     }
     return $result;
 }
 /**
  * @covers \Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector::parse
  *
  * @param string $file
  * @param array $isEndOfLoopReturnValues
  * @param array $getNextRealTokenReturnValues
  * @param array $getFunctionArgumentsTokensReturnValues
  * @param array $isMatchingClassReturnValues
  * @param array $result
  * @dataProvider testParseDataProvider
  */
 public function testParse($file, array $isEndOfLoopReturnValues, array $getNextRealTokenReturnValues, array $getFunctionArgumentsTokensReturnValues, array $isMatchingClassReturnValues, array $result)
 {
     $matchingClass = 'Phrase';
     $this->tokenizerMock->expects($this->once())->method('parse')->with($file);
     $this->tokenizerMock->expects($this->atLeastOnce())->method('isEndOfLoop')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $isEndOfLoopReturnValues));
     $this->tokenizerMock->expects($this->any())->method('getNextRealToken')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $getNextRealTokenReturnValues));
     $this->tokenizerMock->expects($this->any())->method('getFunctionArgumentsTokens')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $getFunctionArgumentsTokensReturnValues));
     $this->tokenizerMock->expects($this->any())->method('isMatchingClass')->with($matchingClass)->will(call_user_func_array([$this, 'onConsecutiveCalls'], $isMatchingClassReturnValues));
     $this->phraseCollector->setIncludeObjects();
     $this->phraseCollector->parse($file);
     $this->assertEquals($result, $this->phraseCollector->getPhrases());
 }
Exemplo n.º 5
0
 public function testArguments()
 {
     $errors = [];
     foreach ($this->_getFiles() as $file) {
         if (in_array($file, $this->blackList)) {
             continue;
         }
         $this->_phraseCollector->parse($file);
         foreach ($this->_phraseCollector->getPhrases() as $phrase) {
             if (preg_match_all('/%(\\d+)/', $phrase['phrase'], $matches) || $phrase['arguments']) {
                 $placeholdersInPhrase = array_unique($matches[1]);
                 if (count($placeholdersInPhrase) != $phrase['arguments']) {
                     $errors[] = $this->_createPhraseError($phrase);
                 }
             }
         }
     }
     $this->assertEmpty($errors, sprintf("\n%d usages of inconsistency the number of arguments and placeholders were discovered: \n%s", count($errors), implode("\n\n", $errors)));
 }