setPrefix() public method

public setPrefix ( $prefix )
コード例 #1
0
 /**
  * @dataProvider getExtractData
  */
 public function testExtract($template, $messages)
 {
     $loader = new \Twig_Loader_Array(array());
     $twig = new \Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false, 'autoescape' => false));
     $twig->addExtension(new TranslationExtension($this->getMock('Symfony\\Component\\Translation\\TranslatorInterface')));
     $extractor = new TwigExtractor($twig);
     $extractor->setPrefix('prefix');
     $catalogue = new MessageCatalogue('en');
     $m = new \ReflectionMethod($extractor, 'extractTemplate');
     $m->setAccessible(true);
     $m->invoke($extractor, $template, $catalogue);
     foreach ($messages as $key => $domain) {
         $this->assertTrue($catalogue->has($key, $domain));
         $this->assertEquals('prefix' . $key, $catalogue->get($key, $domain));
     }
 }
コード例 #2
0
ファイル: TwigExtractorTest.php プロジェクト: ratasxy/symfony
 public function testFilterExtraction()
 {
     // 1.Arrange
     // a node using trans filter : {{ 'new key' | trans({}, 'domain') }}
     $transNode = new \Twig_Node_Expression_Filter(
         new \Twig_Node_Expression_Constant('first key', 0),
         new \Twig_Node_Expression_Constant('trans', 0),
         new \Twig_Node(array(
             1 => new \Twig_Node_Expression_Constant('domain', 0)
         )), array(), 0);
     // a trans block : {% trans from 'domain' %}second key{% endtrans %}
     $transBlock = new TransNode(
         new \Twig_Node(array(), array('data' => 'second key')),
         new \Twig_Node(array(), array('value' => 'domain'))
     );
     // mock the twig environment
     $twig = $this->getMock('Twig_Environment');
     $twig->expects($this->once())
          ->method('tokenize')
          ->will($this->returnValue(new \Twig_TokenStream(array())))
     ;
     $twig->expects($this->once())
          ->method('parse')
          ->will($this->returnValue(
              new \Twig_Node(array(
                  new \Twig_Node_Text('stub text', 0),
                  new \Twig_Node_Print($transNode,0),
                  $transBlock,
              ))
          ))
     ;
     // prepare extractor and catalogue
     $extractor = new TwigExtractor($twig);
     $extractor->setPrefix('prefix');
     $catalogue = new MessageCatalogue('en');
     
     // 2.Act
     $extractor->extract(__DIR__.'/../Fixtures/Resources/views/', $catalogue);
     
     // 3.Assert
     $this->assertTrue($catalogue->has('first key', 'domain'), '->extract() should find at leat "first key" message in the domain "domain"');
     $this->assertTrue($catalogue->has('second key', 'domain'), '->extract() should find at leat "second key" message in the domain "domain"');
     $this->assertEquals(2, count($catalogue->all('domain')), '->extract() should find 2 translations in the domain "domain"');
     $this->assertEquals('prefixfirst key', $catalogue->get('first key', 'domain'), '->extract() should apply "prefix" as prefix');
 }