public function testFilterParsing() { $c = array('article' => array('section' => 'News')); $p = new Parser(''); $fe = new FilterExpression('article.section', $p); $this->assertEquals('News', $fe->resolve($c)); $fe = new FilterExpression('article.section|upper', $p); $this->assertEquals('NEWS', $fe->resolve($c)); $fe = new FilterExpression('"News"', $p); $this->assertEquals('News', $fe->resolve($c)); $fe = new FilterExpression("'News'", $p); $this->assertEquals('News', $fe->resolve($c)); $fe = new FilterExpression('"Some \\"Good\\" News"', $p); $this->assertEquals('Some "Good" News', $fe->resolve($c)); $fe = new FilterExpression("'Some \"Good\" News'", $p); $this->assertEquals('Some "Good" News', $fe->resolve($c)); $fe = new FilterExpression('"Some \\"Good\\" News"', $p); $this->assertEquals(array(), $fe->filters); $this->assertEquals('Some "Good" News', $fe->var); $fe = new FilterExpression("'Some \\'Bad\\' News'", $p); $this->assertEquals("Some 'Bad' News", $fe->resolve($c)); // Filtered variables should reject access of attributes beginning with underscores. $this->setExpectedException('TemplateSyntaxError'); new FilterExpression('article._hidden|upper', $p); }
/** * @param Context $context * * @return SafeString|string */ public function render($context) { $output = $this->filter_expression->resolve($context); return DjaBase::renderValueInContext($output, $context); }