| 1 |
dc33f4
|
Seldaek |
<?php |
|
| 2 |
↓
|
Seldaek |
|
|
| 3 |
dd288f
|
Seldaek |
require_once DWOO_DIRECTORY . 'Dwoo/Compiler.php'; |
|
| 4 |
dc33f4
|
Seldaek |
|
|
| 5 |
↓
|
Seldaek |
class CallTests extends PHPUnit_Framework_TestCase |
|
| 6 |
↓
|
Seldaek |
{ |
|
| 7 |
↓
|
Seldaek |
protected $compiler; |
|
| 8 |
↓
|
Seldaek |
protected $dwoo; |
|
| 9 |
↓
|
Seldaek |
|
|
| 10 |
↓
|
Seldaek |
public function __construct() |
|
| 11 |
↓
|
Seldaek |
{ |
|
| 12 |
↓
|
Seldaek |
// extend this class and override this in your constructor to test a modded compiler |
|
| 13 |
9cf6ad
|
Seldaek |
$this->compiler = new Dwoo_Compiler(); |
|
| 14 |
9315dc
|
seldaek |
$this->dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 15 |
dc33f4
|
Seldaek |
} |
|
| 16 |
↓
|
Seldaek |
|
|
| 17 |
↓
|
Seldaek |
public function testCustomFunctionPlugin() |
|
| 18 |
↓
|
Seldaek |
{ |
|
| 19 |
↓
|
Seldaek |
$this->dwoo->addPlugin('test', 'plugin_custom_name'); |
|
| 20 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{test "xxx"}'); |
|
| 21 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 22 |
↓
|
Seldaek |
|
|
| 23 |
↓
|
Seldaek |
$this->assertEquals('xxxbar', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 24 |
↓
|
Seldaek |
$this->dwoo->removePlugin('test'); |
|
| 25 |
↓
|
Seldaek |
} |
|
| 26 |
↓
|
Seldaek |
|
|
| 27 |
↓
|
Seldaek |
public function testHalfCustomClassPluginByClassMethodCallback() |
|
| 28 |
↓
|
Seldaek |
{ |
|
| 29 |
↓
|
Seldaek |
$this->dwoo->addPlugin('test', array('plugin_half_custom', 'process')); |
|
| 30 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{test "xxx"}'); |
|
| 31 |
2f0eff
|
Seldaek |
$tpl->forceCompilation(); |
|
| 32 |
↓
|
Seldaek |
|
|
| 33 |
dc33f4
|
Seldaek |
$this->assertEquals('xxxbar', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 34 |
2f0eff
|
Seldaek |
$this->dwoo->removePlugin('test'); |
|
| 35 |
dc33f4
|
Seldaek |
} |
|
| 36 |
2f0eff
|
Seldaek |
|
|
| 37 |
1e2469
|
Seldaek |
public function testFullCustomClassPluginByClassMethodCallback() { |
|
| 38 |
dc33f4
|
Seldaek |
$this->dwoo->addPlugin('test', array('plugin_full_custom', 'process')); |
|
| 39 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{test "xxx"}'); |
|
| 40 |
2f0eff
|
Seldaek |
$tpl->forceCompilation(); |
|
| 41 |
↓
|
Seldaek |
|
|
| 42 |
dc33f4
|
Seldaek |
$this->assertEquals('xxxbar', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 43 |
2f0eff
|
Seldaek |
$this->dwoo->removePlugin('test'); |
|
| 44 |
dc33f4
|
Seldaek |
} |
|
| 45 |
2f0eff
|
Seldaek |
|
|
| 46 |
dc33f4
|
Seldaek |
public function testCustomClassPluginByClassname() |
|
| 47 |
2f0eff
|
Seldaek |
{ |
|
| 48 |
dc33f4
|
Seldaek |
$this->dwoo->addPlugin('test', 'plugin_full_custom'); |
|
| 49 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{test "xxx"}'); |
|
| 50 |
2f0eff
|
Seldaek |
$tpl->forceCompilation(); |
|
| 51 |
↓
|
Seldaek |
|
|
| 52 |
dc33f4
|
Seldaek |
$this->assertEquals('xxxbar', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 53 |
2f0eff
|
Seldaek |
$this->dwoo->removePlugin('test'); |
|
| 54 |
dc33f4
|
Seldaek |
} |
|
| 55 |
2f0eff
|
Seldaek |
|
|
| 56 |
dc33f4
|
Seldaek |
public function testCustomObjectPluginByObjectMethodCallback() |
|
| 57 |
1e2469
|
Seldaek |
{ |
|
| 58 |
dc33f4
|
Seldaek |
$this->dwoo->addPlugin('test', array(new plugin_full_custom(), 'process')); |
|
| 59 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{test "xxx"}'); |
|
| 60 |
2f0eff
|
Seldaek |
$tpl->forceCompilation(); |
|
| 61 |
↓
|
Seldaek |
|
|
| 62 |
dc33f4
|
Seldaek |
$this->assertEquals('xxxbar', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 63 |
2f0eff
|
Seldaek |
$this->dwoo->removePlugin('test'); |
|
| 64 |
dc33f4
|
Seldaek |
} |
|
| 65 |
2f0eff
|
Seldaek |
|
|
| 66 |
dc33f4
|
Seldaek |
public function testCustomBlockPluginByClassMethodCallback() |
|
| 67 |
↓
|
Seldaek |
{ |
|
| 68 |
↓
|
Seldaek |
$this->dwoo->addPlugin('test', array('blockplugin_custom', 'process')); |
|
| 69 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{test "xxx"}aaa{/test}'); |
|
| 70 |
2f0eff
|
Seldaek |
$tpl->forceCompilation(); |
|
| 71 |
↓
|
Seldaek |
|
|
| 72 |
dc33f4
|
Seldaek |
$this->assertEquals('xxxbaraaa', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 73 |
2f0eff
|
Seldaek |
$this->dwoo->removePlugin('test'); |
|
| 74 |
dc33f4
|
Seldaek |
} |
|
| 75 |
2f0eff
|
Seldaek |
|
|
| 76 |
dc33f4
|
Seldaek |
public function testCustomBlockPluginByClassname() |
|
| 77 |
↓
|
Seldaek |
{ |
|
| 78 |
↓
|
Seldaek |
$this->dwoo->addPlugin('test', 'blockplugin_custom'); |
|
| 79 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{test "xxx"}aaa{/test}'); |
|
| 80 |
2f0eff
|
Seldaek |
$tpl->forceCompilation(); |
|
| 81 |
↓
|
Seldaek |
|
|
| 82 |
dc33f4
|
Seldaek |
$this->assertEquals('xxxbaraaa', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 83 |
2f0eff
|
Seldaek |
$this->dwoo->removePlugin('test'); |
|
| 84 |
dc33f4
|
Seldaek |
} |
|
| 85 |
↓
|
Seldaek |
|
|
| 86 |
↓
|
Seldaek |
/** |
|
| 87 |
9cf6ad
|
Seldaek |
* @expectedException Dwoo_Exception |
|
| 88 |
dc33f4
|
Seldaek |
*/ |
|
| 89 |
↓
|
Seldaek |
public function testCustomInvalidPlugin() |
|
| 90 |
↓
|
Seldaek |
{ |
|
| 91 |
↓
|
Seldaek |
$this->dwoo->addPlugin('test', 'sdfmslkfmsle'); |
|
| 92 |
↓
|
Seldaek |
} |
|
| 93 |
↓
|
Seldaek |
} |
|
| 94 |
2f0eff
|
Seldaek |
|
|
| 95 |
9315dc
|
seldaek |
function plugin_custom_name(Dwoo_Core $dwoo, $foo, $bar="bar") |
|
| 96 |
2f0eff
|
Seldaek |
{ |
|
| 97 |
↓
|
Seldaek |
return $foo.$bar; |
|
| 98 |
↓
|
Seldaek |
} |
|
| 99 |
↓
|
Seldaek |
|
|
| 100 |
9cf6ad
|
Seldaek |
class plugin_half_custom extends Dwoo_Plugin |
|
| 101 |
2f0eff
|
Seldaek |
{ |
|
| 102 |
↓
|
Seldaek |
public function process($foo, $bar="bar") |
|
| 103 |
↓
|
Seldaek |
{ |
|
| 104 |
↓
|
Seldaek |
return $foo.$bar; |
|
| 105 |
↓
|
Seldaek |
} |
|
| 106 |
↓
|
Seldaek |
} |
|
| 107 |
↓
|
Seldaek |
|
|
| 108 |
↓
|
Seldaek |
class plugin_full_custom |
|
| 109 |
↓
|
Seldaek |
{ |
|
| 110 |
↓
|
Seldaek |
public function process($foo, $bar="bar") |
|
| 111 |
↓
|
Seldaek |
{ |
|
| 112 |
↓
|
Seldaek |
return $foo.$bar; |
|
| 113 |
↓
|
Seldaek |
} |
|
| 114 |
↓
|
Seldaek |
} |
|
| 115 |
↓
|
Seldaek |
|
|
| 116 |
9cf6ad
|
Seldaek |
class blockplugin_custom extends Dwoo_Block_Plugin |
|
| 117 |
2f0eff
|
Seldaek |
{ |
|
| 118 |
↓
|
Seldaek |
public function init($foo, $bar="bar") |
|
| 119 |
↓
|
Seldaek |
{ |
|
| 120 |
↓
|
Seldaek |
$this->foo = $foo; |
|
| 121 |
↓
|
Seldaek |
$this->bar = $bar; |
|
| 122 |
↓
|
Seldaek |
} |
|
| 123 |
↓
|
Seldaek |
|
|
| 124 |
↓
|
Seldaek |
public function process() |
|
| 125 |
↓
|
Seldaek |
{ |
|
| 126 |
↓
|
Seldaek |
return $this->foo.$this->bar.$this->buffer; |
|
| 127 |
↓
|
Seldaek |
} |
|
| 128 |
↓
|
Seldaek |
} |
|