/** * Get (init if necessary) twig environment * * @param boolean $reset Force re-initialization (helpful for UTs) * * @return \Twig_Environment */ protected function getEnvironment($reset = false) { if ($reset === true || null === $this->twig) { $this->twig = new \Twig_Environment($this->getLoader(), $this->getConfig()); $this->twig->removeExtension('escaper'); } return $this->twig; }
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()); }
/** * @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()); }