-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathViewTest.php
More file actions
executable file
·92 lines (70 loc) · 2.35 KB
/
ViewTest.php
File metadata and controls
executable file
·92 lines (70 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Utopia;
use PHPUnit\Framework\TestCase;
class ViewTest extends TestCase
{
protected ?View $view;
public function setUp(): void
{
$this->view = new View(__DIR__.'/mocks/View/template.phtml');
}
public function tearDown(): void
{
$this->view = null;
}
public function testCanSetParam()
{
$value = $this->view->setParam('key', 'value');
$this->assertInstanceOf('Utopia\View', $value);
}
public function testCanGetParam()
{
$this->view->setParam('key', 'value');
$this->assertEquals('value', $this->view->getParam('key', 'default'));
$this->assertEquals('default', $this->view->getParam('fake', 'default'));
}
public function testCanSetPath()
{
$value = $this->view->setPath('mocks/View/fake.phtml');
$this->assertInstanceOf('Utopia\View', $value);
}
public function testCanSetRendered()
{
$this->view->setRendered();
$this->assertEquals(true, $this->view->isRendered());
}
public function testCanGetRendered()
{
$this->view->setRendered(false);
$this->assertEquals(false, $this->view->isRendered());
$this->view->setRendered(true);
$this->assertEquals(true, $this->view->isRendered());
}
public function testCanRenderHtml()
{
$this->assertEquals('<div>Test template mock</div>', $this->view->render());
$this->view->setRendered();
$this->assertEquals('', $this->view->render());
try {
$this->view->setRendered(false);
$this->view->setPath('just-a-broken-string.phtml');
$this->view->render();
} catch (\Exception $e) {
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testCanEscapeUnicode()
{
$this->assertEquals('&"', $this->view->print('&"', View::FILTER_ESCAPE));
}
public function testCanFilterNewLinesToParagraphs()
{
$this->assertEquals('<p>line1</p><p>line2</p>', $this->view->print("line1\n\nline2", View::FILTER_NL2P));
}
public function testCanSetParamWithEscapedHtml()
{
$this->view->setParam('key', '<html>value</html>');
$this->assertEquals('<html>value</html>', $this->view->getParam('key', 'default'));
}
}