1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Lichtenwallner (https://lichtenwallner.at) |
4
|
|
|
* |
5
|
|
|
* @see https://github.com/jolicht/markdown-cms for the canonical source repository |
6
|
|
|
* @license https://github.com/jolicht/markdown-cms/blob/master/LICENSE MIT |
7
|
|
|
* @copyright Copyright (c) Johannes Lichtenwallner |
8
|
|
|
*/ |
9
|
|
|
declare(strict_types = 1); |
10
|
|
|
namespace JolichtTest\MarkdownCms\Action; |
11
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Jolicht\MarkdownCms\Action\SingleBlogEntryAction; |
14
|
|
|
use Zend\Expressive\Template\TemplateRendererInterface; |
15
|
|
|
use Jolicht\MarkdownCms\ContentType\ContentCreator; |
16
|
|
|
use Jolicht\MarkdownCms\Markdown\MarkdownDocumentParser; |
17
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
18
|
|
|
use Psr\Http\Message\ResponseInterface; |
19
|
|
|
use Jolicht\MarkdownCms\Markdown\MarkdownDocument; |
20
|
|
|
use Jolicht\MarkdownCms\ContentType\ContentTypeInterface; |
21
|
|
|
use Prophecy\Argument; |
22
|
|
|
use Zend\Diactoros\Response\HtmlResponse; |
23
|
|
|
|
24
|
|
|
class SingleBlogEntryActionTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
private $action, $templateRenderer, $contentCreator, $markdownDocumentParser, $markdownCmsConfig; |
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function setUp() |
29
|
|
|
{ |
30
|
|
|
$this->templateRenderer = $this->createMock(TemplateRendererInterface::class); |
31
|
|
|
$this->contentCreator = $this->createMock(ContentCreator::class); |
32
|
|
|
$this->markdownDocumentParser = $this->createMock(MarkdownDocumentParser::class); |
33
|
|
|
$this->markdownCmsConfig = [ |
34
|
|
|
'options' => [ |
35
|
|
|
|
36
|
|
|
] |
37
|
|
|
]; |
38
|
|
|
$this->action = new SingleBlogEntryAction( |
39
|
|
|
$this->templateRenderer, $this->contentCreator, $this->markdownDocumentParser, $this->markdownCmsConfig); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testGetTemplateRenderer() |
43
|
|
|
{ |
44
|
|
|
$this->assertSame($this->templateRenderer, $this->action->getTemplateRenderer()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGetContentCreator() |
48
|
|
|
{ |
49
|
|
|
$this->assertSame($this->contentCreator, $this->action->getContentCreator()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testGetMarkdownDocumentParser() |
53
|
|
|
{ |
54
|
|
|
$this->assertSame($this->markdownDocumentParser, $this->action->getMarkdownDocumentParser()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testGetMarkdownCmsConfig() |
58
|
|
|
{ |
59
|
|
|
$this->assertSame($this->markdownCmsConfig, $this->action->getMarkdownCmsConfig()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testInvoke() |
63
|
|
|
{ |
64
|
|
|
$templateRenderer = $this->prophesize(TemplateRendererInterface::class); |
65
|
|
|
$contentCreator = $this->prophesize(ContentCreator::class); |
66
|
|
|
$markdownDocumentParser = $this->prophesize(MarkdownDocumentParser::class); |
67
|
|
|
$markdownCmsConfig = [ |
68
|
|
|
'options' => [ |
69
|
|
|
'content_dir' => __DIR__ . '/_files', |
70
|
|
|
], |
71
|
|
|
'content' => [ |
72
|
|
|
'src' => [ |
73
|
|
|
'testId' => 'test.md' |
74
|
|
|
] |
75
|
|
|
] |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
$action = new SingleBlogEntryAction( |
79
|
|
|
$templateRenderer->reveal(), $contentCreator->reveal(), $markdownDocumentParser->reveal(), |
80
|
|
|
$markdownCmsConfig |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
84
|
|
|
$request |
85
|
|
|
->getAttribute('id') |
86
|
|
|
->willReturn('testId'); |
87
|
|
|
|
88
|
|
|
$markdownDocument = $this->prophesize(MarkdownDocument::class); |
89
|
|
|
|
90
|
|
|
$markdownDocumentParser |
91
|
|
|
->__invoke('testContent') |
92
|
|
|
->willReturn($markdownDocument->reveal()); |
93
|
|
|
|
94
|
|
|
$contentType = $this->prophesize(ContentTypeInterface::class); |
95
|
|
|
$contentType->getTemplate() |
96
|
|
|
->willReturn('testTemplate'); |
97
|
|
|
|
98
|
|
|
$contentCreator |
99
|
|
|
->__invoke($markdownDocument->reveal()) |
100
|
|
|
->willReturn($contentType->reveal()); |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
$serverParams = [ |
105
|
|
|
'REQUEST_SCHEME' => 'http', |
106
|
|
|
'SERVER_NAME' => 'testServerName' |
107
|
|
|
]; |
108
|
|
|
$request |
109
|
|
|
->getServerParams() |
110
|
|
|
->willReturn($serverParams); |
111
|
|
|
|
112
|
|
|
$templateRenderer |
113
|
|
|
->render('testTemplate', Argument::type('array')) |
114
|
|
|
->willReturn(''); |
115
|
|
|
|
116
|
|
|
$response = $action( |
117
|
|
|
$request->reveal(), |
118
|
|
|
$this->prophesize(ResponseInterface::class)->reveal() |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$this->assertInstanceOf(HtmlResponse::class, $response); |
122
|
|
|
} |
123
|
|
|
} |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.