diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-08-27 10:27:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 10:27:34 +0200 |
commit | af41d5ab5d2bd3ba64d052c997bc6afa6966a63c (patch) | |
tree | 8fad2829c55f94022e359fa8914e11f80a2afc2a /tests/front/controller/visitor/FeedControllerTest.php | |
parent | b8e3630f2ecd142d397b1b062a346a667bb78595 (diff) | |
parent | 0c6fdbe12bbbb336348666b14b82096f24d5858b (diff) | |
download | Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.tar.gz Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.tar.zst Shaarli-af41d5ab5d2bd3ba64d052c997bc6afa6966a63c.zip |
Merge pull request #1511 from ArthurHoaro/wip-slim-routing
Diffstat (limited to 'tests/front/controller/visitor/FeedControllerTest.php')
-rw-r--r-- | tests/front/controller/visitor/FeedControllerTest.php | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/tests/front/controller/visitor/FeedControllerTest.php b/tests/front/controller/visitor/FeedControllerTest.php new file mode 100644 index 00000000..fb417e2a --- /dev/null +++ b/tests/front/controller/visitor/FeedControllerTest.php | |||
@@ -0,0 +1,145 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Visitor; | ||
6 | |||
7 | use PHPUnit\Framework\TestCase; | ||
8 | use Shaarli\Feed\FeedBuilder; | ||
9 | use Slim\Http\Request; | ||
10 | use Slim\Http\Response; | ||
11 | |||
12 | class FeedControllerTest extends TestCase | ||
13 | { | ||
14 | use FrontControllerMockHelper; | ||
15 | |||
16 | /** @var FeedController */ | ||
17 | protected $controller; | ||
18 | |||
19 | public function setUp(): void | ||
20 | { | ||
21 | $this->createContainer(); | ||
22 | |||
23 | $this->container->feedBuilder = $this->createMock(FeedBuilder::class); | ||
24 | |||
25 | $this->controller = new FeedController($this->container); | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * Feed Controller - RSS default behaviour | ||
30 | */ | ||
31 | public function testDefaultRssController(): void | ||
32 | { | ||
33 | $request = $this->createMock(Request::class); | ||
34 | $response = new Response(); | ||
35 | |||
36 | $this->container->feedBuilder->expects(static::once())->method('setLocale'); | ||
37 | $this->container->feedBuilder->expects(static::once())->method('setHideDates')->with(false); | ||
38 | $this->container->feedBuilder->expects(static::once())->method('setUsePermalinks')->with(true); | ||
39 | |||
40 | // Save RainTPL assigned variables | ||
41 | $assignedVariables = []; | ||
42 | $this->assignTemplateVars($assignedVariables); | ||
43 | |||
44 | $this->container->feedBuilder->method('buildData')->willReturn(['content' => 'data']); | ||
45 | |||
46 | // Make sure that PluginManager hook is triggered | ||
47 | $this->container->pluginManager | ||
48 | ->expects(static::at(0)) | ||
49 | ->method('executeHooks') | ||
50 | ->willReturnCallback(function (string $hook, array $data, array $param): void { | ||
51 | static::assertSame('render_feed', $hook); | ||
52 | static::assertSame('data', $data['content']); | ||
53 | |||
54 | static::assertArrayHasKey('loggedin', $param); | ||
55 | static::assertSame('rss', $param['target']); | ||
56 | }) | ||
57 | ; | ||
58 | |||
59 | $result = $this->controller->rss($request, $response); | ||
60 | |||
61 | static::assertSame(200, $result->getStatusCode()); | ||
62 | static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); | ||
63 | static::assertSame('feed.rss', (string) $result->getBody()); | ||
64 | static::assertSame('data', $assignedVariables['content']); | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * Feed Controller - ATOM default behaviour | ||
69 | */ | ||
70 | public function testDefaultAtomController(): void | ||
71 | { | ||
72 | $request = $this->createMock(Request::class); | ||
73 | $response = new Response(); | ||
74 | |||
75 | $this->container->feedBuilder->expects(static::once())->method('setLocale'); | ||
76 | $this->container->feedBuilder->expects(static::once())->method('setHideDates')->with(false); | ||
77 | $this->container->feedBuilder->expects(static::once())->method('setUsePermalinks')->with(true); | ||
78 | |||
79 | // Save RainTPL assigned variables | ||
80 | $assignedVariables = []; | ||
81 | $this->assignTemplateVars($assignedVariables); | ||
82 | |||
83 | $this->container->feedBuilder->method('buildData')->willReturn(['content' => 'data']); | ||
84 | |||
85 | // Make sure that PluginManager hook is triggered | ||
86 | $this->container->pluginManager | ||
87 | ->expects(static::at(0)) | ||
88 | ->method('executeHooks') | ||
89 | ->willReturnCallback(function (string $hook, array $data, array $param): void { | ||
90 | static::assertSame('render_feed', $hook); | ||
91 | static::assertSame('data', $data['content']); | ||
92 | |||
93 | static::assertArrayHasKey('loggedin', $param); | ||
94 | static::assertSame('atom', $param['target']); | ||
95 | }) | ||
96 | ; | ||
97 | |||
98 | $result = $this->controller->atom($request, $response); | ||
99 | |||
100 | static::assertSame(200, $result->getStatusCode()); | ||
101 | static::assertStringContainsString('application/atom', $result->getHeader('Content-Type')[0]); | ||
102 | static::assertSame('feed.atom', (string) $result->getBody()); | ||
103 | static::assertSame('data', $assignedVariables['content']); | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * Feed Controller - ATOM with parameters | ||
108 | */ | ||
109 | public function testAtomControllerWithParameters(): void | ||
110 | { | ||
111 | $request = $this->createMock(Request::class); | ||
112 | $request->method('getParams')->willReturn(['parameter' => 'value']); | ||
113 | $response = new Response(); | ||
114 | |||
115 | // Save RainTPL assigned variables | ||
116 | $assignedVariables = []; | ||
117 | $this->assignTemplateVars($assignedVariables); | ||
118 | |||
119 | $this->container->feedBuilder | ||
120 | ->method('buildData') | ||
121 | ->with('atom', ['parameter' => 'value']) | ||
122 | ->willReturn(['content' => 'data']) | ||
123 | ; | ||
124 | |||
125 | // Make sure that PluginManager hook is triggered | ||
126 | $this->container->pluginManager | ||
127 | ->expects(static::at(0)) | ||
128 | ->method('executeHooks') | ||
129 | ->willReturnCallback(function (string $hook, array $data, array $param): void { | ||
130 | static::assertSame('render_feed', $hook); | ||
131 | static::assertSame('data', $data['content']); | ||
132 | |||
133 | static::assertArrayHasKey('loggedin', $param); | ||
134 | static::assertSame('atom', $param['target']); | ||
135 | }) | ||
136 | ; | ||
137 | |||
138 | $result = $this->controller->atom($request, $response); | ||
139 | |||
140 | static::assertSame(200, $result->getStatusCode()); | ||
141 | static::assertStringContainsString('application/atom', $result->getHeader('Content-Type')[0]); | ||
142 | static::assertSame('feed.atom', (string) $result->getBody()); | ||
143 | static::assertSame('data', $assignedVariables['content']); | ||
144 | } | ||
145 | } | ||