| 1 |
37cb06
|
Seldaek |
<?php |
|
| 2 |
↓
|
Seldaek |
|
|
| 3 |
dd288f
|
Seldaek |
require_once DWOO_DIRECTORY . 'Dwoo/Compiler.php'; |
|
| 4 |
37cb06
|
Seldaek |
|
|
| 5 |
↓
|
Seldaek |
class PluginTypesTests 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 |
↓
|
Seldaek |
$this->compiler = new Dwoo_Compiler(); |
|
| 14 |
9315dc
|
seldaek |
$this->dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 15 |
37cb06
|
Seldaek |
} |
|
| 16 |
↓
|
Seldaek |
|
|
| 17 |
↓
|
Seldaek |
// Functions - Dwoo style |
|
| 18 |
↓
|
Seldaek |
public function testCompilableFunctionPlugin() |
|
| 19 |
↓
|
Seldaek |
{ |
|
| 20 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{CompilableFunctionPlugin 4 5}'); |
|
| 21 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 22 |
↓
|
Seldaek |
|
|
| 23 |
↓
|
Seldaek |
$this->assertEquals('20', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 24 |
↓
|
Seldaek |
} |
|
| 25 |
↓
|
Seldaek |
|
|
| 26 |
↓
|
Seldaek |
public function testCompilableFunctionPluginAsModifier() |
|
| 27 |
↓
|
Seldaek |
{ |
|
| 28 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|CompilableFunctionPlugin:5}'); |
|
| 29 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 30 |
↓
|
Seldaek |
|
|
| 31 |
↓
|
Seldaek |
$this->assertEquals('20', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 32 |
↓
|
Seldaek |
} |
|
| 33 |
↓
|
Seldaek |
|
|
| 34 |
↓
|
Seldaek |
public function testFunctionPlugin() |
|
| 35 |
↓
|
Seldaek |
{ |
|
| 36 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{FunctionPlugin 4 5}'); |
|
| 37 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 38 |
↓
|
Seldaek |
|
|
| 39 |
↓
|
Seldaek |
$this->assertEquals('20', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 40 |
↓
|
Seldaek |
} |
|
| 41 |
↓
|
Seldaek |
|
|
| 42 |
↓
|
Seldaek |
public function testFunctionPluginAsModifier() |
|
| 43 |
↓
|
Seldaek |
{ |
|
| 44 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|FunctionPlugin:5}'); |
|
| 45 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 46 |
↓
|
Seldaek |
|
|
| 47 |
↓
|
Seldaek |
$this->assertEquals('20', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 48 |
↓
|
Seldaek |
} |
|
| 49 |
↓
|
Seldaek |
|
|
| 50 |
↓
|
Seldaek |
// Classes - Dwoo style |
|
| 51 |
↓
|
Seldaek |
public function testCompilableClassPlugin() |
|
| 52 |
↓
|
Seldaek |
{ |
|
| 53 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{CompilableClassPlugin 4 5}'); |
|
| 54 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 55 |
↓
|
Seldaek |
|
|
| 56 |
↓
|
Seldaek |
$this->assertEquals('20', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 57 |
↓
|
Seldaek |
} |
|
| 58 |
↓
|
Seldaek |
|
|
| 59 |
↓
|
Seldaek |
public function testCompilableClassPluginAsModifier() |
|
| 60 |
↓
|
Seldaek |
{ |
|
| 61 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|CompilableClassPlugin:5}'); |
|
| 62 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 63 |
↓
|
Seldaek |
|
|
| 64 |
↓
|
Seldaek |
$this->assertEquals('20', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 65 |
↓
|
Seldaek |
} |
|
| 66 |
↓
|
Seldaek |
|
|
| 67 |
↓
|
Seldaek |
public function testClassPlugin() |
|
| 68 |
↓
|
Seldaek |
{ |
|
| 69 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{ClassPlugin 4 5}'); |
|
| 70 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 71 |
↓
|
Seldaek |
|
|
| 72 |
↓
|
Seldaek |
$this->assertEquals('20', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 73 |
↓
|
Seldaek |
} |
|
| 74 |
↓
|
Seldaek |
|
|
| 75 |
↓
|
Seldaek |
public function testClassPluginAsModifier() |
|
| 76 |
↓
|
Seldaek |
{ |
|
| 77 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|ClassPlugin:5}'); |
|
| 78 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 79 |
↓
|
Seldaek |
|
|
| 80 |
↓
|
Seldaek |
$this->assertEquals('20', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 81 |
↓
|
Seldaek |
} |
|
| 82 |
↓
|
Seldaek |
|
|
| 83 |
↓
|
Seldaek |
// Functions - Custom style |
|
| 84 |
↓
|
Seldaek |
public function testCustomCompilableFunctionPlugin() |
|
| 85 |
↓
|
Seldaek |
{ |
|
| 86 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 87 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomCompilableFunctionPlugin', 'custom_compilable_plugin', true); |
|
| 88 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{CustomCompilableFunctionPlugin 4 5}'); |
|
| 89 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 90 |
↓
|
Seldaek |
|
|
| 91 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 92 |
↓
|
Seldaek |
} |
|
| 93 |
↓
|
Seldaek |
|
|
| 94 |
↓
|
Seldaek |
public function testCustomCompilableFunctionPluginAsModifier() |
|
| 95 |
↓
|
Seldaek |
{ |
|
| 96 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 97 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomCompilableFunctionPlugin', 'custom_compilable_plugin', true); |
|
| 98 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|CustomCompilableFunctionPlugin:5}'); |
|
| 99 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 100 |
↓
|
Seldaek |
|
|
| 101 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 102 |
↓
|
Seldaek |
} |
|
| 103 |
↓
|
Seldaek |
|
|
| 104 |
↓
|
Seldaek |
public function testCustomFunctionPlugin() |
|
| 105 |
↓
|
Seldaek |
{ |
|
| 106 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 107 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomFunctionPlugin', 'custom_plugin'); |
|
| 108 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{CustomFunctionPlugin 4 5}'); |
|
| 109 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 110 |
↓
|
Seldaek |
|
|
| 111 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 112 |
↓
|
Seldaek |
} |
|
| 113 |
↓
|
Seldaek |
|
|
| 114 |
↓
|
Seldaek |
public function testCustomFunctionPluginAsModifier() |
|
| 115 |
↓
|
Seldaek |
{ |
|
| 116 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 117 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomFunctionPlugin', 'custom_plugin'); |
|
| 118 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|CustomFunctionPlugin:5}'); |
|
| 119 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 120 |
↓
|
Seldaek |
|
|
| 121 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 122 |
↓
|
Seldaek |
} |
|
| 123 |
↓
|
Seldaek |
|
|
| 124 |
↓
|
Seldaek |
// Classes - Custom style - Static |
|
| 125 |
↓
|
Seldaek |
public function testCustomCompilableClassPlugin() |
|
| 126 |
↓
|
Seldaek |
{ |
|
| 127 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 128 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomCompilableClassPlugin', array('custom_compilable_class_plugin', 'call'), true); |
|
| 129 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{CustomCompilableClassPlugin 4 5}'); |
|
| 130 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 131 |
↓
|
Seldaek |
|
|
| 132 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 133 |
↓
|
Seldaek |
} |
|
| 134 |
↓
|
Seldaek |
|
|
| 135 |
↓
|
Seldaek |
public function testCustomCompilableClassPluginAsModifier() |
|
| 136 |
↓
|
Seldaek |
{ |
|
| 137 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 138 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomCompilableClassPlugin', array('custom_compilable_class_plugin', 'call'), true); |
|
| 139 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|CustomCompilableClassPlugin:5}'); |
|
| 140 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 141 |
↓
|
Seldaek |
|
|
| 142 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 143 |
↓
|
Seldaek |
} |
|
| 144 |
↓
|
Seldaek |
|
|
| 145 |
↓
|
Seldaek |
public function testCustomClassPlugin() |
|
| 146 |
↓
|
Seldaek |
{ |
|
| 147 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 148 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomClassPlugin', array('custom_class_plugin', 'call')); |
|
| 149 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{CustomClassPlugin 4 5}'); |
|
| 150 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 151 |
↓
|
Seldaek |
|
|
| 152 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 153 |
↓
|
Seldaek |
} |
|
| 154 |
↓
|
Seldaek |
|
|
| 155 |
↓
|
Seldaek |
public function testCustomClassPluginAsModifier() |
|
| 156 |
↓
|
Seldaek |
{ |
|
| 157 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 158 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomClassPlugin', array('custom_class_plugin', 'call')); |
|
| 159 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|CustomClassPlugin:5}'); |
|
| 160 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 161 |
↓
|
Seldaek |
|
|
| 162 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 163 |
↓
|
Seldaek |
} |
|
| 164 |
↓
|
Seldaek |
|
|
| 165 |
↓
|
Seldaek |
// Classes - Custom style - Instance |
|
| 166 |
↓
|
Seldaek |
public function testCustomCompilableClassPluginInstance() |
|
| 167 |
↓
|
Seldaek |
{ |
|
| 168 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 169 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomCompilableClassPlugin', array(new custom_compilable_class_plugin_obj(), 'call'), true); |
|
| 170 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{CustomCompilableClassPlugin 4 5}'); |
|
| 171 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 172 |
↓
|
Seldaek |
|
|
| 173 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 174 |
↓
|
Seldaek |
} |
|
| 175 |
↓
|
Seldaek |
|
|
| 176 |
↓
|
Seldaek |
public function testCustomCompilableClassPluginInstanceAsModifier() |
|
| 177 |
↓
|
Seldaek |
{ |
|
| 178 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 179 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomCompilableClassPlugin', array(new custom_compilable_class_plugin_obj(), 'call'), true); |
|
| 180 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|CustomCompilableClassPlugin:5}'); |
|
| 181 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 182 |
↓
|
Seldaek |
|
|
| 183 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 184 |
↓
|
Seldaek |
} |
|
| 185 |
↓
|
Seldaek |
|
|
| 186 |
↓
|
Seldaek |
public function testCustomClassPluginInstance() |
|
| 187 |
↓
|
Seldaek |
{ |
|
| 188 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 189 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomClassPlugin', array(new custom_class_plugin_obj(), 'call')); |
|
| 190 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{CustomClassPlugin 4 5}'); |
|
| 191 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 192 |
↓
|
Seldaek |
|
|
| 193 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 194 |
↓
|
Seldaek |
} |
|
| 195 |
↓
|
Seldaek |
|
|
| 196 |
↓
|
Seldaek |
public function testCustomClassPluginInstanceAsModifier() |
|
| 197 |
↓
|
Seldaek |
{ |
|
| 198 |
9315dc
|
seldaek |
$dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR); |
|
| 199 |
37cb06
|
Seldaek |
$dwoo->addPlugin('CustomClassPlugin', array(new custom_class_plugin_obj(), 'call')); |
|
| 200 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{$foo=4}{$foo|CustomClassPlugin:5}'); |
|
| 201 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 202 |
↓
|
Seldaek |
|
|
| 203 |
↓
|
Seldaek |
$this->assertEquals('20', $dwoo->get($tpl, array(), $this->compiler)); |
|
| 204 |
↓
|
Seldaek |
} |
|
| 205 |
↓
|
Seldaek |
} |
|
| 206 |
↓
|
Seldaek |
|
|
| 207 |
↓
|
Seldaek |
function Dwoo_Plugin_CompilableFunctionPlugin_compile(Dwoo_Compiler $compiler, $number, $number2) |
|
| 208 |
↓
|
Seldaek |
{ |
|
| 209 |
↓
|
Seldaek |
return "$number * $number2"; |
|
| 210 |
↓
|
Seldaek |
} |
|
| 211 |
↓
|
Seldaek |
|
|
| 212 |
9315dc
|
seldaek |
function Dwoo_Plugin_FunctionPlugin(Dwoo_Core $dwoo, $number, $number2) |
|
| 213 |
37cb06
|
Seldaek |
{ |
|
| 214 |
↓
|
Seldaek |
return $number * $number2; |
|
| 215 |
↓
|
Seldaek |
} |
|
| 216 |
↓
|
Seldaek |
|
|
| 217 |
↓
|
Seldaek |
class Dwoo_Plugin_CompilableClassPlugin extends Dwoo_Plugin implements Dwoo_ICompilable |
|
| 218 |
↓
|
Seldaek |
{ |
|
| 219 |
↓
|
Seldaek |
public static function compile(Dwoo_Compiler $compiler, $number, $number2) |
|
| 220 |
↓
|
Seldaek |
{ |
|
| 221 |
↓
|
Seldaek |
return "$number * $number2"; |
|
| 222 |
↓
|
Seldaek |
} |
|
| 223 |
↓
|
Seldaek |
} |
|
| 224 |
↓
|
Seldaek |
|
|
| 225 |
↓
|
Seldaek |
class Dwoo_Plugin_ClassPlugin extends Dwoo_Plugin |
|
| 226 |
↓
|
Seldaek |
{ |
|
| 227 |
↓
|
Seldaek |
public function process($number, $number2) |
|
| 228 |
↓
|
Seldaek |
{ |
|
| 229 |
↓
|
Seldaek |
return $number * $number2; |
|
| 230 |
↓
|
Seldaek |
} |
|
| 231 |
↓
|
Seldaek |
} |
|
| 232 |
↓
|
Seldaek |
|
|
| 233 |
↓
|
Seldaek |
function custom_compilable_plugin(Dwoo_Compiler $cmp, $number, $number2) |
|
| 234 |
↓
|
Seldaek |
{ |
|
| 235 |
↓
|
Seldaek |
return "$number * $number2"; |
|
| 236 |
↓
|
Seldaek |
} |
|
| 237 |
↓
|
Seldaek |
|
|
| 238 |
9315dc
|
seldaek |
function custom_plugin(Dwoo_Core $dwoo, $number, $number2) |
|
| 239 |
37cb06
|
Seldaek |
{ |
|
| 240 |
↓
|
Seldaek |
return $number * $number2; |
|
| 241 |
↓
|
Seldaek |
} |
|
| 242 |
↓
|
Seldaek |
|
|
| 243 |
↓
|
Seldaek |
class custom_compilable_class_plugin |
|
| 244 |
↓
|
Seldaek |
{ |
|
| 245 |
↓
|
Seldaek |
public static function call($number, $number2) |
|
| 246 |
↓
|
Seldaek |
{ |
|
| 247 |
↓
|
Seldaek |
return "$number * $number2"; |
|
| 248 |
↓
|
Seldaek |
} |
|
| 249 |
↓
|
Seldaek |
} |
|
| 250 |
↓
|
Seldaek |
|
|
| 251 |
↓
|
Seldaek |
class custom_class_plugin |
|
| 252 |
↓
|
Seldaek |
{ |
|
| 253 |
↓
|
Seldaek |
public static function call($number, $number2) |
|
| 254 |
↓
|
Seldaek |
{ |
|
| 255 |
↓
|
Seldaek |
return $number * $number2; |
|
| 256 |
↓
|
Seldaek |
} |
|
| 257 |
↓
|
Seldaek |
} |
|
| 258 |
↓
|
Seldaek |
|
|
| 259 |
↓
|
Seldaek |
class custom_compilable_class_plugin_obj |
|
| 260 |
↓
|
Seldaek |
{ |
|
| 261 |
↓
|
Seldaek |
public function call($number, $number2) |
|
| 262 |
↓
|
Seldaek |
{ |
|
| 263 |
↓
|
Seldaek |
return "$number * $number2"; |
|
| 264 |
↓
|
Seldaek |
} |
|
| 265 |
↓
|
Seldaek |
} |
|
| 266 |
↓
|
Seldaek |
|
|
| 267 |
↓
|
Seldaek |
class custom_class_plugin_obj |
|
| 268 |
↓
|
Seldaek |
{ |
|
| 269 |
↓
|
Seldaek |
public function call($number, $number2) |
|
| 270 |
↓
|
Seldaek |
{ |
|
| 271 |
↓
|
Seldaek |
return $number * $number2; |
|
| 272 |
↓
|
Seldaek |
} |
|
| 273 |
↓
|
Seldaek |
} |
|