@@ -36,4 +36,184 @@ public function testIfStatementsAreRemovedIfReplacementIsNotSet()
3636 $ this ->assertContains ('bar ' , $ parsed );
3737 $ this ->assertNotContains ('qux ' , $ parsed );
3838 }
39+
40+ public function testEqualToIfStatementIsReplacedIfTrue ()
41+ {
42+ $ parser = $ this ->parser ();
43+
44+ $ template = '{{ foo }} [if:baz == \'qux \'] {{ baz }} [endif] ' ;
45+
46+ $ parsed = $ parser ->parse ($ template , [
47+ 'foo ' => 'bar ' ,
48+ 'baz ' => 'qux '
49+ ]);
50+
51+ $ this ->assertContains ('bar ' , $ parsed );
52+ $ this ->assertContains ('qux ' , $ parsed );
53+ }
54+
55+ public function testEqualToIfStatementIsNotReplacedIfFalse ()
56+ {
57+ $ parser = $ this ->parser ();
58+
59+ $ template = '{{ foo }} [if:baz == \'foo \'] {{ baz }} [endif] ' ;
60+
61+ $ parsed = $ parser ->parse ($ template , [
62+ 'foo ' => 'bar ' ,
63+ 'baz ' => 'qux '
64+ ]);
65+
66+ $ this ->assertContains ('bar ' , $ parsed );
67+ $ this ->assertNotContains ('qux ' , $ parsed );
68+ }
69+
70+ public function testEqualToIfDoesNotEqualStatementIsReplacedIfTrue ()
71+ {
72+ $ parser = $ this ->parser ();
73+
74+ $ template = '{{ foo }} [if:baz != \'foo \'] {{ baz }} [endif] ' ;
75+
76+ $ parsed = $ parser ->parse ($ template , [
77+ 'foo ' => 'bar ' ,
78+ 'baz ' => 'qux '
79+ ]);
80+
81+ $ this ->assertContains ('bar ' , $ parsed );
82+ $ this ->assertContains ('qux ' , $ parsed );
83+ }
84+
85+ public function testEqualToIfDoesNotEqualStatementIsNotReplacedIfFalse ()
86+ {
87+ $ parser = $ this ->parser ();
88+
89+ $ template = '{{ foo }} [if:baz != \'qux \'] {{ baz }} [endif] ' ;
90+
91+ $ parsed = $ parser ->parse ($ template , [
92+ 'foo ' => 'bar ' ,
93+ 'baz ' => 'qux '
94+ ]);
95+
96+ $ this ->assertContains ('bar ' , $ parsed );
97+ $ this ->assertNotContains ('qux ' , $ parsed );
98+ }
99+
100+ public function testEqualToIfGreaterThanStatementIsReplacedIfTrue ()
101+ {
102+ $ parser = $ this ->parser ();
103+
104+ $ template = '{{ foo }} [if:baz > 0] {{ baz }} [endif] ' ;
105+
106+ $ parsed = $ parser ->parse ($ template , [
107+ 'foo ' => 'bar ' ,
108+ 'baz ' => 1
109+ ]);
110+
111+ $ this ->assertContains ('bar ' , $ parsed );
112+ $ this ->assertContains ('1 ' , $ parsed );
113+ }
114+
115+ public function testEqualToIfGreaterThanStatementIsNotReplacedIfFalse ()
116+ {
117+ $ parser = $ this ->parser ();
118+
119+ $ template = '{{ foo }} [if:baz > 5] {{ baz }} [endif] ' ;
120+
121+ $ parsed = $ parser ->parse ($ template , [
122+ 'foo ' => 'bar ' ,
123+ 'baz ' => 2
124+ ]);
125+
126+ $ this ->assertContains ('bar ' , $ parsed );
127+ $ this ->assertNotContains ('2 ' , $ parsed );
128+ }
129+
130+ public function testEqualToIfGreaterThanOrEqualStatementIsReplacedIfTrue ()
131+ {
132+ $ parser = $ this ->parser ();
133+
134+ $ template = '{{ foo }} [if:baz >= 1] {{ baz }} [endif] ' ;
135+
136+ $ parsed = $ parser ->parse ($ template , [
137+ 'foo ' => 'bar ' ,
138+ 'baz ' => 1
139+ ]);
140+
141+ $ this ->assertContains ('bar ' , $ parsed );
142+ $ this ->assertContains ('1 ' , $ parsed );
143+ }
144+
145+ public function testEqualToIfGreaterThanOrEqualStatementIsNotReplacedIfFalse ()
146+ {
147+ $ parser = $ this ->parser ();
148+
149+ $ template = '{{ foo }} [if:baz >= 5] {{ baz }} [endif] ' ;
150+
151+ $ parsed = $ parser ->parse ($ template , [
152+ 'foo ' => 'bar ' ,
153+ 'baz ' => 2
154+ ]);
155+
156+ $ this ->assertContains ('bar ' , $ parsed );
157+ $ this ->assertNotContains ('2 ' , $ parsed );
158+ }
159+
160+ public function testEqualToIfLessThanStatementIsReplacedIfTrue ()
161+ {
162+ $ parser = $ this ->parser ();
163+
164+ $ template = '{{ foo }} [if:baz < 2] {{ baz }} [endif] ' ;
165+
166+ $ parsed = $ parser ->parse ($ template , [
167+ 'foo ' => 'bar ' ,
168+ 'baz ' => 1
169+ ]);
170+
171+ $ this ->assertContains ('bar ' , $ parsed );
172+ $ this ->assertContains ('1 ' , $ parsed );
173+ }
174+
175+ public function testEqualToIfLessThanStatementIsNotReplacedIfFalse ()
176+ {
177+ $ parser = $ this ->parser ();
178+
179+ $ template = '{{ foo }} [if:baz < 1] {{ baz }} [endif] ' ;
180+
181+ $ parsed = $ parser ->parse ($ template , [
182+ 'foo ' => 'bar ' ,
183+ 'baz ' => 2
184+ ]);
185+
186+ $ this ->assertContains ('bar ' , $ parsed );
187+ $ this ->assertNotContains ('2 ' , $ parsed );
188+ }
189+
190+ public function testEqualToIfLessThanOrEqualStatementIsReplacedIfTrue ()
191+ {
192+ $ parser = $ this ->parser ();
193+
194+ $ template = '{{ foo }} [if:baz <= 1] {{ baz }} [endif] ' ;
195+
196+ $ parsed = $ parser ->parse ($ template , [
197+ 'foo ' => 'bar ' ,
198+ 'baz ' => 1
199+ ]);
200+
201+ $ this ->assertContains ('bar ' , $ parsed );
202+ $ this ->assertContains ('1 ' , $ parsed );
203+ }
204+
205+ public function testEqualToIfLessThanOrEqualStatementIsNotReplacedIfFalse ()
206+ {
207+ $ parser = $ this ->parser ();
208+
209+ $ template = '{{ foo }} [if:baz <= 1] {{ baz }} [endif] ' ;
210+
211+ $ parsed = $ parser ->parse ($ template , [
212+ 'foo ' => 'bar ' ,
213+ 'baz ' => 2
214+ ]);
215+
216+ $ this ->assertContains ('bar ' , $ parsed );
217+ $ this ->assertNotContains ('2 ' , $ parsed );
218+ }
39219}
0 commit comments