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
|
|
|
* Data provider for the test testActionsJson |
14
|
|
|
* |
15
|
|
|
* @return array testing data |
16
|
|
|
*/ |
17
|
|
|
public function actionsJsonDataProvider(): array |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
|
|
// #0, default behaviour, layout is not set |
21
|
|
|
[ |
22
|
|
|
'from-config', |
23
|
|
|
function (string $result) { |
24
|
|
|
$this->assertStringContainsString('Some title', $result); |
25
|
|
|
$this->assertStringContainsString('Main From Config', $result); |
26
|
|
|
$this->assertStringContainsString('<!-- index1 -->', $result); |
27
|
|
|
|
28
|
|
|
$this->assertTrue(TestingPresenter::$actionPresenterFromConfigWasCalled); |
29
|
|
|
} |
30
|
|
|
], |
31
|
|
|
// #1, default behaviour, layout is set |
32
|
|
|
[ |
33
|
|
|
'from-config2', |
34
|
|
|
function (string $result) { |
35
|
|
|
$this->assertStringContainsString('Some title', $result); |
36
|
|
|
$this->assertStringContainsString('Main From Config', $result); |
37
|
|
|
$this->assertStringContainsString('<!-- index2 -->', $result); |
38
|
|
|
|
39
|
|
|
$this->assertTrue(TestingPresenter::$actionPresenterFromConfigWasCalled); |
40
|
|
|
} |
41
|
|
|
] |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Running with actions |
47
|
|
|
* |
48
|
|
|
* @param string $page |
49
|
|
|
* - loading page |
50
|
|
|
* @param callable $asserter |
51
|
|
|
* asserting method |
52
|
|
|
* @dataProvider actionsJsonDataProvider |
53
|
|
|
*/ |
54
|
|
|
public function testActionsJson(string $page, callable $asserter): void |
55
|
|
|
{ |
56
|
|
|
// setup |
57
|
|
|
$_GET['r'] = $page; |
58
|
|
|
$application = new TestCommonApplication(); |
59
|
|
|
|
60
|
|
|
// test body |
61
|
|
|
ob_start(); |
62
|
|
|
$application->run(); |
63
|
|
|
$result = ob_get_flush(); |
64
|
|
|
ob_clean(); |
65
|
|
|
|
66
|
|
|
// assertions |
67
|
|
|
$asserter($result); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|