| 1 |
dc33f4
|
Seldaek |
<?php |
|
| 2 |
↓
|
Seldaek |
|
|
| 3 |
dd288f
|
Seldaek |
require_once DWOO_DIRECTORY . 'Dwoo/Compiler.php'; |
|
| 4 |
dc33f4
|
Seldaek |
|
|
| 5 |
↓
|
Seldaek |
class FuncTests 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 testAssign() |
|
| 18 |
↓
|
Seldaek |
{ |
|
| 19 |
↓
|
Seldaek |
// test simple assign |
|
| 20 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{assign "bar" foo}{$foo}'); |
|
| 21 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 22 |
↓
|
Seldaek |
|
|
| 23 |
9cf6ad
|
Seldaek |
$tpl2 = new Dwoo_Template_String('{assign baz foo}{$foo}'); |
|
| 24 |
dc33f4
|
Seldaek |
$tpl2->forceCompilation(); |
|
| 25 |
↓
|
Seldaek |
|
|
| 26 |
↓
|
Seldaek |
$this->assertEquals('barbaz', $this->dwoo->get($tpl, array(), $this->compiler) . $this->dwoo->get($tpl2, array(), $this->compiler)); |
|
| 27 |
↓
|
Seldaek |
|
|
| 28 |
↓
|
Seldaek |
// test array assignation with function call |
|
| 29 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{assign reverse($foo) foo}{foreach $foo val}{$val}{/foreach}'); |
|
| 30 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 31 |
↓
|
Seldaek |
|
|
| 32 |
↓
|
Seldaek |
$this->assertEquals('321', $this->dwoo->get($tpl, array('foo'=>array(1,2,3)), $this->compiler)); |
|
| 33 |
↓
|
Seldaek |
} |
|
| 34 |
↓
|
Seldaek |
|
|
| 35 |
↓
|
Seldaek |
public function testCapitalize() |
|
| 36 |
↓
|
Seldaek |
{ |
|
| 37 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{capitalize "hello world 1st"}-{capitalize "hello world 1st" true}'); |
|
| 38 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 39 |
↓
|
Seldaek |
|
|
| 40 |
↓
|
Seldaek |
$this->assertEquals('Hello World 1st-Hello World 1St', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 41 |
05ec46
|
seldaek |
|
|
| 42 |
↓
|
seldaek |
$this->dwoo->setCharset('iso-8859-1'); |
|
| 43 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{capitalize "hello world 1st"}-{capitalize "hello world 1st" true}'); |
|
| 44 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 45 |
↓
|
seldaek |
$this->assertEquals('Hello World 1st-Hello World 1St', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 46 |
↓
|
seldaek |
$this->dwoo->setCharset('utf-8'); |
|
| 47 |
dc33f4
|
Seldaek |
} |
|
| 48 |
↓
|
Seldaek |
|
|
| 49 |
↓
|
Seldaek |
public function testCat() |
|
| 50 |
↓
|
Seldaek |
{ |
|
| 51 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{cat 3 bar "FOO"}'); |
|
| 52 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 53 |
↓
|
Seldaek |
|
|
| 54 |
↓
|
Seldaek |
$this->assertEquals('3barFOO', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 55 |
↓
|
Seldaek |
} |
|
| 56 |
↓
|
Seldaek |
|
|
| 57 |
↓
|
Seldaek |
public function testCounter() |
|
| 58 |
↓
|
Seldaek |
{ |
|
| 59 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{counter start=0 skip=2}{counter}{counter}{counter}'); |
|
| 60 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 61 |
↓
|
Seldaek |
|
|
| 62 |
↓
|
Seldaek |
$this->assertEquals('0246', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 63 |
↓
|
Seldaek |
|
|
| 64 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{counter start=0 skip=2 assign=foo}{counter}{counter}{counter}{$foo}'); |
|
| 65 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 66 |
↓
|
Seldaek |
|
|
| 67 |
↓
|
Seldaek |
$this->assertEquals('6', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 68 |
↓
|
Seldaek |
|
|
| 69 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{counter start=0 skip=2 assign=foo direction=down}{counter}{counter}{counter}{$foo}'); |
|
| 70 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 71 |
↓
|
Seldaek |
|
|
| 72 |
↓
|
Seldaek |
$this->assertEquals('-6', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 73 |
↓
|
Seldaek |
|
|
| 74 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{counter start=0 skip=3 print=false}{counter}{counter}{counter}{counter print=true}'); |
|
| 75 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 76 |
↓
|
Seldaek |
|
|
| 77 |
↓
|
Seldaek |
$this->assertEquals('12', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 78 |
05ec46
|
seldaek |
|
|
| 79 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{counter start=0 skip=3 print=false}{counter skip=1 start=10 assign=moo direction=down}{$moo}/{counter}{$moo}'); |
|
| 80 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 81 |
↓
|
seldaek |
$this->assertEquals('10/9', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 82 |
dc33f4
|
Seldaek |
} |
|
| 83 |
↓
|
Seldaek |
|
|
| 84 |
↓
|
Seldaek |
public function testCountChars() |
|
| 85 |
↓
|
Seldaek |
{ |
|
| 86 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{count_characters "hello world"}{count_characters "hello world" true}'); |
|
| 87 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 88 |
↓
|
Seldaek |
|
|
| 89 |
↓
|
Seldaek |
$this->assertEquals('1011', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 90 |
↓
|
Seldaek |
} |
|
| 91 |
↓
|
Seldaek |
|
|
| 92 |
↓
|
Seldaek |
public function testCountParagraphs() |
|
| 93 |
↓
|
Seldaek |
{ |
|
| 94 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{count_paragraphs $foo}'); |
|
| 95 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 96 |
↓
|
Seldaek |
|
|
| 97 |
↓
|
Seldaek |
$this->assertEquals('4', $this->dwoo->get($tpl, array('foo'=>"amdslfk smdkmsfd\nmsldkfmsldsdfml\nmlskfmlsdksdf\nmklsdspo"), $this->compiler)); |
|
| 98 |
↓
|
Seldaek |
} |
|
| 99 |
↓
|
Seldaek |
|
|
| 100 |
↓
|
Seldaek |
public function testCountSentences() |
|
| 101 |
↓
|
Seldaek |
{ |
|
| 102 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{count_sentences $foo}'); |
|
| 103 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 104 |
↓
|
Seldaek |
|
|
| 105 |
↓
|
Seldaek |
$this->assertEquals('4', $this->dwoo->get($tpl, array('foo'=>"amdslfk smdkmsfd.\nmsldkfmsldsdfml. sdfsml\nmlskfmlsdksdf... mklsdspo."), $this->compiler)); |
|
| 106 |
↓
|
Seldaek |
} |
|
| 107 |
↓
|
Seldaek |
|
|
| 108 |
↓
|
Seldaek |
public function testCountWords() |
|
| 109 |
↓
|
Seldaek |
{ |
|
| 110 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{count_words $foo}'); |
|
| 111 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 112 |
↓
|
Seldaek |
|
|
| 113 |
↓
|
Seldaek |
$this->assertEquals('5', $this->dwoo->get($tpl, array('foo'=>"sfsdf.smdf\nmkoep\tsdlk sdfsdf"), $this->compiler)); |
|
| 114 |
↓
|
Seldaek |
} |
|
| 115 |
↓
|
Seldaek |
|
|
| 116 |
↓
|
Seldaek |
public function testCycle() |
|
| 117 |
↓
|
Seldaek |
{ |
|
| 118 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{cycle "hoy" array(foo,bar) }{cycle hoy}{cycle hoy}{cycle name=hoy print=false}{cycle name="hoy"}{cycle name=hoy reset=true advance=false}{cycle name="hoy" advance=true}'); |
|
| 119 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 120 |
↓
|
Seldaek |
|
|
| 121 |
↓
|
Seldaek |
$this->assertEquals('foobarfoofoofoofoo', $this->dwoo->get($tpl, array('foo'=>"sfsdf.smdf\nmkoep\tsdlk sdfsdf"), $this->compiler)); |
|
| 122 |
05ec46
|
seldaek |
|
|
| 123 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{cycle "hoy" "foo,bar"}{cycle hoy}{cycle hoy assign="moo"}|{$moo}'); |
|
| 124 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 125 |
↓
|
seldaek |
|
|
| 126 |
↓
|
seldaek |
$this->assertEquals('foobar|foo', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 127 |
dc33f4
|
Seldaek |
} |
|
| 128 |
↓
|
Seldaek |
|
|
| 129 |
↓
|
Seldaek |
public function testDateFormat() |
|
| 130 |
↓
|
Seldaek |
{ |
|
| 131 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{date_format $dwoo.now "%Y%H:%M:%S"}{date_format $foo "%Y%H:%M:%S" "one hour ago"}{date_format ""}'); |
|
| 132 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 133 |
cfb65a
|
Seldaek |
$this->assertEquals(strftime("%Y%H:%M:%S", $_SERVER['REQUEST_TIME']).strftime('%Y%H:%M:%S', strtotime("one hour ago")), $this->dwoo->get($tpl, array('foo'=>''), $this->compiler)); |
|
| 134 |
05ec46
|
seldaek |
|
|
| 135 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{date_format "'.date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME'] - 10).'" "%Y:%H:%M:%S"}'); |
|
| 136 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 137 |
↓
|
seldaek |
$this->assertEquals(strftime("%Y:%H:%M:%S", $_SERVER['REQUEST_TIME'] - 10), $this->dwoo->get($tpl, array('foo'=>''), $this->compiler)); |
|
| 138 |
↓
|
seldaek |
|
|
| 139 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{date_format "" "%Y%H:%M:%S" '.($_SERVER['REQUEST_TIME'] - 10).'}'); |
|
| 140 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 141 |
↓
|
seldaek |
$this->assertEquals(strftime("%Y%H:%M:%S", $_SERVER['REQUEST_TIME'] - 10), $this->dwoo->get($tpl, array('foo'=>''), $this->compiler)); |
|
| 142 |
dc33f4
|
Seldaek |
} |
|
| 143 |
↓
|
Seldaek |
|
|
| 144 |
↓
|
Seldaek |
public function testDefault() |
|
| 145 |
↓
|
Seldaek |
{ |
|
| 146 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{default $foo bar}{default $foo2 bar}{default $foo3 bar}'); |
|
| 147 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 148 |
↓
|
Seldaek |
|
|
| 149 |
↓
|
Seldaek |
$this->assertEquals("barbarfoo3", $this->dwoo->get($tpl, array('foo2'=>"", 'foo3'=>"foo3"), $this->compiler)); |
|
| 150 |
↓
|
Seldaek |
} |
|
| 151 |
↓
|
Seldaek |
|
|
| 152 |
↓
|
Seldaek |
public function testDo() |
|
| 153 |
↓
|
Seldaek |
{ |
|
| 154 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{do assign($foo bar)}{do $bar}{$bar}'); |
|
| 155 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 156 |
↓
|
Seldaek |
|
|
| 157 |
↓
|
Seldaek |
$this->assertEquals("moo", $this->dwoo->get($tpl, array('foo'=>"moo"), $this->compiler)); |
|
| 158 |
↓
|
Seldaek |
} |
|
| 159 |
2f0eff
|
Seldaek |
|
|
| 160 |
↓
|
Seldaek |
public function testDoEmpty() |
|
| 161 |
↓
|
Seldaek |
{ |
|
| 162 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{do}'); |
|
| 163 |
2f0eff
|
Seldaek |
$tpl->forceCompilation(); |
|
| 164 |
↓
|
Seldaek |
|
|
| 165 |
↓
|
Seldaek |
$this->assertEquals("", $this->dwoo->get($tpl, array('foo'=>"moo"), $this->compiler)); |
|
| 166 |
↓
|
Seldaek |
} |
|
| 167 |
dc33f4
|
Seldaek |
|
|
| 168 |
dc0233
|
Seldaek |
public function testEol() |
|
| 169 |
↓
|
Seldaek |
{ |
|
| 170 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{eol}'); |
|
| 171 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 172 |
↓
|
Seldaek |
|
|
| 173 |
↓
|
Seldaek |
$this->assertEquals(PHP_EOL, $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 174 |
↓
|
Seldaek |
} |
|
| 175 |
↓
|
Seldaek |
|
|
| 176 |
dc33f4
|
Seldaek |
public function testEscape() |
|
| 177 |
↓
|
Seldaek |
{ |
|
| 178 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo}'); |
|
| 179 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 180 |
↓
|
Seldaek |
|
|
| 181 |
↓
|
Seldaek |
$this->assertEquals(""", $this->dwoo->get($tpl, array('foo'=>'"'), $this->compiler)); |
|
| 182 |
↓
|
Seldaek |
|
|
| 183 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo htmlall}'); |
|
| 184 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 185 |
↓
|
Seldaek |
|
|
| 186 |
↓
|
Seldaek |
$this->assertEquals("é", $this->dwoo->get($tpl, array('foo'=>'é'), $this->compiler)); |
|
| 187 |
↓
|
Seldaek |
|
|
| 188 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo htmlall iso-8859-1}'); |
|
| 189 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 190 |
↓
|
Seldaek |
|
|
| 191 |
↓
|
Seldaek |
$this->assertEquals("ü", $this->dwoo->get($tpl, array('foo'=>utf8_decode('ü')), $this->compiler)); |
|
| 192 |
↓
|
Seldaek |
|
|
| 193 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo url}'); |
|
| 194 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 195 |
↓
|
Seldaek |
|
|
| 196 |
↓
|
Seldaek |
$this->assertEquals(rawurlencode(':#?/'), $this->dwoo->get($tpl, array('foo'=>':#?/'), $this->compiler)); |
|
| 197 |
↓
|
Seldaek |
|
|
| 198 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo quotes}'); |
|
| 199 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 200 |
↓
|
Seldaek |
|
|
| 201 |
↓
|
Seldaek |
$this->assertEquals("\\'", $this->dwoo->get($tpl, array('foo'=>'\''), $this->compiler)); |
|
| 202 |
↓
|
Seldaek |
|
|
| 203 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo urlpathinfo}'); |
|
| 204 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 205 |
↓
|
Seldaek |
|
|
| 206 |
↓
|
Seldaek |
$this->assertEquals(rawurlencode(':#?').'/', $this->dwoo->get($tpl, array('foo'=>':#?/'), $this->compiler)); |
|
| 207 |
↓
|
Seldaek |
|
|
| 208 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo hex}'); |
|
| 209 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 210 |
↓
|
Seldaek |
|
|
| 211 |
↓
|
Seldaek |
$this->assertEquals('%0a', $this->dwoo->get($tpl, array('foo'=>chr(10)), $this->compiler)); |
|
| 212 |
↓
|
Seldaek |
|
|
| 213 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo hexentity}'); |
|
| 214 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 215 |
↓
|
Seldaek |
|
|
| 216 |
↓
|
Seldaek |
$this->assertEquals('
', $this->dwoo->get($tpl, array('foo'=>chr(10)), $this->compiler)); |
|
| 217 |
↓
|
Seldaek |
|
|
| 218 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo javascript}'); |
|
| 219 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 220 |
↓
|
Seldaek |
|
|
| 221 |
↓
|
Seldaek |
$this->assertEquals('\\\\n', $this->dwoo->get($tpl, array('foo'=>'\\n'), $this->compiler)); |
|
| 222 |
↓
|
Seldaek |
|
|
| 223 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{escape $foo mail}'); |
|
| 224 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 225 |
↓
|
Seldaek |
|
|
| 226 |
↓
|
Seldaek |
$this->assertEquals('test (AT) foo (DOT) bar', $this->dwoo->get($tpl, array('foo'=>'test@foo.bar'), $this->compiler)); |
|
| 227 |
↓
|
Seldaek |
} |
|
| 228 |
↓
|
Seldaek |
|
|
| 229 |
↓
|
Seldaek |
public function testEval() |
|
| 230 |
↓
|
Seldaek |
{ |
|
| 231 |
05ec46
|
seldaek |
$tpl = new Dwoo_Template_String('{eval $foo}{assign "baz" test}{eval $foo bar}+{$bar}{eval ""}'); |
|
| 232 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 233 |
↓
|
Seldaek |
|
|
| 234 |
↓
|
Seldaek |
$this->assertEquals("moo+baz", $this->dwoo->get($tpl, array('foo'=>'{$test}', 'test'=>'moo'), $this->compiler)); |
|
| 235 |
↓
|
Seldaek |
} |
|
| 236 |
↓
|
Seldaek |
|
|
| 237 |
2b587a
|
Seldaek |
public function testExtends() |
|
| 238 |
↓
|
Seldaek |
{ |
|
| 239 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_File(TEST_DIRECTORY.'/resources/extends/sub/test.html'); |
|
| 240 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 241 |
↓
|
Seldaek |
|
|
| 242 |
↓
|
Seldaek |
$this->assertEquals("<html>ThirdLevel</html>", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 243 |
↓
|
Seldaek |
} |
|
| 244 |
↓
|
Seldaek |
|
|
| 245 |
↓
|
Seldaek |
public function testExtendsVariation2() |
|
| 246 |
↓
|
Seldaek |
{ |
|
| 247 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_File(TEST_DIRECTORY.'/resources/extends/root.html'); |
|
| 248 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 249 |
↓
|
Seldaek |
|
|
| 250 |
↓
|
Seldaek |
$this->assertEquals("<html>Root</html>", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 251 |
↓
|
Seldaek |
} |
|
| 252 |
↓
|
Seldaek |
|
|
| 253 |
dc33f4
|
Seldaek |
public function testFetch() |
|
| 254 |
↓
|
Seldaek |
{ |
|
| 255 |
05ec46
|
seldaek |
$tpl = new Dwoo_Template_String('{fetch file="'.TEST_DIRECTORY.'/resources/test.html"}{fetch ""}{fetch file="'.TEST_DIRECTORY.'/resources/test.html" assign="boo"}|{$boo}'); |
|
| 256 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 257 |
↓
|
Seldaek |
|
|
| 258 |
05ec46
|
seldaek |
$this->assertEquals('{$foo}{$bar}|{$foo}{$bar}', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 259 |
dc33f4
|
Seldaek |
} |
|
| 260 |
↓
|
Seldaek |
|
|
| 261 |
↓
|
Seldaek |
public function testInclude() |
|
| 262 |
↓
|
Seldaek |
{ |
|
| 263 |
5b6806
|
Seldaek |
$tpl = new Dwoo_Template_String('{include file=\'file:'.TEST_DIRECTORY.'/resources/test.html\' foo=$a bar=$b}'); |
|
| 264 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 265 |
↓
|
Seldaek |
|
|
| 266 |
↓
|
Seldaek |
$this->assertEquals("AB", $this->dwoo->get($tpl, array('a'=>'A', 'b'=>'B'))); |
|
| 267 |
↓
|
Seldaek |
|
|
| 268 |
05ec46
|
seldaek |
$tpl = new Dwoo_Template_String('{include file="" foo=$a bar=$b}'); |
|
| 269 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 270 |
↓
|
seldaek |
$this->assertEquals("", $this->dwoo->get($tpl, array('a'=>'A', 'b'=>'B'))); |
|
| 271 |
↓
|
seldaek |
|
|
| 272 |
5b6806
|
Seldaek |
$tpl = new Dwoo_Template_String('{include file=\'file:'.TEST_DIRECTORY.'/resources/test.html\'}'); |
|
| 273 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 274 |
↓
|
Seldaek |
|
|
| 275 |
↓
|
Seldaek |
$this->assertEquals("ab", $this->dwoo->get($tpl, array('foo'=>'a', 'bar'=>'b'), $this->compiler)); |
|
| 276 |
↓
|
Seldaek |
|
|
| 277 |
848d2a
|
Seldaek |
$tpl = new Dwoo_Template_File(TEST_DIRECTORY.'/resources/inctest.html'); |
|
| 278 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 279 |
↓
|
Seldaek |
|
|
| 280 |
848d2a
|
Seldaek |
$this->assertEquals("34", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 281 |
↓
|
Seldaek |
} |
|
| 282 |
dc33f4
|
Seldaek |
|
|
| 283 |
848d2a
|
Seldaek |
public function testIncludeString() |
|
| 284 |
↓
|
Seldaek |
{ |
|
| 285 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{include file=$tpl foo=$a bar=$b}'); |
|
| 286 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 287 |
↓
|
Seldaek |
|
|
| 288 |
848d2a
|
Seldaek |
$this->assertEquals("AB", $this->dwoo->get($tpl, array('a'=>'A', 'b'=>'B', 'tpl'=>'{$a}{$b}'))); |
|
| 289 |
dc33f4
|
Seldaek |
} |
|
| 290 |
↓
|
Seldaek |
|
|
| 291 |
57022c
|
Seldaek |
public function testIncludeParent() |
|
| 292 |
↓
|
Seldaek |
{ |
|
| 293 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_File(TEST_DIRECTORY.'/resources/subfolder/inctest.html'); |
|
| 294 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 295 |
↓
|
Seldaek |
|
|
| 296 |
↓
|
Seldaek |
$this->assertEquals("43", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 297 |
↓
|
Seldaek |
} |
|
| 298 |
↓
|
Seldaek |
|
|
| 299 |
dc33f4
|
Seldaek |
public function testIndent() |
|
| 300 |
↓
|
Seldaek |
{ |
|
| 301 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{indent $foo 6 "-"}'); |
|
| 302 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 303 |
↓
|
Seldaek |
|
|
| 304 |
↓
|
Seldaek |
$this->assertEquals("------FOO\n------BAR", $this->dwoo->get($tpl, array('foo'=>"FOO\nBAR"), $this->compiler)); |
|
| 305 |
↓
|
Seldaek |
} |
|
| 306 |
↓
|
Seldaek |
|
|
| 307 |
↓
|
Seldaek |
public function testIsset() |
|
| 308 |
↓
|
Seldaek |
{ |
|
| 309 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{if isset($foo)}set{else}not set{/if}'); |
|
| 310 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 311 |
↓
|
Seldaek |
$this->assertEquals("not set", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 312 |
↓
|
Seldaek |
$this->assertEquals("set", $this->dwoo->get($tpl, array('foo'=>'a'), $this->compiler)); |
|
| 313 |
↓
|
Seldaek |
$this->assertEquals("set", $this->dwoo->get($tpl, array('foo'=>''), $this->compiler)); |
|
| 314 |
↓
|
Seldaek |
} |
|
| 315 |
↓
|
Seldaek |
|
|
| 316 |
↓
|
Seldaek |
public function testLower() |
|
| 317 |
↓
|
Seldaek |
{ |
|
| 318 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{lower "FOO"}'); |
|
| 319 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 320 |
↓
|
Seldaek |
|
|
| 321 |
↓
|
Seldaek |
$this->assertEquals("foo", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 322 |
↓
|
Seldaek |
} |
|
| 323 |
↓
|
Seldaek |
|
|
| 324 |
↓
|
Seldaek |
public function testMailto() |
|
| 325 |
↓
|
Seldaek |
{ |
|
| 326 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{mailto address="me@example.com" encode="jschar"}'); |
|
| 327 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 328 |
↓
|
Seldaek |
|
|
| 329 |
↓
|
Seldaek |
$this->assertEquals('<script type="text/javascript">'."\n".'<!--'."\n".'document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,109,101,64,101,120,97,109,112,108,101,46,99,111,109,34,32,62,109,101,64,101,120,97,109,112,108,101,46,99,111,109,60,47,97,62));'."\n".'-->'."\n".'</script>'."\n", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 330 |
↓
|
Seldaek |
|
|
| 331 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{mailto address="me@example.com" text="send me some mail"}'); |
|
| 332 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 333 |
↓
|
Seldaek |
|
|
| 334 |
↓
|
Seldaek |
$this->assertEquals('<a href="mailto:me@example.com" >send me some mail</a>', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 335 |
↓
|
Seldaek |
|
|
| 336 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{mailto address="me@example.com" encode="javascript"}'); |
|
| 337 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 338 |
↓
|
Seldaek |
|
|
| 339 |
↓
|
Seldaek |
$this->assertEquals('<script type="text/javascript">eval(unescape(\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%22%20%3e%6d%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%3c%2f%61%3e%27%29%3b\'));</script>', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 340 |
↓
|
Seldaek |
|
|
| 341 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{mailto address="me@example.com" encode="hex"}'); |
|
| 342 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 343 |
↓
|
Seldaek |
|
|
| 344 |
↓
|
Seldaek |
$this->assertEquals('<a href="mailto:%6d%65@%65%78%61%6d%70%6c%65.%63%6f%6d" >me@example.com</a>', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 345 |
↓
|
Seldaek |
|
|
| 346 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{mailto address="me@example.com" subject="Hello to you!" cc="you@example.com,they@example.com" extra=\'class="email"\'}'); |
|
| 347 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 348 |
↓
|
Seldaek |
$this->assertEquals('<a href="mailto:me@example.com?subject=Hello%20to%20you%21&cc=you%40example.com%2Cthey%40example.com" class="email">me@example.com</a>', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 349 |
05ec46
|
seldaek |
|
|
| 350 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{mailto address="" subject="Hello to you!" cc="you@example.com,they@example.com" extra=\'class="email"\'}'); |
|
| 351 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 352 |
↓
|
seldaek |
$this->assertEquals('', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 353 |
↓
|
seldaek |
|
|
| 354 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{mailto address="me@example.com" subject="Hello to you!" bcc="moo" newsgroups="bleh" followupto="meh"}'); |
|
| 355 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 356 |
↓
|
seldaek |
$this->assertEquals('<a href="mailto:me@example.com?subject=Hello%20to%20you%21&bcc=moo&newsgroups=bleh&followupto=meh" >me@example.com</a>', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 357 |
dc33f4
|
Seldaek |
} |
|
| 358 |
↓
|
Seldaek |
|
|
| 359 |
↓
|
Seldaek |
public function testMath() |
|
| 360 |
↓
|
Seldaek |
{ |
|
| 361 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{math equation="3+5+a+b" a="100" b="20"}'); |
|
| 362 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 363 |
↓
|
Seldaek |
|
|
| 364 |
↓
|
Seldaek |
$this->assertEquals((string)(3+5+100+20), $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 365 |
↓
|
Seldaek |
|
|
| 366 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{math equation="3+5+`$a`+b" b="20"}'); |
|
| 367 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 368 |
↓
|
Seldaek |
|
|
| 369 |
↓
|
Seldaek |
$this->assertEquals((string)(3+5+100+20), $this->dwoo->get($tpl, array('a'=>100), $this->compiler)); |
|
| 370 |
↓
|
Seldaek |
|
|
| 371 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{math equation="3+5+cos(a)" a="1"}'); |
|
| 372 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 373 |
↓
|
Seldaek |
|
|
| 374 |
↓
|
Seldaek |
$this->assertEquals((string)(3+5+cos(1)), $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 375 |
↓
|
Seldaek |
|
|
| 376 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{math equation="3+5+(cos(a) + max(3,2))" a="1"}'); |
|
| 377 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 378 |
↓
|
Seldaek |
|
|
| 379 |
↓
|
Seldaek |
$this->assertEquals((string)(3+5+(cos(1) + max(3,2))), $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 380 |
↓
|
Seldaek |
|
|
| 381 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{math equation="3+5+(cos(a) + max(3,2))" a="1" assign="foo"}-{$foo}'); |
|
| 382 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 383 |
↓
|
Seldaek |
|
|
| 384 |
↓
|
Seldaek |
$this->assertEquals('-'.(3+5+(cos(1) + max(3,2))), $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 385 |
05ec46
|
seldaek |
|
|
| 386 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{math equation="max((1+2),2)"}'); |
|
| 387 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 388 |
↓
|
seldaek |
|
|
| 389 |
↓
|
seldaek |
$this->assertEquals('3', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 390 |
↓
|
seldaek |
|
|
| 391 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{math equation="1/3" format="%.4f"}'); |
|
| 392 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 393 |
↓
|
seldaek |
|
|
| 394 |
↓
|
seldaek |
$this->assertEquals('0.3333', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 395 |
dc33f4
|
Seldaek |
} |
|
| 396 |
↓
|
Seldaek |
|
|
| 397 |
↓
|
Seldaek |
public function testNl2br() |
|
| 398 |
↓
|
Seldaek |
{ |
|
| 399 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{nl2br "f |
|
| 400 |
dc33f4
|
Seldaek |
a"}'); |
|
| 401 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 402 |
↓
|
Seldaek |
|
|
| 403 |
937188
|
Seldaek |
$this->assertEquals("f<br />\na", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 404 |
dc33f4
|
Seldaek |
} |
|
| 405 |
↓
|
Seldaek |
|
|
| 406 |
↓
|
Seldaek |
public function testRegexReplace() |
|
| 407 |
↓
|
Seldaek |
{ |
|
| 408 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{regex_replace "FOOMOO" "/OO\$/" "L"}'); |
|
| 409 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 410 |
↓
|
Seldaek |
|
|
| 411 |
↓
|
Seldaek |
$this->assertEquals("FOOML", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 412 |
↓
|
Seldaek |
|
|
| 413 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{regex_replace "FOOMOO" "/OO\$/e" "die"}'); |
|
| 414 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 415 |
↓
|
Seldaek |
|
|
| 416 |
↓
|
Seldaek |
$this->assertEquals("FOOMdie", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 417 |
↓
|
Seldaek |
} |
|
| 418 |
↓
|
Seldaek |
|
|
| 419 |
↓
|
Seldaek |
public function testReplace() |
|
| 420 |
↓
|
Seldaek |
{ |
|
| 421 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{replace "FOOMOO" "OO" "L"}'); |
|
| 422 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 423 |
↓
|
Seldaek |
|
|
| 424 |
↓
|
Seldaek |
$this->assertEquals("FLML", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 425 |
b9a093
|
Seldaek |
|
|
| 426 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{replace "FOOMOO" "oo" "l" off}'); |
|
| 427 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 428 |
↓
|
Seldaek |
|
|
| 429 |
↓
|
Seldaek |
$this->assertEquals("FlMl", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 430 |
dc33f4
|
Seldaek |
} |
|
| 431 |
↓
|
Seldaek |
|
|
| 432 |
cb80c4
|
seldaek |
public function testReturn() |
|
| 433 |
↓
|
seldaek |
{ |
|
| 434 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{return bar=$foo}'); |
|
| 435 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 436 |
↓
|
seldaek |
$this->dwoo->get($tpl, array('foo' => 'FOO'), $this->compiler); |
|
| 437 |
↓
|
seldaek |
|
|
| 438 |
↓
|
seldaek |
$this->assertEquals(array('bar'=>'FOO'), $this->dwoo->getReturnValues()); |
|
| 439 |
↓
|
seldaek |
} |
|
| 440 |
↓
|
seldaek |
|
|
| 441 |
↓
|
seldaek |
public function testReturnViaInclude() |
|
| 442 |
↓
|
seldaek |
{ |
|
| 443 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{include cat("file:" %TEST_DIRECTORY "/resources/returnTest.html") val="foo"}{$bar}'); |
|
| 444 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 445 |
↓
|
seldaek |
|
|
| 446 |
↓
|
seldaek |
$this->assertEquals('FOO', $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 447 |
↓
|
seldaek |
} |
|
| 448 |
↓
|
seldaek |
|
|
| 449 |
dc33f4
|
Seldaek |
public function testReverse() |
|
| 450 |
↓
|
Seldaek |
{ |
|
| 451 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{reverse "abc"}'); |
|
| 452 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 453 |
↓
|
Seldaek |
|
|
| 454 |
↓
|
Seldaek |
$this->assertEquals("cba", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 455 |
↓
|
Seldaek |
|
|
| 456 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{foreach reverse(array(a,b,c)) foo}{$foo}{/foreach}'); |
|
| 457 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 458 |
↓
|
Seldaek |
|
|
| 459 |
↓
|
Seldaek |
$this->assertEquals("cba", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 460 |
05ec46
|
seldaek |
|
|
| 461 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{reverse "abc"}'); |
|
| 462 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 463 |
↓
|
seldaek |
$this->dwoo->setCharset('iso-8859-1'); |
|
| 464 |
↓
|
seldaek |
$this->assertEquals("cba", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 465 |
↓
|
seldaek |
$this->dwoo->setCharset('utf-8'); |
|
| 466 |
dc33f4
|
Seldaek |
} |
|
| 467 |
↓
|
Seldaek |
|
|
| 468 |
↓
|
Seldaek |
public function testSpacify() |
|
| 469 |
↓
|
Seldaek |
{ |
|
| 470 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{spacify "ABC" "+"}'); |
|
| 471 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 472 |
↓
|
Seldaek |
|
|
| 473 |
↓
|
Seldaek |
$this->assertEquals("A+B+C", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 474 |
↓
|
Seldaek |
} |
|
| 475 |
↓
|
Seldaek |
|
|
| 476 |
↓
|
Seldaek |
public function testStringFormat() |
|
| 477 |
↓
|
Seldaek |
{ |
|
| 478 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{string_format 53.3942 "%.2f"}'); |
|
| 479 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 480 |
↓
|
Seldaek |
|
|
| 481 |
↓
|
Seldaek |
$this->assertEquals("53.39", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 482 |
↓
|
Seldaek |
} |
|
| 483 |
↓
|
Seldaek |
|
|
| 484 |
↓
|
Seldaek |
public function testStripTags() |
|
| 485 |
↓
|
Seldaek |
{ |
|
| 486 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{strip_tags "<a href=\'foo\'>test</a>test"}'); |
|
| 487 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 488 |
↓
|
Seldaek |
|
|
| 489 |
↓
|
Seldaek |
$this->assertEquals(" test test", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 490 |
↓
|
Seldaek |
|
|
| 491 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{strip_tags "<a href=\'foo\'>test</a>test" false}'); |
|
| 492 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 493 |
↓
|
Seldaek |
|
|
| 494 |
↓
|
Seldaek |
$this->assertEquals("testtest", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 495 |
↓
|
Seldaek |
} |
|
| 496 |
↓
|
Seldaek |
|
|
| 497 |
c6133a
|
Seldaek |
public function testWhitespace() |
|
| 498 |
dc33f4
|
Seldaek |
{ |
|
| 499 |
c6133a
|
Seldaek |
$tpl = new Dwoo_Template_String('{whitespace "a b c d"}'); |
|
| 500 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 501 |
↓
|
Seldaek |
|
|
| 502 |
↓
|
Seldaek |
$this->assertEquals("a b c d", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 503 |
↓
|
Seldaek |
} |
|
| 504 |
↓
|
Seldaek |
|
|
| 505 |
1d3732
|
Seldaek |
public function testTif() |
|
| 506 |
↓
|
Seldaek |
{ |
|
| 507 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{tif $a && $b && 3==3 ? foo : bar}'); |
|
| 508 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 509 |
↓
|
Seldaek |
|
|
| 510 |
↓
|
Seldaek |
$this->assertEquals("foo", $this->dwoo->get($tpl, array('a'=>true, 'b'=>3), $this->compiler)); |
|
| 511 |
↓
|
Seldaek |
|
|
| 512 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{tif $a && $b && 3==3 foo bar}'); |
|
| 513 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 514 |
↓
|
Seldaek |
|
|
| 515 |
↓
|
Seldaek |
$this->assertEquals("bar", $this->dwoo->get($tpl, array('a'=>true, 'b'=>0), $this->compiler)); |
|
| 516 |
↓
|
Seldaek |
|
|
| 517 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{tif $a foo bar}'); |
|
| 518 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 519 |
↓
|
Seldaek |
|
|
| 520 |
↓
|
Seldaek |
$this->assertEquals("foo", $this->dwoo->get($tpl, array('a'=>true, 'b'=>0), $this->compiler)); |
|
| 521 |
↓
|
Seldaek |
|
|
| 522 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{tif $a?"foo":"bar"}'); |
|
| 523 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 524 |
↓
|
Seldaek |
|
|
| 525 |
↓
|
Seldaek |
$this->assertEquals("foo", $this->dwoo->get($tpl, array('a'=>true, 'b'=>0), $this->compiler)); |
|
| 526 |
↓
|
Seldaek |
|
|
| 527 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{tif $a?foo:bar}'); |
|
| 528 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 529 |
↓
|
Seldaek |
|
|
| 530 |
↓
|
Seldaek |
$this->assertEquals("foo", $this->dwoo->get($tpl, array('a'=>true, 'b'=>0), $this->compiler)); |
|
| 531 |
↓
|
Seldaek |
|
|
| 532 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{tif $a ? foo}'); |
|
| 533 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 534 |
↓
|
Seldaek |
|
|
| 535 |
↓
|
Seldaek |
$this->assertEquals("foo", $this->dwoo->get($tpl, array('a'=>true, 'b'=>0), $this->compiler)); |
|
| 536 |
↓
|
Seldaek |
|
|
| 537 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{tif $a foo}'); |
|
| 538 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 539 |
↓
|
Seldaek |
|
|
| 540 |
↓
|
Seldaek |
$this->assertEquals("foo", $this->dwoo->get($tpl, array('a'=>true, 'b'=>0), $this->compiler)); |
|
| 541 |
↓
|
Seldaek |
|
|
| 542 |
↓
|
Seldaek |
$tpl = new Dwoo_Template_String('{tif $a ?: foo}'); |
|
| 543 |
↓
|
Seldaek |
$tpl->forceCompilation(); |
|
| 544 |
↓
|
Seldaek |
|
|
| 545 |
↓
|
Seldaek |
$this->assertEquals("1", $this->dwoo->get($tpl, array('a'=>true, 'b'=>0), $this->compiler)); |
|
| 546 |
↓
|
Seldaek |
} |
|
| 547 |
↓
|
Seldaek |
|
|
| 548 |
dc33f4
|
Seldaek |
public function testTruncate() |
|
| 549 |
↓
|
Seldaek |
{ |
|
| 550 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{truncate "abcdefghijklmnopqrstuvwxyz" 20 "..." true}'); |
|
| 551 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 552 |
↓
|
Seldaek |
$this->assertEquals("abcdefghijklmnopq...", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 553 |
↓
|
Seldaek |
|
|
| 554 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{truncate "abcdefghijklmnopqrstuvwxyz" 20 "..." true true}'); |
|
| 555 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 556 |
↓
|
Seldaek |
$this->assertEquals("abcdefghi...stuvwxyz", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 557 |
05ec46
|
seldaek |
|
|
| 558 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{truncate "" 20 "..." true true}'); |
|
| 559 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 560 |
↓
|
seldaek |
$this->assertEquals("", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 561 |
↓
|
seldaek |
|
|
| 562 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{truncate "a" 20 "..." true true}'); |
|
| 563 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 564 |
↓
|
seldaek |
$this->assertEquals("a", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 565 |
↓
|
seldaek |
|
|
| 566 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{truncate "abcdefghijklmnopqrstuvwxyz abcdef" 20 "..."}'); |
|
| 567 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 568 |
↓
|
seldaek |
$this->assertEquals("abcdefghijklmnopq...", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 569 |
↓
|
seldaek |
|
|
| 570 |
↓
|
seldaek |
$tpl = new Dwoo_Template_String('{truncate "abc abc abc abc abc abc" 10 "..."}'); |
|
| 571 |
↓
|
seldaek |
$tpl->forceCompilation(); |
|
| 572 |
↓
|
seldaek |
$this->assertEquals("abc abc...", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 573 |
dc33f4
|
Seldaek |
} |
|
| 574 |
↓
|
Seldaek |
|
|
| 575 |
↓
|
Seldaek |
public function testUpper() |
|
| 576 |
↓
|
Seldaek |
{ |
|
| 577 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{upper "foo"}'); |
|
| 578 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 579 |
↓
|
Seldaek |
|
|
| 580 |
↓
|
Seldaek |
$this->assertEquals("FOO", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 581 |
↓
|
Seldaek |
} |
|
| 582 |
↓
|
Seldaek |
|
|
| 583 |
↓
|
Seldaek |
public function testWordwrap() |
|
| 584 |
↓
|
Seldaek |
{ |
|
| 585 |
9cf6ad
|
Seldaek |
$tpl = new Dwoo_Template_String('{wordwrap "abcdefghijklmnopqrstuvwxyz" 8 "\n" true}'); |
|
| 586 |
dc33f4
|
Seldaek |
$tpl->forceCompilation(); |
|
| 587 |
↓
|
Seldaek |
|
|
| 588 |
↓
|
Seldaek |
$this->assertEquals("abcdefgh\nijklmnop\nqrstuvwx\nyz", $this->dwoo->get($tpl, array(), $this->compiler)); |
|
| 589 |
↓
|
Seldaek |
} |
|
| 590 |
↓
|
Seldaek |
} |
|