function test_array_scoping() { $template = new LiquidTemplate(); $template->parse('{{ test.test }}'); $this->assertEqual('worked', $template->render(array('test' => array('test' => 'worked')))); // this wasn't working properly in if tests, test seperately $template->parse('{{ foo.bar }}'); $this->dump($template->render(array('foo' => array()))); }
function test_error_with_css() { $text = " div { font-weight: bold; } "; $template = new LiquidTemplate(); $template->parse($text); $this->assertEqual($text, $template->render()); $this->assertIsA($template->root->nodelist[0], 'string'); }
function test_override_global_filter() { $template = new LiquidTemplate(); $template->register_filter(new GlobalFilter()); $template->parse("{{'test' | notice }}"); $this->assertEqual('Global test', $template->render()); $this->assertEqual('Local test', $template->render(array(), new LocalFilter())); }
function test_local_global() { $template = new LiquidTemplate(); $template->register_filter(new MoneyFilter()); $template->parse('{{1000 | money}}'); $this->assertIdentical(' 1000$ ', $template->render()); $this->assertIdentical(' 1000$ CAD ', $template->render(null, new CanadianMoneyFilter())); }
function test_with_block() { $template = new LiquidTemplate(); $template->parse(' {% comment %} {% endcomment %} '); $this->assertEqual(3, count($template->root->nodelist)); $this->assertIsA($template->root->nodelist[0], 'string'); $this->assertIsA($template->root->nodelist[1], 'CommentLiquidTag'); $this->assertIsA($template->root->nodelist[2], 'string'); }
function test_with_block() { $template = new LiquidTemplate(); $template->parse(' {% comment %} {% endcomment %} '); $nodelist = $template->getRoot()->getNodelist(); $this->assertEqual(3, count($nodelist)); $this->assertIsA($nodelist[0], 'string'); $this->assertIsA($nodelist[1], 'LiquidTagComment'); $this->assertIsA($nodelist[2], 'string'); }
function assert_template_result($expected, $template, $assigns = null, $message = "%s", $debug = false) { if (is_null($assigns)) { $assigns = array(); } $result = new LiquidTemplate(); $result->parse($template); if ($debug) { debug($result); } $this->assertEqual($expected, $result->render($assigns, $this->filters), $message); }
/** * Tests filtered value assignment * * @return void */ public function testAssignWithFilters() { $template = new LiquidTemplate(); $template->parse('{% assign test = "hello" | upcase %}{{ test }}'); $this->assertTrue($template->render() === 'HELLO'); $template->parse('{% assign test = "hello" | upcase | downcase | capitalize %}{{ test }}'); $this->assertTrue($template->render() === 'Hello'); $template->parse('{% assign test = var1 | first | upcase %}{{ test }}'); $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'A'); $template->parse('{% assign test = var1 | last | upcase %}{{ test }}'); $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'C'); $template->parse('{% assign test = var1 | join %}{{ test }}'); $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'a b c'); $template->parse('{% assign test = var1 | join : "." %}{{ test }}'); $this->assertTrue($template->render(array('var1' => array('a', 'b', 'c'))) === 'a.b.c'); }
<?php require_once '../lib/liquid.php'; $liquid = new LiquidTemplate(); $liquid->parse(file_get_contents('templates/index.liquid')); $assigns = array('date' => date('r')); print $liquid->render($assigns);
function test_include_tag_no_with() { $template = new LiquidTemplate(); $template->setFileSystem(new LiquidTestFileSystem()); $template->parse("Outer-{% include 'inner' %}-Outer-{% include 'inner' other:'23' %}"); $output = $template->render(array("inner" => "orig", "var" => array(1, 2, 3))); $this->assertEqual("Outer-Inner: orig-Outer-Inner: orig23", $output); }
public function assertTrueHelper($templateString, $expected, $data = array()) { $template = new LiquidTemplate(); $template->parse($templateString); $this->assertTrue($template->render($data) === $expected); }
<?php define('LIQUID_INCLUDE_SUFFIX', 'tpl'); define('LIQUID_INCLUDE_PREFIX', ''); require_once '../Liquid.class.php'; $liquid = new LiquidTemplate(); $liquid->parse('{{ hello }} {{ goback }}'); print $liquid->render(array('hello' => 'hello world', 'goback' => '<a href=".">index</a>'));
function test_nested_context_drop() { $template = new LiquidTemplate(); $template->parse(' {{ product.context.foo }} '); $output = $template->render(array('product' => new ProductDrop(), 'foo' => 'monkey')); $this->assertEqual(' monkey ', $output); }
<?php define('LIQUID_INCLUDE_ALLOW_EXT', true); require_once '../Liquid.class.php'; define('PROTECTED_PATH', dirname(__FILE__) . '/protected/'); $liquid = new LiquidTemplate(PROTECTED_PATH . 'templates/'); $cache = array('cache' => 'file', 'cache_dir' => PROTECTED_PATH . 'cache/'); //$cache = array('cache' => 'apc'); //$liquid->setCache($cache); $liquid->parse(file_get_contents(PROTECTED_PATH . 'templates/child.tpl')); $assigns = array('document' => array('title' => 'This is php-liquid', 'content' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.', 'copyright' => '© Copyright 2012 Harald Hanek - All rights reserved.')); echo $liquid->render($assigns);
<?php class ProductsFilter { function price($integer) { return sprintf("\$%.2d USD", $integer / 100); } function prettyprint($text) { return preg_replace('/\\*(.*)\\*/', '<b>\\1</b>', $text); } function count($array) { return count($array); } function paragraph($p) { return "<p>" . $p . "</p>"; } } require_once '../lib/liquid.php'; $liquid = new LiquidTemplate(); $liquid->register_filter(new ProductsFilter()); $liquid->parse(file_get_contents('templates/products.liquid')); $products_list = array(array('name' => 'Arbor Draft', 'price' => 39900, 'description' => 'the *arbor draft* is a excellent product'), array('name' => 'Arbor Element', 'price' => 40000, 'description' => 'the *arbor element* rocks for freestyling'), array('name' => 'Arbor Diamond', 'price' => 59900, 'description' => 'the *arbor diamond* is a made up product because im obsessed with arbor and have no creativity')); $products = array('products' => $products_list, 'section' => 'Snowboards', 'cool_products' => true); $assigns = array('date' => date('r')); print $liquid->render($products);