Arbit - project tracking

Dwoo

Browse source code

File: / tests/ BugTests.php

Type
text/plain text/plain
Last Author
seldaek
Version
9315dcc815b5063f6212c06dd2c20b8b75004434
Line Rev. Author Source
1 390861 Seldaek <?php
2 Seldaek
3 dd288f Seldaek require_once DWOO_DIRECTORY . 'Dwoo/Compiler.php';
4 390861 Seldaek
5 Seldaek class BugTests 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 $this->compiler = new Dwoo_Compiler();
13 9315dc seldaek $this->dwoo = new Dwoo_Core(DWOO_COMPILE_DIR, DWOO_CACHE_DIR);
14 390861 Seldaek }
15 Seldaek
16 Seldaek public function testBlockStackBufferingBug()
17 Seldaek {
18 Seldaek $tpl = new Dwoo_Template_String('{textformat 10 wrap_char="\n"}here is some text that should wrap{/textformat}
19 Seldaek {textformat 10 wrap_cut=true wrap_char="\n"}and this one should cut words that go beyooooooond 10 chars{/textformat}');
20 Seldaek $tpl->forceCompilation();
21 Seldaek
22 Seldaek $this->assertEquals("here is\nsome text\nthat\nshould\nwrap\nand this\none should\ncut words\nthat go\nbeyooooooo\nnd 10\nchars", $this->dwoo->get($tpl, array()));
23 Seldaek }
24 f1a184 Seldaek
25 Seldaek public function testSpaceBeforeArgsBug()
26 Seldaek {
27 Seldaek $tpl = new Dwoo_Template_String('{upper ("moo")}.{upper ("moo")}.{if (true) && (true)}MOO{/if}');
28 Seldaek $tpl->forceCompilation();
29 Seldaek
30 Seldaek $this->assertEquals("MOO.MOO.MOO", $this->dwoo->get($tpl, array()));
31 Seldaek }
32 23a6b7 Seldaek
33 Seldaek public function testEmptyStringArgInModifierCall()
34 Seldaek {
35 Seldaek $tpl = new Dwoo_Template_String('{$var|replace:"foo":""}');
36 Seldaek $tpl->forceCompilation();
37 Seldaek
38 Seldaek $this->assertEquals("ab", $this->dwoo->get($tpl, array('var'=>'afoob')));
39 Seldaek }
40 Seldaek
41 Seldaek public function testRecursiveVarModifiersCalls()
42 Seldaek {
43 Seldaek $tpl = new Dwoo_Template_String('{$var|replace:array("foo", "bar"):array("")}');
44 Seldaek $tpl->forceCompilation();
45 Seldaek
46 Seldaek $this->assertEquals("abc", $this->dwoo->get($tpl, array('var'=>'afoobbarc')));
47 Seldaek }
48 Seldaek
49 Seldaek public function testVarModifierCallWithSpaces()
50 Seldaek {
51 Seldaek $tpl = new Dwoo_Template_String('{"x$var|replace:array(\'foo\', bar):array(\"\") y"}');
52 Seldaek $tpl->forceCompilation();
53 Seldaek
54 Seldaek $this->assertEquals("xabc y", $this->dwoo->get($tpl, array('var'=>'afoobbarc')));
55 Seldaek }
56 Seldaek
57 Seldaek public function testVarModifierCallWithDelimiters()
58 Seldaek {
59 Seldaek $tpl = new Dwoo_Template_String('{"x`$var|replace:array(\'foo\', bar):array(\"\")`y"}');
60 Seldaek $tpl->forceCompilation();
61 Seldaek
62 Seldaek $this->assertEquals("xabcy", $this->dwoo->get($tpl, array('var'=>'afoobbarc')));
63 Seldaek }
64 Seldaek
65 Seldaek public function testStringModifierInOtherCall()
66 Seldaek {
67 Seldaek $tpl = new Dwoo_Template_String('{cat "f o o"|replace:" ":"" "xx"}');
68 Seldaek $tpl->forceCompilation();
69 Seldaek
70 Seldaek $this->assertEquals("fooxx", $this->dwoo->get($tpl, array()));
71 Seldaek }
72 b84956 Seldaek
73 Seldaek public function testPhpTagWithoutSemicolon()
74 Seldaek {
75 Seldaek $tpl = new Dwoo_Template_String('{capture "foo"}<?php $var=3; echo $var ?>{/capture}-{$.capture.foo}');
76 Seldaek $tpl->forceCompilation();
77 Seldaek
78 Seldaek $this->assertEquals("-3", $this->dwoo->get($tpl, array()));
79 Seldaek }
80 691afc Seldaek
81 Seldaek public function testUppercasePlugin()
82 Seldaek {
83 Seldaek $tpl = new Dwoo_Template_String('{X foo}');
84 Seldaek $tpl->forceCompilation();
85 Seldaek
86 Seldaek $this->assertEquals("foo", $this->dwoo->get($tpl, array()));
87 Seldaek }
88 Seldaek
89 Seldaek public function testMultilineAssignments()
90 Seldaek {
91 Seldaek $tpl = new Dwoo_Template_String('{$foo = array(
92 Seldaek moo=bar
93 Seldaek foo=baz
94 Seldaek )}{foreach $foo k v}{$k; $v}.{/foreach}');
95 Seldaek $tpl->forceCompilation();
96 Seldaek
97 Seldaek $this->assertEquals("moobar.foobaz.", $this->dwoo->get($tpl, array()));
98 Seldaek }
99 Seldaek
100 93275b seldaek public function testAssignmentsWithAutoEscape()
101 seldaek {
102 seldaek $cmp = new Dwoo_Compiler();
103 seldaek $cmp->setAutoEscape(true);
104 seldaek $tpl = new Dwoo_Template_String('{$foo = $bar}>{$foo}');
105 seldaek $tpl->forceCompilation();
106 seldaek
107 seldaek $this->assertEquals(">moo", $this->dwoo->get($tpl, array('bar'=>'moo'), $cmp));
108 seldaek }
109 seldaek
110 691afc Seldaek public function testAndOrOperatorsFollowedWithRoundBrackets()
111 Seldaek {
112 Seldaek $tpl = new Dwoo_Template_String('{if 1 AND (0 OR 1)}true{/if}');
113 Seldaek $tpl->forceCompilation();
114 Seldaek
115 Seldaek $this->assertEquals("true", $this->dwoo->get($tpl, array()));
116 Seldaek }
117 93275b seldaek
118 seldaek public function testMultipleVarsWithStringKey()
119 seldaek {
120 seldaek $tpl = new Dwoo_Template_String('{$foo["bar"]}{$foo["baz"]}');
121 seldaek $tpl->forceCompilation();
122 seldaek
123 seldaek $this->assertEquals("12", $this->dwoo->get($tpl, array('foo'=>array('bar'=>1, 'baz'=>2))));
124 seldaek }
125 f71d42 seldaek
126 seldaek public function testTopCommentParsingWithWhitespaceAtTheEnd()
127 seldaek {
128 seldaek $tpl = new Dwoo_Template_String('{* Foo *}
129 seldaek aaa
130 seldaek ');
131 seldaek $tpl->forceCompilation();
132 seldaek
133 seldaek $this->assertEquals('aaa
134 seldaek ', $this->dwoo->get($tpl, array()));
135 seldaek }
136 seldaek
137 seldaek public function testTopCommentParsingWithWhitespaceAtTheEndAndBeginning()
138 seldaek {
139 seldaek $tpl = new Dwoo_Template_String(' {* Foo *}
140 seldaek aaa
141 seldaek ');
142 seldaek $tpl->forceCompilation();
143 seldaek
144 seldaek $this->assertEquals('
145 seldaek aaa
146 seldaek ', $this->dwoo->get($tpl, array()));
147 seldaek }
148 390861 Seldaek }
149 691afc Seldaek
150 Seldaek function Dwoo_Plugin_X_compile(Dwoo_Compiler $cmp, $text)
151 Seldaek {
152 Seldaek return $text;
153 Seldaek }