]>
Commit | Line | Data |
---|---|---|
769e19dc J |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\ApiBundle\Controller; |
769e19dc | 4 | |
23634d5d | 5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; |
769e19dc | 6 | |
8a493541 | 7 | class WallabagRestControllerTest extends WallabagApiTestCase |
769e19dc J |
8 | { |
9 | protected static $salt; | |
10 | ||
769e19dc J |
11 | public function testGetOneEntry() |
12 | { | |
fcb1fba5 | 13 | $entry = $this->client->getContainer() |
769e19dc J |
14 | ->get('doctrine.orm.entity_manager') |
15 | ->getRepository('WallabagCoreBundle:Entry') | |
4094ea47 | 16 | ->findOneBy(['user' => 1, 'isArchived' => false]); |
769e19dc J |
17 | |
18 | if (!$entry) { | |
19 | $this->markTestSkipped('No content found in db.'); | |
20 | } | |
21 | ||
fcb1fba5 NL |
22 | $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); |
23 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
769e19dc | 24 | |
fcb1fba5 | 25 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
26 | |
27 | $this->assertEquals($entry->getTitle(), $content['title']); | |
28 | $this->assertEquals($entry->getUrl(), $content['url']); | |
29 | $this->assertCount(count($entry->getTags()), $content['tags']); | |
bc44aa57 TC |
30 | $this->assertEquals($entry->getUserName(), $content['user_name']); |
31 | $this->assertEquals($entry->getUserEmail(), $content['user_email']); | |
32 | $this->assertEquals($entry->getUserId(), $content['user_id']); | |
769e19dc J |
33 | |
34 | $this->assertTrue( | |
fcb1fba5 | 35 | $this->client->getResponse()->headers->contains( |
769e19dc J |
36 | 'Content-Type', |
37 | 'application/json' | |
38 | ) | |
39 | ); | |
40 | } | |
41 | ||
42 | public function testGetOneEntryWrongUser() | |
43 | { | |
fcb1fba5 | 44 | $entry = $this->client->getContainer() |
769e19dc J |
45 | ->get('doctrine.orm.entity_manager') |
46 | ->getRepository('WallabagCoreBundle:Entry') | |
4094ea47 | 47 | ->findOneBy(['user' => 2, 'isArchived' => false]); |
769e19dc J |
48 | |
49 | if (!$entry) { | |
50 | $this->markTestSkipped('No content found in db.'); | |
51 | } | |
52 | ||
fcb1fba5 | 53 | $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); |
769e19dc | 54 | |
fcb1fba5 | 55 | $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); |
769e19dc J |
56 | } |
57 | ||
58 | public function testGetEntries() | |
59 | { | |
fcb1fba5 | 60 | $this->client->request('GET', '/api/entries'); |
769e19dc | 61 | |
fcb1fba5 | 62 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 63 | |
fcb1fba5 | 64 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
65 | |
66 | $this->assertGreaterThanOrEqual(1, count($content)); | |
67 | $this->assertNotEmpty($content['_embedded']['items']); | |
68 | $this->assertGreaterThanOrEqual(1, $content['total']); | |
69 | $this->assertEquals(1, $content['page']); | |
70 | $this->assertGreaterThanOrEqual(1, $content['pages']); | |
71 | ||
72 | $this->assertTrue( | |
fcb1fba5 | 73 | $this->client->getResponse()->headers->contains( |
769e19dc J |
74 | 'Content-Type', |
75 | 'application/json' | |
76 | ) | |
77 | ); | |
78 | } | |
79 | ||
80 | public function testGetStarredEntries() | |
81 | { | |
4094ea47 | 82 | $this->client->request('GET', '/api/entries', ['star' => 1, 'sort' => 'updated']); |
769e19dc | 83 | |
fcb1fba5 | 84 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
e6f55346 | 85 | |
fcb1fba5 | 86 | $content = json_decode($this->client->getResponse()->getContent(), true); |
e6f55346 JB |
87 | |
88 | $this->assertGreaterThanOrEqual(1, count($content)); | |
89 | $this->assertNotEmpty($content['_embedded']['items']); | |
90 | $this->assertGreaterThanOrEqual(1, $content['total']); | |
91 | $this->assertEquals(1, $content['page']); | |
92 | $this->assertGreaterThanOrEqual(1, $content['pages']); | |
93 | ||
94 | $this->assertTrue( | |
fcb1fba5 | 95 | $this->client->getResponse()->headers->contains( |
e6f55346 JB |
96 | 'Content-Type', |
97 | 'application/json' | |
98 | ) | |
99 | ); | |
100 | } | |
101 | ||
102 | public function testGetArchiveEntries() | |
103 | { | |
4094ea47 | 104 | $this->client->request('GET', '/api/entries', ['archive' => 1]); |
769e19dc | 105 | |
fcb1fba5 | 106 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 107 | |
fcb1fba5 | 108 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
109 | |
110 | $this->assertGreaterThanOrEqual(1, count($content)); | |
9744e971 | 111 | $this->assertNotEmpty($content['_embedded']['items']); |
28803f10 TC |
112 | $this->assertGreaterThanOrEqual(1, $content['total']); |
113 | $this->assertEquals(1, $content['page']); | |
114 | $this->assertGreaterThanOrEqual(1, $content['pages']); | |
115 | ||
116 | $this->assertTrue( | |
117 | $this->client->getResponse()->headers->contains( | |
118 | 'Content-Type', | |
119 | 'application/json' | |
120 | ) | |
121 | ); | |
122 | } | |
123 | ||
124 | public function testGetTaggedEntries() | |
125 | { | |
126 | $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']); | |
127 | ||
128 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
129 | ||
130 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
131 | ||
132 | $this->assertGreaterThanOrEqual(1, count($content)); | |
133 | $this->assertNotEmpty($content['_embedded']['items']); | |
9744e971 | 134 | $this->assertGreaterThanOrEqual(1, $content['total']); |
769e19dc | 135 | $this->assertEquals(1, $content['page']); |
9744e971 | 136 | $this->assertGreaterThanOrEqual(1, $content['pages']); |
769e19dc J |
137 | |
138 | $this->assertTrue( | |
fcb1fba5 | 139 | $this->client->getResponse()->headers->contains( |
769e19dc J |
140 | 'Content-Type', |
141 | 'application/json' | |
142 | ) | |
143 | ); | |
144 | } | |
145 | ||
e5fb89e5 TC |
146 | public function testGetDatedEntries() |
147 | { | |
148 | $this->client->request('GET', '/api/entries', ['since' => 1]); | |
149 | ||
150 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
151 | ||
152 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
153 | ||
154 | $this->assertGreaterThanOrEqual(1, count($content)); | |
155 | $this->assertNotEmpty($content['_embedded']['items']); | |
156 | $this->assertGreaterThanOrEqual(1, $content['total']); | |
157 | $this->assertEquals(1, $content['page']); | |
158 | $this->assertGreaterThanOrEqual(1, $content['pages']); | |
159 | ||
160 | $this->assertTrue( | |
161 | $this->client->getResponse()->headers->contains( | |
162 | 'Content-Type', | |
163 | 'application/json' | |
164 | ) | |
165 | ); | |
166 | } | |
167 | ||
168 | public function testGetDatedSupEntries() | |
169 | { | |
170 | $future = new \DateTime(date('Y-m-d H:i:s')); | |
171 | $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]); | |
172 | ||
173 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
174 | ||
175 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
176 | ||
177 | $this->assertGreaterThanOrEqual(1, count($content)); | |
178 | $this->assertEmpty($content['_embedded']['items']); | |
179 | $this->assertEquals(0, $content['total']); | |
180 | $this->assertEquals(1, $content['page']); | |
181 | $this->assertEquals(1, $content['pages']); | |
182 | ||
183 | $this->assertTrue( | |
184 | $this->client->getResponse()->headers->contains( | |
185 | 'Content-Type', | |
186 | 'application/json' | |
187 | ) | |
188 | ); | |
189 | } | |
190 | ||
769e19dc J |
191 | public function testDeleteEntry() |
192 | { | |
fcb1fba5 | 193 | $entry = $this->client->getContainer() |
769e19dc J |
194 | ->get('doctrine.orm.entity_manager') |
195 | ->getRepository('WallabagCoreBundle:Entry') | |
196 | ->findOneByUser(1); | |
197 | ||
198 | if (!$entry) { | |
199 | $this->markTestSkipped('No content found in db.'); | |
200 | } | |
201 | ||
fcb1fba5 | 202 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); |
769e19dc | 203 | |
fcb1fba5 | 204 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 205 | |
fcb1fba5 | 206 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
207 | |
208 | $this->assertEquals($entry->getTitle(), $content['title']); | |
209 | $this->assertEquals($entry->getUrl(), $content['url']); | |
210 | ||
211 | // We'll try to delete this entry again | |
fcb1fba5 | 212 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); |
769e19dc | 213 | |
fcb1fba5 | 214 | $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); |
769e19dc J |
215 | } |
216 | ||
217 | public function testPostEntry() | |
218 | { | |
4094ea47 | 219 | $this->client->request('POST', '/api/entries.json', [ |
769e19dc J |
220 | 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', |
221 | 'tags' => 'google', | |
51a15609 | 222 | 'title' => 'New title for my article', |
4094ea47 | 223 | ]); |
769e19dc | 224 | |
fcb1fba5 | 225 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 226 | |
fcb1fba5 | 227 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
228 | |
229 | $this->assertGreaterThan(0, $content['id']); | |
230 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); | |
231 | $this->assertEquals(false, $content['is_archived']); | |
232 | $this->assertEquals(false, $content['is_starred']); | |
51a15609 | 233 | $this->assertEquals('New title for my article', $content['title']); |
bc44aa57 | 234 | $this->assertEquals(1, $content['user_id']); |
769e19dc J |
235 | $this->assertCount(1, $content['tags']); |
236 | } | |
237 | ||
3107f92a TC |
238 | public function testPostSameEntry() |
239 | { | |
4094ea47 | 240 | $this->client->request('POST', '/api/entries.json', [ |
3107f92a TC |
241 | 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', |
242 | 'archive' => '1', | |
2baca964 | 243 | 'tags' => 'google, apple', |
4094ea47 | 244 | ]); |
3107f92a TC |
245 | |
246 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
247 | ||
248 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
249 | ||
250 | $this->assertGreaterThan(0, $content['id']); | |
251 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); | |
252 | $this->assertEquals(true, $content['is_archived']); | |
253 | $this->assertEquals(false, $content['is_starred']); | |
2baca964 | 254 | $this->assertCount(2, $content['tags']); |
3107f92a TC |
255 | } |
256 | ||
09d8bb6f | 257 | public function testPostArchivedAndStarredEntry() |
816ad405 | 258 | { |
4094ea47 | 259 | $this->client->request('POST', '/api/entries.json', [ |
816ad405 | 260 | 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', |
189ef634 TC |
261 | 'archive' => '1', |
262 | 'starred' => '1', | |
4094ea47 | 263 | ]); |
816ad405 TC |
264 | |
265 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
266 | ||
267 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
268 | ||
269 | $this->assertGreaterThan(0, $content['id']); | |
270 | $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); | |
271 | $this->assertEquals(true, $content['is_archived']); | |
09d8bb6f | 272 | $this->assertEquals(true, $content['is_starred']); |
bc44aa57 | 273 | $this->assertEquals(1, $content['user_id']); |
816ad405 TC |
274 | } |
275 | ||
2f60e5ea TC |
276 | public function testPostArchivedAndStarredEntryWithoutQuotes() |
277 | { | |
4094ea47 | 278 | $this->client->request('POST', '/api/entries.json', [ |
2f60e5ea TC |
279 | 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', |
280 | 'archive' => 0, | |
281 | 'starred' => 1, | |
4094ea47 | 282 | ]); |
2f60e5ea TC |
283 | |
284 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
285 | ||
286 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
287 | ||
288 | $this->assertGreaterThan(0, $content['id']); | |
289 | $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); | |
290 | $this->assertEquals(false, $content['is_archived']); | |
291 | $this->assertEquals(true, $content['is_starred']); | |
292 | } | |
293 | ||
769e19dc J |
294 | public function testPatchEntry() |
295 | { | |
fcb1fba5 | 296 | $entry = $this->client->getContainer() |
769e19dc J |
297 | ->get('doctrine.orm.entity_manager') |
298 | ->getRepository('WallabagCoreBundle:Entry') | |
299 | ->findOneByUser(1); | |
300 | ||
301 | if (!$entry) { | |
302 | $this->markTestSkipped('No content found in db.'); | |
303 | } | |
304 | ||
305 | // hydrate the tags relations | |
306 | $nbTags = count($entry->getTags()); | |
307 | ||
4094ea47 | 308 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ |
769e19dc J |
309 | 'title' => 'New awesome title', |
310 | 'tags' => 'new tag '.uniqid(), | |
189ef634 TC |
311 | 'starred' => '1', |
312 | 'archive' => '0', | |
4094ea47 | 313 | ]); |
769e19dc | 314 | |
fcb1fba5 | 315 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 316 | |
fcb1fba5 | 317 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
318 | |
319 | $this->assertEquals($entry->getId(), $content['id']); | |
320 | $this->assertEquals($entry->getUrl(), $content['url']); | |
321 | $this->assertEquals('New awesome title', $content['title']); | |
322 | $this->assertGreaterThan($nbTags, count($content['tags'])); | |
bc44aa57 | 323 | $this->assertEquals(1, $content['user_id']); |
769e19dc J |
324 | } |
325 | ||
2f60e5ea TC |
326 | public function testPatchEntryWithoutQuotes() |
327 | { | |
328 | $entry = $this->client->getContainer() | |
329 | ->get('doctrine.orm.entity_manager') | |
330 | ->getRepository('WallabagCoreBundle:Entry') | |
331 | ->findOneByUser(1); | |
332 | ||
333 | if (!$entry) { | |
334 | $this->markTestSkipped('No content found in db.'); | |
335 | } | |
336 | ||
337 | // hydrate the tags relations | |
338 | $nbTags = count($entry->getTags()); | |
339 | ||
4094ea47 | 340 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ |
2f60e5ea TC |
341 | 'title' => 'New awesome title', |
342 | 'tags' => 'new tag '.uniqid(), | |
343 | 'starred' => 1, | |
344 | 'archive' => 0, | |
4094ea47 | 345 | ]); |
2f60e5ea TC |
346 | |
347 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
348 | ||
349 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
350 | ||
351 | $this->assertEquals($entry->getId(), $content['id']); | |
352 | $this->assertEquals($entry->getUrl(), $content['url']); | |
353 | $this->assertEquals('New awesome title', $content['title']); | |
354 | $this->assertGreaterThan($nbTags, count($content['tags'])); | |
355 | } | |
356 | ||
769e19dc J |
357 | public function testGetTagsEntry() |
358 | { | |
fcb1fba5 | 359 | $entry = $this->client->getContainer() |
769e19dc J |
360 | ->get('doctrine.orm.entity_manager') |
361 | ->getRepository('WallabagCoreBundle:Entry') | |
362 | ->findOneWithTags(1); | |
363 | ||
364 | $entry = $entry[0]; | |
365 | ||
366 | if (!$entry) { | |
367 | $this->markTestSkipped('No content found in db.'); | |
368 | } | |
369 | ||
4094ea47 | 370 | $tags = []; |
769e19dc | 371 | foreach ($entry->getTags() as $tag) { |
4094ea47 | 372 | $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()]; |
769e19dc J |
373 | } |
374 | ||
fcb1fba5 | 375 | $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags'); |
769e19dc | 376 | |
fcb1fba5 | 377 | $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent()); |
769e19dc J |
378 | } |
379 | ||
380 | public function testPostTagsOnEntry() | |
381 | { | |
fcb1fba5 | 382 | $entry = $this->client->getContainer() |
769e19dc J |
383 | ->get('doctrine.orm.entity_manager') |
384 | ->getRepository('WallabagCoreBundle:Entry') | |
385 | ->findOneByUser(1); | |
386 | ||
387 | if (!$entry) { | |
388 | $this->markTestSkipped('No content found in db.'); | |
389 | } | |
390 | ||
391 | $nbTags = count($entry->getTags()); | |
392 | ||
393 | $newTags = 'tag1,tag2,tag3'; | |
394 | ||
4094ea47 | 395 | $this->client->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]); |
769e19dc | 396 | |
fcb1fba5 | 397 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 398 | |
fcb1fba5 | 399 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
400 | |
401 | $this->assertArrayHasKey('tags', $content); | |
4346a860 | 402 | $this->assertEquals($nbTags + 3, count($content['tags'])); |
769e19dc | 403 | |
fcb1fba5 | 404 | $entryDB = $this->client->getContainer() |
769e19dc J |
405 | ->get('doctrine.orm.entity_manager') |
406 | ->getRepository('WallabagCoreBundle:Entry') | |
407 | ->find($entry->getId()); | |
408 | ||
4094ea47 | 409 | $tagsInDB = []; |
769e19dc J |
410 | foreach ($entryDB->getTags()->toArray() as $tag) { |
411 | $tagsInDB[$tag->getId()] = $tag->getLabel(); | |
412 | } | |
413 | ||
414 | foreach (explode(',', $newTags) as $tag) { | |
415 | $this->assertContains($tag, $tagsInDB); | |
416 | } | |
417 | } | |
418 | ||
fcb1fba5 | 419 | public function testDeleteOneTagEntry() |
769e19dc | 420 | { |
fcb1fba5 | 421 | $entry = $this->client->getContainer() |
769e19dc J |
422 | ->get('doctrine.orm.entity_manager') |
423 | ->getRepository('WallabagCoreBundle:Entry') | |
fcb1fba5 NL |
424 | ->findOneWithTags(1); |
425 | $entry = $entry[0]; | |
769e19dc J |
426 | |
427 | if (!$entry) { | |
428 | $this->markTestSkipped('No content found in db.'); | |
429 | } | |
430 | ||
431 | // hydrate the tags relations | |
432 | $nbTags = count($entry->getTags()); | |
433 | $tag = $entry->getTags()[0]; | |
434 | ||
fcb1fba5 | 435 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json'); |
769e19dc | 436 | |
fcb1fba5 | 437 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 438 | |
fcb1fba5 | 439 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
440 | |
441 | $this->assertArrayHasKey('tags', $content); | |
4346a860 | 442 | $this->assertEquals($nbTags - 1, count($content['tags'])); |
769e19dc J |
443 | } |
444 | ||
445 | public function testGetUserTags() | |
446 | { | |
fcb1fba5 | 447 | $this->client->request('GET', '/api/tags.json'); |
769e19dc | 448 | |
fcb1fba5 | 449 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 450 | |
fcb1fba5 | 451 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
452 | |
453 | $this->assertGreaterThan(0, $content); | |
454 | $this->assertArrayHasKey('id', $content[0]); | |
455 | $this->assertArrayHasKey('label', $content[0]); | |
456 | ||
457 | return end($content); | |
458 | } | |
459 | ||
460 | /** | |
461 | * @depends testGetUserTags | |
462 | */ | |
463 | public function testDeleteUserTag($tag) | |
464 | { | |
fcb1fba5 | 465 | $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); |
769e19dc | 466 | |
fcb1fba5 | 467 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
769e19dc | 468 | |
fcb1fba5 | 469 | $content = json_decode($this->client->getResponse()->getContent(), true); |
769e19dc J |
470 | |
471 | $this->assertArrayHasKey('label', $content); | |
472 | $this->assertEquals($tag['label'], $content['label']); | |
fc732227 | 473 | $this->assertEquals($tag['slug'], $content['slug']); |
4059a061 JB |
474 | |
475 | $entries = $entry = $this->client->getContainer() | |
476 | ->get('doctrine.orm.entity_manager') | |
477 | ->getRepository('WallabagCoreBundle:Entry') | |
478 | ->findAllByTagId($this->user->getId(), $tag['id']); | |
479 | ||
480 | $this->assertCount(0, $entries); | |
769e19dc | 481 | } |
9761bfa1 | 482 | |
6f8310b4 TC |
483 | public function testGetVersion() |
484 | { | |
485 | $this->client->request('GET', '/api/version'); | |
9761bfa1 V |
486 | |
487 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
488 | ||
489 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
490 | ||
6f8310b4 | 491 | $this->assertEquals($this->client->getContainer()->getParameter('wallabag_core.version'), $content); |
9761bfa1 | 492 | } |
bba271e6 YE |
493 | |
494 | public function testSaveIsArchivedAfterPost() | |
495 | { | |
496 | $entry = $this->client->getContainer() | |
497 | ->get('doctrine.orm.entity_manager') | |
498 | ->getRepository('WallabagCoreBundle:Entry') | |
499 | ->findOneBy(['user' => 1, 'isArchived' => true]); | |
500 | ||
501 | if (!$entry) { | |
502 | $this->markTestSkipped('No content found in db.'); | |
503 | } | |
504 | ||
505 | $this->client->request('POST', '/api/entries.json', [ | |
506 | 'url' => $entry->getUrl(), | |
507 | ]); | |
508 | ||
509 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
510 | ||
511 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
512 | ||
69221684 | 513 | $this->assertEquals(true, $content['is_archived']); |
bba271e6 YE |
514 | } |
515 | ||
516 | public function testSaveIsStarredAfterPost() | |
517 | { | |
518 | $entry = $this->client->getContainer() | |
519 | ->get('doctrine.orm.entity_manager') | |
520 | ->getRepository('WallabagCoreBundle:Entry') | |
521 | ->findOneBy(['user' => 1, 'isStarred' => true]); | |
522 | ||
523 | if (!$entry) { | |
524 | $this->markTestSkipped('No content found in db.'); | |
525 | } | |
526 | ||
527 | $this->client->request('POST', '/api/entries.json', [ | |
528 | 'url' => $entry->getUrl(), | |
529 | ]); | |
530 | ||
531 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
532 | ||
533 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
534 | ||
69221684 | 535 | $this->assertEquals(true, $content['is_starred']); |
bba271e6 YE |
536 | } |
537 | ||
538 | public function testSaveIsArchivedAfterPatch() | |
539 | { | |
540 | $entry = $this->client->getContainer() | |
541 | ->get('doctrine.orm.entity_manager') | |
542 | ->getRepository('WallabagCoreBundle:Entry') | |
543 | ->findOneBy(['user' => 1, 'isArchived' => true]); | |
544 | ||
545 | if (!$entry) { | |
546 | $this->markTestSkipped('No content found in db.'); | |
547 | } | |
548 | ||
549 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ | |
550 | 'title' => $entry->getTitle().'++', | |
551 | ]); | |
552 | ||
553 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
554 | ||
555 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
556 | ||
557 | $this->assertEquals(true, $content['is_archived']); | |
558 | } | |
559 | ||
560 | public function testSaveIsStarredAfterPatch() | |
561 | { | |
562 | $entry = $this->client->getContainer() | |
563 | ->get('doctrine.orm.entity_manager') | |
564 | ->getRepository('WallabagCoreBundle:Entry') | |
565 | ->findOneBy(['user' => 1, 'isStarred' => true]); | |
566 | ||
567 | if (!$entry) { | |
568 | $this->markTestSkipped('No content found in db.'); | |
569 | } | |
570 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ | |
571 | 'title' => $entry->getTitle().'++', | |
572 | ]); | |
573 | ||
574 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | |
575 | ||
576 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
577 | ||
69221684 | 578 | $this->assertEquals(true, $content['is_starred']); |
bba271e6 | 579 | } |
769e19dc | 580 | } |