예제 #1
0
 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));
 }
예제 #2
0
 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));
 }
예제 #3
0
 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));
 }
예제 #4
0
 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');
 }
예제 #5
0
 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');
 }
예제 #6
0
    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));
    }
예제 #7
0
 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));
 }
예제 #8
0
 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));
 }
예제 #9
0
 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('');
 }
예제 #10
0
 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));
 }
예제 #11
0
 public function testTemplateGetSet()
 {
     $dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR);
     $dwoo->setCacheTime(10);
     $tpl = new Dwoo_Template_String('foo');
     $tpl2 = new Dwoo_Template_File('./resources/test.html');
     $this->assertEquals(false, $tpl->getResourceIdentifier());
     $this->assertEquals('string', $tpl->getResourceName());
     $this->assertEquals('file', $tpl2->getResourceName());
     $this->assertEquals(hash('md4', 'foo'), $tpl->getUid());
 }
예제 #12
0
 /**
  * @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);
 }
예제 #13
0
 /**
  * @expectedException Dwoo_Compilation_Exception
  */
 public function testElseWithoutIfIsInvalid()
 {
     $tpl = new Dwoo_Template_String('{else}1{/}');
     $tpl->forceCompilation();
     $this->dwoo->get($tpl, array(), $this->compiler);
 }
예제 #14
0
 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()));
 }
예제 #15
0
 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));
 }
예제 #16
0
 /**
  * Checks if compiled file is valid (exists and it's the modification is greater or
  * equal to the modification time of the template file)
  *
  * @param string file
  * @return boolean True cache file existance and it's modification time
  */
 protected function isValidCompiledFile($file)
 {
     return parent::isValidCompiledFile($file) && (int) $this->getUid() <= filemtime($file);
 }
예제 #17
0
 public function testDoubleEscapingOnAssignments()
 {
     $tpl = new Dwoo_Template_String('{$bar = $foo}{$foo}{$bar}');
     $tpl->forceCompilation();
     $cmp = new Dwoo_Compiler();
     $cmp->setAutoEscape(true);
     $this->assertEquals('a&#039;ba&#039;b', $this->dwoo->get($tpl, array('foo' => "a'b"), $cmp));
 }