1
|
|
|
<?php |
2
|
|
|
use Mezon\HtmlTemplate\HtmlTemplate; |
3
|
|
|
use Mezon\Application\Presenter; |
4
|
|
|
use Mezon\Application\View; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* View class for testing purposes |
8
|
|
|
* |
9
|
|
|
* @author Dodonov A.A. |
10
|
|
|
*/ |
11
|
|
|
class TestingView extends View |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public function viewTest(): string |
15
|
|
|
{ |
16
|
|
|
return 'rendered content'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function viewTest2(): string |
20
|
|
|
{ |
21
|
|
|
return 'rendered content 2'; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
class ViewStaticUnitTest extends \PHPUnit\Framework\TestCase |
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Testing constructor |
30
|
|
|
*/ |
31
|
|
|
public function testConstructor(): void |
32
|
|
|
{ |
33
|
|
|
// setup |
34
|
|
|
$view = new TestingView(null, 'test'); |
35
|
|
|
|
36
|
|
|
// test body and assertions |
37
|
|
|
$this->assertEquals('test', $view->getViewName(), 'Invalid constructor call'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Testing render |
42
|
|
|
*/ |
43
|
|
|
public function testRender(): void |
44
|
|
|
{ |
45
|
|
|
// setup |
46
|
|
|
$view = new TestingView(null, 'test'); |
47
|
|
|
|
48
|
|
|
// test body and assertions |
49
|
|
|
$this->assertEquals('rendered content', $view->render(), 'Invalid view renderring'); |
50
|
|
|
$this->assertEquals('rendered content 2', $view->render('test2'), 'Invalid view renderring'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Testing render |
55
|
|
|
*/ |
56
|
|
|
public function testDefault(): void |
57
|
|
|
{ |
58
|
|
|
// setup |
59
|
|
|
$view = new TestingView(); |
60
|
|
|
|
61
|
|
|
// assertions |
62
|
|
|
$this->expectExceptionMessage('View Default was not found'); |
63
|
|
|
|
64
|
|
|
// test body |
65
|
|
|
$view->render(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Testing template getter |
70
|
|
|
*/ |
71
|
|
|
public function testGetTemplate(): void |
72
|
|
|
{ |
73
|
|
|
// setup |
74
|
|
|
$view = new TestingView(new HtmlTemplate(__DIR__ . '/res/templates/')); |
75
|
|
|
|
76
|
|
|
// test body and assertions |
77
|
|
|
$this->assertInstanceOf(HtmlTemplate::class, $view->getTemplate()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Testing template getter with exception |
82
|
|
|
*/ |
83
|
|
|
public function testGetTemplateException(): void |
84
|
|
|
{ |
85
|
|
|
// setup and assertions |
86
|
|
|
$view = new TestingView(); |
87
|
|
|
$this->expectException(\Exception::class); |
88
|
|
|
|
89
|
|
|
// test body |
90
|
|
|
$view->getTemplate(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Testing method getPresenter |
95
|
|
|
*/ |
96
|
|
|
public function testExceptionInPresenterFetcher(): void |
97
|
|
|
{ |
98
|
|
|
// setup |
99
|
|
|
$view = new View(null, '', null); |
100
|
|
|
|
101
|
|
|
// assertions |
102
|
|
|
$this->expectException(\Exception::class); |
103
|
|
|
|
104
|
|
|
// test body |
105
|
|
|
$view->getPresenter(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Testing method getPresenter |
110
|
|
|
*/ |
111
|
|
|
public function testNoExceptionInPresenterFetcher(): void |
112
|
|
|
{ |
113
|
|
|
// setup |
114
|
|
|
$view = new View(null, '', new Presenter()); |
|
|
|
|
115
|
|
|
|
116
|
|
|
// test body |
117
|
|
|
$presenter = $view->getPresenter(); |
118
|
|
|
|
119
|
|
|
// assertions |
120
|
|
|
$this->assertInstanceOf(Presenter::class, $presenter); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|