function test_second_filter_overwrites_first() { $var = new LiquidVariable('var | money '); $this->context->set('var', 1000); $this->context->add_filters(new MoneyFilter(), 'money'); $this->context->add_filters(new CanadianMoneyFilter(), 'money'); $this->assertIdentical(' 1000$ CAD ', $var->render($this->context)); }
function test_add_filter() { $context = new LiquidContext(); $context->add_filters(new HiFilter()); $this->assertEqual('hi? hi!', $context->invoke('hi', 'hi?')); $context = new LiquidContext(); $this->assertEqual('hi?', $context->invoke('hi', 'hi?')); $context->add_filters(new HiFilter()); $this->assertEqual('hi? hi!', $context->invoke('hi', 'hi?')); }
/** * Renders the current template * * @param array $assigns An array of values for the template * @param array $filters Additional filters for the template * @param array $registers Additional registers for the template * @return string */ function render($assigns = null, $filters = null, $registers = null) { if (is_null($assigns)) { $assigns = array(); } $context = new LiquidContext($assigns, $registers); if (!is_null($filters)) { if (is_array($filters)) { array_merge($this->filters, $filters); } else { $this->filters[] = $filters; } } foreach ($this->filters as $filter) { $context->add_filters($filter); } return $this->root->render($context); }