예제 #1
0
 /**
  * Unregister a function
  *
  * @param string    $name   The function name
  * @return TemplateEngineTwig
  */
 public function unregisterFunction($name)
 {
     parent::unregisterFunction($name);
     $functions = $this->_twig->getFunctions();
     if (isset($functions[$name])) {
         unset($functions[$name]);
     }
     return $this;
 }
예제 #2
0
 public function testRemoveExtension()
 {
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension());
     $twig->removeExtension('test');
     $this->assertFalse(array_key_exists('test', $twig->getTags()));
     $this->assertFalse(array_key_exists('foo_filter', $twig->getFilters()));
     $this->assertFalse(array_key_exists('foo_function', $twig->getFunctions()));
     $this->assertFalse(array_key_exists('foo_test', $twig->getTests()));
     $this->assertFalse(array_key_exists('foo_unary', $twig->getUnaryOperators()));
     $this->assertFalse(array_key_exists('foo_binary', $twig->getBinaryOperators()));
     $this->assertFalse(array_key_exists('foo_global', $twig->getGlobals()));
     $this->assertCount(2, $twig->getNodeVisitors());
 }
예제 #3
0
 public function testAddExtension()
 {
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension());
     $this->assertArrayHasKey('test', $twig->getTags());
     $this->assertArrayHasKey('foo_filter', $twig->getFilters());
     $this->assertArrayHasKey('foo_function', $twig->getFunctions());
     $this->assertArrayHasKey('foo_test', $twig->getTests());
     $this->assertArrayHasKey('foo_unary', $twig->getUnaryOperators());
     $this->assertArrayHasKey('foo_binary', $twig->getBinaryOperators());
     $this->assertArrayHasKey('foo_global', $twig->getGlobals());
     $visitors = $twig->getNodeVisitors();
     $this->assertEquals('Twig_Tests_EnvironmentTest_NodeVisitor', get_class($visitors[2]));
 }
 /**
  * @group legacy
  */
 public function testRemoveExtension()
 {
     $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
     $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName());
     $twig->removeExtension('environment_test');
     $this->assertFalse(array_key_exists('test', $twig->getTags()));
     $this->assertFalse(array_key_exists('foo_filter', $twig->getFilters()));
     $this->assertFalse(array_key_exists('foo_function', $twig->getFunctions()));
     $this->assertFalse(array_key_exists('foo_test', $twig->getTests()));
     $this->assertFalse(array_key_exists('foo_unary', $twig->getUnaryOperators()));
     $this->assertFalse(array_key_exists('foo_binary', $twig->getBinaryOperators()));
     $this->assertFalse(array_key_exists('foo_global', $twig->getGlobals()));
     $this->assertCount(2, $twig->getNodeVisitors());
 }