diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:05:08 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:05:08 +0200 |
commit | b6f678a5a1d15acf284ebcec16c905e976671ce1 (patch) | |
tree | 33c7da831482ed79c44896ef19c73c72ada84f2e /tests/front/controller/visitor/FeedControllerTest.php | |
parent | b14687036b9b800681197f51fdc47e62f0c88e2e (diff) | |
parent | 1c1520b6b98ab20201bfe15577782a52320339df (diff) | |
download | Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.gz Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.zst Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.zip |
Merge branch 'v0.12' into latest
Diffstat (limited to 'tests/front/controller/visitor/FeedControllerTest.php')
-rw-r--r-- | tests/front/controller/visitor/FeedControllerTest.php | 151 |
1 files changed, 151 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..4ae7c925 --- /dev/null +++ b/tests/front/controller/visitor/FeedControllerTest.php | |||
@@ -0,0 +1,151 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Visitor; | ||
6 | |||
7 | use Shaarli\Feed\FeedBuilder; | ||
8 | use Shaarli\TestCase; | ||
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::atLeastOnce()) | ||
49 | ->method('executeHooks') | ||
50 | ->withConsecutive(['render_feed']) | ||
51 | ->willReturnCallback(function (string $hook, array $data, array $param): void { | ||
52 | if ('render_feed' === $hook) { | ||
53 | static::assertSame('data', $data['content']); | ||
54 | |||
55 | static::assertArrayHasKey('loggedin', $param); | ||
56 | static::assertSame('feed.rss', $param['target']); | ||
57 | } | ||
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 | { | ||
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 | ||
89 | ->expects(static::atLeastOnce()) | ||
90 | ->method('executeHooks') | ||
91 | ->withConsecutive(['render_feed']) | ||
92 | ->willReturnCallback(function (string $hook, array $data, array $param): void { | ||
93 | if ('render_feed' === $hook) { | ||
94 | static::assertSame('data', $data['content']); | ||
95 | |||
96 | static::assertArrayHasKey('loggedin', $param); | ||
97 | static::assertSame('feed.atom', $param['target']); | ||
98 | } | ||
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 | { | ||
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 | ||
131 | ->expects(static::atLeastOnce()) | ||
132 | ->method('executeHooks') | ||
133 | ->withConsecutive(['render_feed']) | ||
134 | ->willReturnCallback(function (string $hook, array $data, array $param): void { | ||
135 | if ('render_feed' === $hook) { | ||
136 | static::assertSame('data', $data['content']); | ||
137 | |||
138 | static::assertArrayHasKey('loggedin', $param); | ||
139 | static::assertSame('feed.atom', $param['target']); | ||
140 | } | ||
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 | } | ||
151 | } | ||