public function testAllowPhpFunction() { $this->policy->allowPhpFunction('testphpfunc'); $tpl = new Dwoo_Template_String('{testphpfunc("foo")}'); $tpl->forceCompilation(); $this->assertEquals("fooOK", $this->dwoo->get($tpl, array(), $this->compiler)); }
public function testCustomBlockPluginByClassname() { $this->dwoo->addPlugin('test', 'blockplugin_custom'); $tpl = new Dwoo_Template_String('{test "xxx"}aaa{/test}'); $tpl->forceCompilation(); $this->assertEquals('xxxbaraaa', $this->dwoo->get($tpl, array(), $this->compiler)); $this->dwoo->removePlugin('test'); }
public function testSmartyCompat() { $tpl = new Dwoo_Template_String('{ldelim}{$smarty.version}{rdelim}'); $tpl->forceCompilation(); $cmp = new Dwoo_Compiler(); $cmp->addPreProcessor('smarty_compat', true); $this->assertEquals('{' . Dwoo::VERSION . '}', $this->dwoo->get($tpl, array(), $cmp)); }
public function testAdvNestedProxyCall() { $this->dwoo->setPluginProxy(new PluginProxyTest_PluginProxy()); // test simple assign $tpl = new Dwoo_Template_String('{assign F1_Stub(F2_Stub(\'/public/css/global.css\'))->something(F3_Stub(\'/public/css/global.css\')) styles}'); $tpl->forceCompilation(); $this->assertContains('PluginProxyTest_F3_Stub(', $this->compiler->compile($this->dwoo, $tpl)); }
public function testRebuildClassPath() { $dwoo = new Dwoo(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); $loader = new Dwoo_Loader(TEST_DIRECTORY . '/temp/cache'); $dwoo->setLoader($loader); $loader->addDirectory(TEST_DIRECTORY . '/resources/plugins'); file_put_contents(TEST_DIRECTORY . '/resources/plugins/loaderTest2.php', '<?php function Dwoo_Plugin_loaderTest2(Dwoo $dwoo) { return "It works!"; }'); $tpl = new Dwoo_Template_String('{loaderTest2}'); $tpl->forceCompilation(); $this->assertEquals('It works!', $dwoo->get($tpl, array(), $this->compiler)); unlink(TEST_DIRECTORY . '/resources/plugins/loaderTest2.php'); }
public function testAssociativeArray() { $tpl = new Dwoo_Template_String('{if array(hoy=3,5="foo",bar=moo) === $test}true{/if}'); $tpl->forceCompilation(); $this->assertEquals('true', $this->dwoo->get($tpl, array('test' => array("hoy" => 3, 5 => "foo", "bar" => "moo"), 'baz' => 'baz'), $this->compiler)); $tpl = new Dwoo_Template_String('{if array(hoy=3,5=array( "foo" frack 18 ) bar=moo) === $test}true{/if}'); $tpl->forceCompilation(); $this->assertEquals('true', $this->dwoo->get($tpl, array('test' => array("hoy" => 3, 5 => array("foo", "frack", 18), "bar" => "moo"), 'baz' => 'baz'), $this->compiler)); }
public function testWordwrap() { $tpl = new Dwoo_Template_String('{wordwrap "abcdefghijklmnopqrstuvwxyz" 8 "\\n" true}'); $tpl->forceCompilation(); $this->assertEquals("abcdefgh\nijklmnop\nqrstuvwx\nyz", $this->dwoo->get($tpl, array(), $this->compiler)); }
public function testAssociativeArrayWithMixedOrderDefinedKeys() { $tpl = new Dwoo_Template_String('{if array(5="foo", 3=moo) === $test}true{/if}'); $tpl->forceCompilation(); $this->assertEquals('true', $this->dwoo->get($tpl, array('test' => array(5 => "foo", 3 => "moo")), $this->compiler)); }
public function testCustomClassPluginInstanceAsModifier() { $dwoo = new Dwoo(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); $dwoo->addPlugin('CustomClassPlugin', array(new custom_class_plugin_obj(), 'call')); $tpl = new Dwoo_Template_String('{$foo=4}{$foo|CustomClassPlugin:5}'); $tpl->forceCompilation(); $this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); }
public function testWith() { $tpl = new Dwoo_Template_String('{with $foo}{$a}{/with}-{if $a}FAIL{/if}-{with $foo.b}mlsk{/with}'); $tpl->forceCompilation(); $this->assertEquals('bar--', $this->dwoo->get($tpl, array('foo' => array('a' => 'bar')), $this->compiler)); $tpl = new Dwoo_Template_String('{with $foo}{$a.0}{with $a}{$0}{/with}{with $b}B{else}NOB{/with}{/with}-{if $a}FAIL{/if}-{with $foo.b}mlsk{/with}{with $fooo}a{withelse}b{/with}'); $tpl->forceCompilation(); $this->assertEquals('barbarNOB--b', $this->dwoo->get($tpl, array('foo' => array('a' => array('bar'))), $this->compiler)); // fixes the init call not being called (which is normal) $fixCall = new Dwoo_Plugin_with($this->dwoo); $fixCall->init(''); $fixCall = new Dwoo_Plugin_withelse($this->dwoo); $fixCall->init(''); }
public function testCallingMethodOnPropery() { $tpl = new Dwoo_Template_String('{getobj()->instance->Bar("hoy")}'); $tpl->forceCompilation(); $dwoo = new Dwoo(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); $dwoo->addPlugin('getobj', array(new PluginHelper(), 'call')); $this->assertEquals('HOY', $dwoo->get($tpl, array(), $this->compiler)); }
public function testClearCacheOnTemplateClass() { $dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); $dwoo->setCacheTime(10); $tpl = new Dwoo_Template_String('foo{$foo}bar', null, 'cachetest2'); $tpl->forceCompilation(); $this->assertEquals("foo1bar", $dwoo->get($tpl, array('foo' => 1))); $this->assertEquals(true, $dwoo->isCached($tpl)); $this->assertEquals("foo1bar", $dwoo->get($tpl, array('foo' => 1))); $this->assertEquals(false, $tpl->clearCache($dwoo, 10)); $this->assertEquals(true, $tpl->clearCache($dwoo, -1)); $this->assertEquals(false, $dwoo->isCached($tpl)); }
/** * @expectedException Dwoo_Security_Exception */ public function testNotAllowedSubExecution() { $tpl = new Dwoo_Template_String('{$obj->test(preg_replace_callback("{.}", "mail", "f"))}'); $tpl->forceCompilation(); $this->dwoo->get($tpl, array('obj' => new testSecurityClass()), $this->compiler); }
/** * @expectedException Dwoo_Compilation_Exception */ public function testElseWithoutIfIsInvalid() { $tpl = new Dwoo_Template_String('{else}1{/}'); $tpl->forceCompilation(); $this->dwoo->get($tpl, array(), $this->compiler); }
public function testPhpTagWithoutSemicolon() { $tpl = new Dwoo_Template_String('{capture "foo"}<?php $var=3; echo $var ?>{/capture}-{$.capture.foo}'); $tpl->forceCompilation(); $this->assertEquals("-3", $this->dwoo->get($tpl, array())); }
public function testDoubleEscapingOnAssignments() { $tpl = new Dwoo_Template_String('{$bar = $foo}{$foo}{$bar}'); $tpl->forceCompilation(); $cmp = new Dwoo_Compiler(); $cmp->setAutoEscape(true); $this->assertEquals('a'ba'b', $this->dwoo->get($tpl, array('foo' => "a'b"), $cmp)); }