1
|
|
|
<?php |
2
|
|
|
namespace Mezon\Application\Tests; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use Mezon\Application\CommonApplication; |
6
|
|
|
use Mezon\HtmlTemplate\HtmlTemplate; |
7
|
|
|
use Mezon\Application\View; |
8
|
|
|
|
9
|
|
|
class CommonApplicationActionsUnitTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Asserting that page was generated |
14
|
|
|
* |
15
|
|
|
* @param string $result |
16
|
|
|
* page generation result |
17
|
|
|
* @param string $layout |
18
|
|
|
* substring to be found |
19
|
|
|
*/ |
20
|
|
|
public function assertCommonCall(string $result, string $layout): void |
21
|
|
|
{ |
22
|
|
|
$this->assertStringContainsString('Some title', $result); |
23
|
|
|
$this->assertStringContainsString('Main From Config', $result); |
24
|
|
|
$this->assertStringContainsString($layout, $result); |
25
|
|
|
|
26
|
|
|
$this->assertTrue(TestingPresenter::$actionPresenterFromConfigWasCalled); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Data provider for the test testActionsJson |
31
|
|
|
* |
32
|
|
|
* @return array testing data |
33
|
|
|
*/ |
34
|
|
|
public function actionsJsonDataProvider(): array |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
// #0, default behaviour, layout is not set |
38
|
|
|
[ |
39
|
|
|
'from-config', |
40
|
|
|
function (string $result) { |
41
|
|
|
$this->assertCommonCall($result, '<!-- index1 -->'); |
42
|
|
|
} |
43
|
|
|
], |
44
|
|
|
// #1, default behaviour, layout is set, no name is defined for the other-view |
45
|
|
|
[ |
46
|
|
|
'from-config2', |
47
|
|
|
function (string $result) { |
48
|
|
|
$this->assertCommonCall($result, '<!-- index2 -->'); |
49
|
|
|
|
50
|
|
|
$this->assertTrue(TestingView::$defaultViewWasRendered); |
51
|
|
|
} |
52
|
|
|
], |
53
|
|
|
// #2, inherit from from-config2 |
54
|
|
|
[ |
55
|
|
|
'from-config3', |
56
|
|
|
function (string $result) { |
57
|
|
|
$this->assertCommonCall($result, '<!-- index1 -->'); |
58
|
|
|
|
59
|
|
|
$this->assertTrue(TestingView::$defaultViewWasRendered); |
60
|
|
|
} |
61
|
|
|
] |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Running with actions |
67
|
|
|
* |
68
|
|
|
* @param string $page |
69
|
|
|
* - loading page |
70
|
|
|
* @param callable $asserter |
71
|
|
|
* asserting method |
72
|
|
|
* @dataProvider actionsJsonDataProvider |
73
|
|
|
*/ |
74
|
|
|
public function testActionsJson(string $page, callable $asserter): void |
75
|
|
|
{ |
76
|
|
|
// setup |
77
|
|
|
$_GET['r'] = $page; |
78
|
|
|
$application = new TestCommonApplication(); |
79
|
|
|
|
80
|
|
|
// test body |
81
|
|
|
ob_start(); |
82
|
|
|
$application->run(); |
83
|
|
|
$result = ob_get_flush(); |
84
|
|
|
ob_clean(); |
85
|
|
|
|
86
|
|
|
// assertions |
87
|
|
|
$asserter($result); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|