Skip to content

Commit 852c2db

Browse files
committed
test: Added Test Cases for Before Render
1 parent a929438 commit 852c2db

File tree

1 file changed

+85
-2
lines changed

1 file changed

+85
-2
lines changed

tests/webfiori/framework/test/PageTest.php

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,100 @@ public function testBeforeRender00() {
154154
$c->assertTrue($p->getDocument()->hasChild('super-el'));
155155
},0, [$this]);
156156
$this->assertNotNull($c);
157-
$this->assertEquals(2, $c->getID());
158157
$this->assertEquals(0, $c->getPriority());
159158

160159
$c2 = $page->addBeforeRender(function(WebPage $p, TestCase $c)
161160
{
162161
$ch = $p->insert('div');
163162
$ch->setID('super-el');
164163
}, 3, [$this]);
165-
$this->assertEquals(3, $c2->getID());
166164
$this->assertEquals(3, $c2->getPriority());
167165
}
166+
/**
167+
* @test
168+
*/
169+
public function testBeforeRender01() {
170+
$page = new WebPage();
171+
$c = $page->addBeforeRender(function (WebPage $p, TestCase $c)
172+
{
173+
$c->assertTrue($p->getDocument()->getChildByID('super-el') !== null);
174+
},0, [$this]);
175+
176+
$c2 = $page->addBeforeRender(function(WebPage $p, TestCase $c)
177+
{
178+
$ch = $p->insert('div');
179+
$ch->setID('super-el');
180+
}, 3, [$this]);
181+
$this->assertNull($page->getDocument()->getChildByID('super-el'));
182+
$page->beforeRender();
183+
$this->assertNotNull($page->getDocument()->getChildByID('super-el'));
184+
}
185+
/**
186+
* @test
187+
*/
188+
public function testBeforeRender02() {
189+
$page = new WebPage();
190+
$c = $page->addBeforeRender(function (WebPage $p, TestCase $c)
191+
{
192+
$c->assertTrue($p->getDocument()->getChildByID('super-el') === null);
193+
},0, [$this]);
194+
195+
$c2 = $page->addBeforeRender(function(WebPage $p, TestCase $c)
196+
{
197+
$ch = $p->insert('div');
198+
$ch->setID('super-el');
199+
}, 3, [$this]);
200+
$page->removeBeforeRender($c2->getID());
201+
$page->beforeRender();
202+
$this->assertNull($page->getDocument()->getChildByID('super-el'));
203+
}
204+
/**
205+
* @test
206+
*/
207+
public function testBeforeRender03() {
208+
$page = new WebPage();
209+
$c = $page->addBeforeRender(function (WebPage $p, TestCase $c)
210+
{
211+
212+
$p->addBeforeRender(function (WebPage $p, TestCase $c) {
213+
$c->assertTrue($p->getDocument()->getChildByID('super-el') === null);
214+
}, 4, [$this]);
215+
$p->addBeforeRender(function(WebPage $p, TestCase $c)
216+
{
217+
$ch = $p->insert('div');
218+
$ch->setID('super-el');
219+
}, 3, [$this]);
220+
$p->addBeforeRender(function (WebPage $p, TestCase $c) {
221+
$c->assertTrue($p->getDocument()->getChildByID('super-el') !== null);
222+
}, 2, [$this]);
223+
224+
},0, [$this]);
225+
226+
$page->beforeRender();
227+
$this->assertNotNull($page->getDocument()->getChildByID('super-el'));
228+
}
229+
/**
230+
* @test
231+
*/
232+
public function testBeforeRender04() {
233+
$page = new WebPage();
234+
235+
$c2 = $page->addBeforeRender(function(WebPage $p, TestCase $c)
236+
{
237+
$ch = $p->insert('div');
238+
$ch->setID('super-el');
239+
}, 3, [$this]);
240+
241+
$c2->setCallback(function(WebPage $p, TestCase $c)
242+
{
243+
$ch = $p->insert('div');
244+
$ch->setID('super-cool');
245+
}, [$this]);
246+
247+
$page->beforeRender();
248+
$this->assertNull($page->getDocument()->getChildByID('super-el'));
249+
$this->assertNotNull($page->getDocument()->getChildByID('super-cool'));
250+
}
168251
/**
169252
* @test
170253
*/

0 commit comments

Comments
 (0)