diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-05-22 13:20:31 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | 2899ebb5b5e82890c877151f5c02045266ac9973 (patch) | |
tree | 0c4e2684c7f6d161f92a21181bfa4b2f78d6a82f /tests/front/controller/visitor/TagControllerTest.php | |
parent | af290059d10319e76d1e7d78b592cab99c26d91a (diff) | |
download | Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.tar.gz Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.tar.zst Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.zip |
Initialize admin Slim controllers
- Reorganize visitor controllers
- Fix redirection with Slim's requests base path
- Fix daily links
Diffstat (limited to 'tests/front/controller/visitor/TagControllerTest.php')
-rw-r--r-- | tests/front/controller/visitor/TagControllerTest.php | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/tests/front/controller/visitor/TagControllerTest.php b/tests/front/controller/visitor/TagControllerTest.php new file mode 100644 index 00000000..9a2b1f71 --- /dev/null +++ b/tests/front/controller/visitor/TagControllerTest.php | |||
@@ -0,0 +1,241 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Visitor; | ||
6 | |||
7 | use PHPUnit\Framework\TestCase; | ||
8 | use Slim\Http\Request; | ||
9 | use Slim\Http\Response; | ||
10 | |||
11 | class TagControllerTest extends TestCase | ||
12 | { | ||
13 | use FrontControllerMockHelper; | ||
14 | |||
15 | /** @var TagController */ protected $controller; | ||
16 | |||
17 | public function setUp(): void | ||
18 | { | ||
19 | $this->createContainer(); | ||
20 | |||
21 | $this->controller = new TagController($this->container); | ||
22 | } | ||
23 | |||
24 | public function testAddTagWithReferer(): void | ||
25 | { | ||
26 | $this->createValidContainerMockSet(); | ||
27 | |||
28 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/']; | ||
29 | |||
30 | $request = $this->createMock(Request::class); | ||
31 | $response = new Response(); | ||
32 | |||
33 | $tags = ['newTag' => 'abc']; | ||
34 | |||
35 | $result = $this->controller->addTag($request, $response, $tags); | ||
36 | |||
37 | static::assertInstanceOf(Response::class, $result); | ||
38 | static::assertSame(302, $result->getStatusCode()); | ||
39 | static::assertSame(['/controller/?searchtags=abc'], $result->getHeader('location')); | ||
40 | } | ||
41 | |||
42 | public function testAddTagWithRefererAndExistingSearch(): void | ||
43 | { | ||
44 | $this->createValidContainerMockSet(); | ||
45 | |||
46 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def']; | ||
47 | |||
48 | $request = $this->createMock(Request::class); | ||
49 | $response = new Response(); | ||
50 | |||
51 | $tags = ['newTag' => 'abc']; | ||
52 | |||
53 | $result = $this->controller->addTag($request, $response, $tags); | ||
54 | |||
55 | static::assertInstanceOf(Response::class, $result); | ||
56 | static::assertSame(302, $result->getStatusCode()); | ||
57 | static::assertSame(['/controller/?searchtags=def+abc'], $result->getHeader('location')); | ||
58 | } | ||
59 | |||
60 | public function testAddTagWithoutRefererAndExistingSearch(): void | ||
61 | { | ||
62 | $this->createValidContainerMockSet(); | ||
63 | |||
64 | $request = $this->createMock(Request::class); | ||
65 | $response = new Response(); | ||
66 | |||
67 | $tags = ['newTag' => 'abc']; | ||
68 | |||
69 | $result = $this->controller->addTag($request, $response, $tags); | ||
70 | |||
71 | static::assertInstanceOf(Response::class, $result); | ||
72 | static::assertSame(302, $result->getStatusCode()); | ||
73 | static::assertSame(['./?searchtags=abc'], $result->getHeader('location')); | ||
74 | } | ||
75 | |||
76 | public function testAddTagRemoveLegacyQueryParam(): void | ||
77 | { | ||
78 | $this->createValidContainerMockSet(); | ||
79 | |||
80 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def&addtag=abc']; | ||
81 | |||
82 | $request = $this->createMock(Request::class); | ||
83 | $response = new Response(); | ||
84 | |||
85 | $tags = ['newTag' => 'abc']; | ||
86 | |||
87 | $result = $this->controller->addTag($request, $response, $tags); | ||
88 | |||
89 | static::assertInstanceOf(Response::class, $result); | ||
90 | static::assertSame(302, $result->getStatusCode()); | ||
91 | static::assertSame(['/controller/?searchtags=def+abc'], $result->getHeader('location')); | ||
92 | } | ||
93 | |||
94 | public function testAddTagResetPagination(): void | ||
95 | { | ||
96 | $this->createValidContainerMockSet(); | ||
97 | |||
98 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def&page=12']; | ||
99 | |||
100 | $request = $this->createMock(Request::class); | ||
101 | $response = new Response(); | ||
102 | |||
103 | $tags = ['newTag' => 'abc']; | ||
104 | |||
105 | $result = $this->controller->addTag($request, $response, $tags); | ||
106 | |||
107 | static::assertInstanceOf(Response::class, $result); | ||
108 | static::assertSame(302, $result->getStatusCode()); | ||
109 | static::assertSame(['/controller/?searchtags=def+abc'], $result->getHeader('location')); | ||
110 | } | ||
111 | |||
112 | public function testAddTagWithRefererAndEmptySearch(): void | ||
113 | { | ||
114 | $this->createValidContainerMockSet(); | ||
115 | |||
116 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=']; | ||
117 | |||
118 | $request = $this->createMock(Request::class); | ||
119 | $response = new Response(); | ||
120 | |||
121 | $tags = ['newTag' => 'abc']; | ||
122 | |||
123 | $result = $this->controller->addTag($request, $response, $tags); | ||
124 | |||
125 | static::assertInstanceOf(Response::class, $result); | ||
126 | static::assertSame(302, $result->getStatusCode()); | ||
127 | static::assertSame(['/controller/?searchtags=abc'], $result->getHeader('location')); | ||
128 | } | ||
129 | |||
130 | public function testAddTagWithoutNewTagWithReferer(): void | ||
131 | { | ||
132 | $this->createValidContainerMockSet(); | ||
133 | |||
134 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def']; | ||
135 | |||
136 | $request = $this->createMock(Request::class); | ||
137 | $response = new Response(); | ||
138 | |||
139 | $result = $this->controller->addTag($request, $response, []); | ||
140 | |||
141 | static::assertInstanceOf(Response::class, $result); | ||
142 | static::assertSame(302, $result->getStatusCode()); | ||
143 | static::assertSame(['/controller/?searchtags=def'], $result->getHeader('location')); | ||
144 | } | ||
145 | |||
146 | public function testAddTagWithoutNewTagWithoutReferer(): void | ||
147 | { | ||
148 | $this->createValidContainerMockSet(); | ||
149 | |||
150 | $request = $this->createMock(Request::class); | ||
151 | $response = new Response(); | ||
152 | |||
153 | $result = $this->controller->addTag($request, $response, []); | ||
154 | |||
155 | static::assertInstanceOf(Response::class, $result); | ||
156 | static::assertSame(302, $result->getStatusCode()); | ||
157 | static::assertSame(['./'], $result->getHeader('location')); | ||
158 | } | ||
159 | |||
160 | public function testRemoveTagWithoutMatchingTag(): void | ||
161 | { | ||
162 | $this->createValidContainerMockSet(); | ||
163 | |||
164 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtags=def']; | ||
165 | |||
166 | $request = $this->createMock(Request::class); | ||
167 | $response = new Response(); | ||
168 | |||
169 | $tags = ['tag' => 'abc']; | ||
170 | |||
171 | $result = $this->controller->removeTag($request, $response, $tags); | ||
172 | |||
173 | static::assertInstanceOf(Response::class, $result); | ||
174 | static::assertSame(302, $result->getStatusCode()); | ||
175 | static::assertSame(['/controller/?searchtags=def'], $result->getHeader('location')); | ||
176 | } | ||
177 | |||
178 | public function testRemoveTagWithoutTagsearch(): void | ||
179 | { | ||
180 | $this->createValidContainerMockSet(); | ||
181 | |||
182 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/']; | ||
183 | |||
184 | $request = $this->createMock(Request::class); | ||
185 | $response = new Response(); | ||
186 | |||
187 | $tags = ['tag' => 'abc']; | ||
188 | |||
189 | $result = $this->controller->removeTag($request, $response, $tags); | ||
190 | |||
191 | static::assertInstanceOf(Response::class, $result); | ||
192 | static::assertSame(302, $result->getStatusCode()); | ||
193 | static::assertSame(['/controller/'], $result->getHeader('location')); | ||
194 | } | ||
195 | |||
196 | public function testRemoveTagWithoutReferer(): void | ||
197 | { | ||
198 | $this->createValidContainerMockSet(); | ||
199 | |||
200 | $request = $this->createMock(Request::class); | ||
201 | $response = new Response(); | ||
202 | |||
203 | $tags = ['tag' => 'abc']; | ||
204 | |||
205 | $result = $this->controller->removeTag($request, $response, $tags); | ||
206 | |||
207 | static::assertInstanceOf(Response::class, $result); | ||
208 | static::assertSame(302, $result->getStatusCode()); | ||
209 | static::assertSame(['./'], $result->getHeader('location')); | ||
210 | } | ||
211 | |||
212 | public function testRemoveTagWithoutTag(): void | ||
213 | { | ||
214 | $this->createValidContainerMockSet(); | ||
215 | |||
216 | $this->container->environment = ['HTTP_REFERER' => 'http://shaarli/controller/?searchtag=abc']; | ||
217 | |||
218 | $request = $this->createMock(Request::class); | ||
219 | $response = new Response(); | ||
220 | |||
221 | $result = $this->controller->removeTag($request, $response, []); | ||
222 | |||
223 | static::assertInstanceOf(Response::class, $result); | ||
224 | static::assertSame(302, $result->getStatusCode()); | ||
225 | static::assertSame(['/controller/?searchtag=abc'], $result->getHeader('location')); | ||
226 | } | ||
227 | |||
228 | public function testRemoveTagWithoutTagWithoutReferer(): void | ||
229 | { | ||
230 | $this->createValidContainerMockSet(); | ||
231 | |||
232 | $request = $this->createMock(Request::class); | ||
233 | $response = new Response(); | ||
234 | |||
235 | $result = $this->controller->removeTag($request, $response, []); | ||
236 | |||
237 | static::assertInstanceOf(Response::class, $result); | ||
238 | static::assertSame(302, $result->getStatusCode()); | ||
239 | static::assertSame(['./'], $result->getHeader('location')); | ||
240 | } | ||
241 | } | ||