Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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');
 }
Ejemplo n.º 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');
 }
Ejemplo n.º 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));
    }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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('');
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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()));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }