]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/front/controller/visitor/FeedControllerTest.php
Compatibility with PHPUnit 9
[github/shaarli/Shaarli.git] / tests / front / controller / visitor / FeedControllerTest.php
CommitLineData
7b2ba6ef
A
1<?php
2
3declare(strict_types=1);
4
2899ebb5 5namespace Shaarli\Front\Controller\Visitor;
7b2ba6ef 6
7b2ba6ef 7use Shaarli\Feed\FeedBuilder;
a5a9cf23 8use Shaarli\TestCase;
7b2ba6ef
A
9use Slim\Http\Request;
10use Slim\Http\Response;
11
12class FeedControllerTest extends TestCase
13{
dd09ec52 14 use FrontControllerMockHelper;
7b2ba6ef
A
15
16 /** @var FeedController */
17 protected $controller;
18
19 public function setUp(): void
20 {
dd09ec52
A
21 $this->createContainer();
22
23 $this->container->feedBuilder = $this->createMock(FeedBuilder::class);
24
7b2ba6ef
A
25 $this->controller = new FeedController($this->container);
26 }
27
28 /**
29 * Feed Controller - RSS default behaviour
30 */
31 public function testDefaultRssController(): void
32 {
7b2ba6ef
A
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
a5a9cf23 48 ->expects(static::atLeastOnce())
7b2ba6ef 49 ->method('executeHooks')
a5a9cf23 50 ->withConsecutive(['render_feed'])
7b2ba6ef 51 ->willReturnCallback(function (string $hook, array $data, array $param): void {
a5a9cf23
A
52 if ('render_feed' === $hook) {
53 static::assertSame('data', $data['content']);
7b2ba6ef 54
a5a9cf23
A
55 static::assertArrayHasKey('loggedin', $param);
56 static::assertSame('feed.rss', $param['target']);
57 }
7b2ba6ef
A
58 })
59 ;
60
61 $result = $this->controller->rss($request, $response);
62
63 static::assertSame(200, $result->getStatusCode());
64 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]);
65 static::assertSame('feed.rss', (string) $result->getBody());
66 static::assertSame('data', $assignedVariables['content']);
67 }
68
69 /**
70 * Feed Controller - ATOM default behaviour
71 */
72 public function testDefaultAtomController(): void
73 {
7b2ba6ef
A
74 $request = $this->createMock(Request::class);
75 $response = new Response();
76
77 $this->container->feedBuilder->expects(static::once())->method('setLocale');
78 $this->container->feedBuilder->expects(static::once())->method('setHideDates')->with(false);
79 $this->container->feedBuilder->expects(static::once())->method('setUsePermalinks')->with(true);
80
81 // Save RainTPL assigned variables
82 $assignedVariables = [];
83 $this->assignTemplateVars($assignedVariables);
84
85 $this->container->feedBuilder->method('buildData')->willReturn(['content' => 'data']);
86
87 // Make sure that PluginManager hook is triggered
88 $this->container->pluginManager
a5a9cf23 89 ->expects(static::atLeastOnce())
7b2ba6ef 90 ->method('executeHooks')
a5a9cf23 91 ->withConsecutive(['render_feed'])
7b2ba6ef 92 ->willReturnCallback(function (string $hook, array $data, array $param): void {
a5a9cf23
A
93 if ('render_feed' === $hook) {
94 static::assertSame('data', $data['content']);
7b2ba6ef 95
a5a9cf23
A
96 static::assertArrayHasKey('loggedin', $param);
97 static::assertSame('feed.atom', $param['target']);
98 }
7b2ba6ef
A
99 })
100 ;
101
102 $result = $this->controller->atom($request, $response);
103
104 static::assertSame(200, $result->getStatusCode());
105 static::assertStringContainsString('application/atom', $result->getHeader('Content-Type')[0]);
106 static::assertSame('feed.atom', (string) $result->getBody());
107 static::assertSame('data', $assignedVariables['content']);
108 }
109
110 /**
111 * Feed Controller - ATOM with parameters
112 */
113 public function testAtomControllerWithParameters(): void
114 {
7b2ba6ef
A
115 $request = $this->createMock(Request::class);
116 $request->method('getParams')->willReturn(['parameter' => 'value']);
117 $response = new Response();
118
119 // Save RainTPL assigned variables
120 $assignedVariables = [];
121 $this->assignTemplateVars($assignedVariables);
122
123 $this->container->feedBuilder
124 ->method('buildData')
125 ->with('atom', ['parameter' => 'value'])
126 ->willReturn(['content' => 'data'])
127 ;
128
129 // Make sure that PluginManager hook is triggered
130 $this->container->pluginManager
a5a9cf23 131 ->expects(static::atLeastOnce())
7b2ba6ef 132 ->method('executeHooks')
a5a9cf23 133 ->withConsecutive(['render_feed'])
7b2ba6ef 134 ->willReturnCallback(function (string $hook, array $data, array $param): void {
a5a9cf23
A
135 if ('render_feed' === $hook) {
136 static::assertSame('data', $data['content']);
7b2ba6ef 137
a5a9cf23
A
138 static::assertArrayHasKey('loggedin', $param);
139 static::assertSame('feed.atom', $param['target']);
140 }
7b2ba6ef
A
141 })
142 ;
143
144 $result = $this->controller->atom($request, $response);
145
146 static::assertSame(200, $result->getStatusCode());
147 static::assertStringContainsString('application/atom', $result->getHeader('Content-Type')[0]);
148 static::assertSame('feed.atom', (string) $result->getBody());
149 static::assertSame('data', $assignedVariables['content']);
150 }
7b2ba6ef 151}