diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 218 |
1 files changed, 177 insertions, 41 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 58b617f3..8b7898ee 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -15,7 +15,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
15 | $entry = $this->client->getContainer() | 15 | $entry = $this->client->getContainer() |
16 | ->get('doctrine.orm.entity_manager') | 16 | ->get('doctrine.orm.entity_manager') |
17 | ->getRepository('WallabagCoreBundle:Entry') | 17 | ->getRepository('WallabagCoreBundle:Entry') |
18 | ->findOneBy(['user' => 1, 'isArchived' => false]); | 18 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]); |
19 | 19 | ||
20 | if (!$entry) { | 20 | if (!$entry) { |
21 | $this->markTestSkipped('No content found in db.'); | 21 | $this->markTestSkipped('No content found in db.'); |
@@ -41,7 +41,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
41 | $entry = $this->client->getContainer() | 41 | $entry = $this->client->getContainer() |
42 | ->get('doctrine.orm.entity_manager') | 42 | ->get('doctrine.orm.entity_manager') |
43 | ->getRepository('WallabagCoreBundle:Entry') | 43 | ->getRepository('WallabagCoreBundle:Entry') |
44 | ->findOneBy(['user' => 1, 'url' => 'http://0.0.0.0/entry2']); | 44 | ->findOneBy(['user' => $this->getUserId(), 'url' => 'http://0.0.0.0/entry2']); |
45 | 45 | ||
46 | if (!$entry) { | 46 | if (!$entry) { |
47 | $this->markTestSkipped('No content found in db.'); | 47 | $this->markTestSkipped('No content found in db.'); |
@@ -60,7 +60,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
60 | $entry = $this->client->getContainer() | 60 | $entry = $this->client->getContainer() |
61 | ->get('doctrine.orm.entity_manager') | 61 | ->get('doctrine.orm.entity_manager') |
62 | ->getRepository('WallabagCoreBundle:Entry') | 62 | ->getRepository('WallabagCoreBundle:Entry') |
63 | ->findOneBy(['user' => 1, 'isArchived' => false]); | 63 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]); |
64 | 64 | ||
65 | if (!$entry) { | 65 | if (!$entry) { |
66 | $this->markTestSkipped('No content found in db.'); | 66 | $this->markTestSkipped('No content found in db.'); |
@@ -108,7 +108,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
108 | $entry = $this->client->getContainer() | 108 | $entry = $this->client->getContainer() |
109 | ->get('doctrine.orm.entity_manager') | 109 | ->get('doctrine.orm.entity_manager') |
110 | ->getRepository('WallabagCoreBundle:Entry') | 110 | ->getRepository('WallabagCoreBundle:Entry') |
111 | ->findOneBy(['user' => 2, 'isArchived' => false]); | 111 | ->findOneBy(['user' => $this->getUserId('bob'), 'isArchived' => false]); |
112 | 112 | ||
113 | if (!$entry) { | 113 | if (!$entry) { |
114 | $this->markTestSkipped('No content found in db.'); | 114 | $this->markTestSkipped('No content found in db.'); |
@@ -133,6 +133,27 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
133 | $this->assertSame(1, $content['page']); | 133 | $this->assertSame(1, $content['page']); |
134 | $this->assertGreaterThanOrEqual(1, $content['pages']); | 134 | $this->assertGreaterThanOrEqual(1, $content['pages']); |
135 | 135 | ||
136 | $this->assertNotNull($content['_embedded']['items'][0]['content']); | ||
137 | |||
138 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
139 | } | ||
140 | |||
141 | public function testGetEntriesDetailMetadata() | ||
142 | { | ||
143 | $this->client->request('GET', '/api/entries?detail=metadata'); | ||
144 | |||
145 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
146 | |||
147 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
148 | |||
149 | $this->assertGreaterThanOrEqual(1, \count($content)); | ||
150 | $this->assertNotEmpty($content['_embedded']['items']); | ||
151 | $this->assertGreaterThanOrEqual(1, $content['total']); | ||
152 | $this->assertSame(1, $content['page']); | ||
153 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
154 | |||
155 | $this->assertNull($content['_embedded']['items'][0]['content']); | ||
156 | |||
136 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | 157 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
137 | } | 158 | } |
138 | 159 | ||
@@ -185,7 +206,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
185 | $entry = $this->client->getContainer() | 206 | $entry = $this->client->getContainer() |
186 | ->get('doctrine.orm.entity_manager') | 207 | ->get('doctrine.orm.entity_manager') |
187 | ->getRepository('WallabagCoreBundle:Entry') | 208 | ->getRepository('WallabagCoreBundle:Entry') |
188 | ->findOneByUser(1); | 209 | ->findOneByUser($this->getUserId()); |
189 | 210 | ||
190 | if (!$entry) { | 211 | if (!$entry) { |
191 | $this->markTestSkipped('No content found in db.'); | 212 | $this->markTestSkipped('No content found in db.'); |
@@ -242,6 +263,15 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
242 | $this->assertSame(2, $content['limit']); | 263 | $this->assertSame(2, $content['limit']); |
243 | } | 264 | } |
244 | 265 | ||
266 | public function testGetStarredEntriesWithBadSort() | ||
267 | { | ||
268 | $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated', 'order' => 'unknown']); | ||
269 | |||
270 | $this->assertSame(400, $this->client->getResponse()->getStatusCode()); | ||
271 | |||
272 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
273 | } | ||
274 | |||
245 | public function testGetStarredEntries() | 275 | public function testGetStarredEntries() |
246 | { | 276 | { |
247 | $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); | 277 | $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); |
@@ -391,29 +421,71 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
391 | 421 | ||
392 | public function testDeleteEntry() | 422 | public function testDeleteEntry() |
393 | { | 423 | { |
394 | $entry = $this->client->getContainer() | 424 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
395 | ->get('doctrine.orm.entity_manager') | 425 | $entry = new Entry($em->getReference(User::class, 1)); |
396 | ->getRepository('WallabagCoreBundle:Entry') | 426 | $entry->setUrl('http://0.0.0.0/test-delete-entry'); |
397 | ->findOneByUser(1, ['id' => 'asc']); | 427 | $entry->setTitle('Test delete entry'); |
428 | $em->persist($entry); | ||
429 | $em->flush(); | ||
398 | 430 | ||
399 | if (!$entry) { | 431 | $em->clear(); |
400 | $this->markTestSkipped('No content found in db.'); | ||
401 | } | ||
402 | 432 | ||
403 | $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); | 433 | $e = [ |
434 | 'title' => $entry->getTitle(), | ||
435 | 'url' => $entry->getUrl(), | ||
436 | 'id' => $entry->getId(), | ||
437 | ]; | ||
438 | |||
439 | $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json'); | ||
404 | 440 | ||
405 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 441 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
406 | 442 | ||
407 | $content = json_decode($this->client->getResponse()->getContent(), true); | 443 | $content = json_decode($this->client->getResponse()->getContent(), true); |
408 | 444 | ||
409 | $this->assertSame($entry->getTitle(), $content['title']); | 445 | $this->assertSame($e['title'], $content['title']); |
410 | $this->assertSame($entry->getUrl(), $content['url']); | 446 | $this->assertSame($e['url'], $content['url']); |
411 | $this->assertSame($entry->getId(), $content['id']); | 447 | $this->assertSame($e['id'], $content['id']); |
448 | |||
449 | // We'll try to delete this entry again | ||
450 | $client = $this->createAuthorizedClient(); | ||
451 | $client->request('DELETE', '/api/entries/' . $e['id'] . '.json'); | ||
452 | |||
453 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | ||
454 | } | ||
455 | |||
456 | public function testDeleteEntryExpectId() | ||
457 | { | ||
458 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
459 | $entry = new Entry($em->getReference(User::class, 1)); | ||
460 | $entry->setUrl('http://0.0.0.0/test-delete-entry-id'); | ||
461 | $em->persist($entry); | ||
462 | $em->flush(); | ||
463 | |||
464 | $em->clear(); | ||
465 | |||
466 | $id = $entry->getId(); | ||
467 | |||
468 | $this->client->request('DELETE', '/api/entries/' . $id . '.json?expect=id'); | ||
469 | |||
470 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
471 | |||
472 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
473 | |||
474 | $this->assertSame($id, $content['id']); | ||
475 | $this->assertArrayNotHasKey('url', $content); | ||
412 | 476 | ||
413 | // We'll try to delete this entry again | 477 | // We'll try to delete this entry again |
414 | $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); | 478 | $client = $this->createAuthorizedClient(); |
479 | $client->request('DELETE', '/api/entries/' . $id . '.json'); | ||
415 | 480 | ||
416 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); | 481 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
482 | } | ||
483 | |||
484 | public function testDeleteEntryExpectBadRequest() | ||
485 | { | ||
486 | $this->client->request('DELETE', '/api/entries/1.json?expect=badrequest'); | ||
487 | |||
488 | $this->assertSame(400, $this->client->getResponse()->getStatusCode()); | ||
417 | } | 489 | } |
418 | 490 | ||
419 | public function testPostEntry() | 491 | public function testPostEntry() |
@@ -438,8 +510,9 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
438 | $this->assertSame(0, $content['is_archived']); | 510 | $this->assertSame(0, $content['is_archived']); |
439 | $this->assertSame(0, $content['is_starred']); | 511 | $this->assertSame(0, $content['is_starred']); |
440 | $this->assertNull($content['starred_at']); | 512 | $this->assertNull($content['starred_at']); |
513 | $this->assertNull($content['archived_at']); | ||
441 | $this->assertSame('New title for my article', $content['title']); | 514 | $this->assertSame('New title for my article', $content['title']); |
442 | $this->assertSame(1, $content['user_id']); | 515 | $this->assertSame($this->getUserId(), $content['user_id']); |
443 | $this->assertCount(2, $content['tags']); | 516 | $this->assertCount(2, $content['tags']); |
444 | $this->assertNull($content['origin_url']); | 517 | $this->assertNull($content['origin_url']); |
445 | $this->assertSame('my content', $content['content']); | 518 | $this->assertSame('my content', $content['content']); |
@@ -454,7 +527,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
454 | public function testPostSameEntry() | 527 | public function testPostSameEntry() |
455 | { | 528 | { |
456 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 529 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
457 | $entry = new Entry($em->getReference(User::class, 1)); | 530 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
458 | $entry->setUrl('https://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'); | 531 | $entry->setUrl('https://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'); |
459 | $entry->setArchived(true); | 532 | $entry->setArchived(true); |
460 | $entry->addTag((new Tag())->setLabel('google')); | 533 | $entry->addTag((new Tag())->setLabel('google')); |
@@ -533,7 +606,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
533 | $this->assertSame(1, $content['is_archived']); | 606 | $this->assertSame(1, $content['is_archived']); |
534 | $this->assertSame(1, $content['is_starred']); | 607 | $this->assertSame(1, $content['is_starred']); |
535 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); | 608 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); |
536 | $this->assertSame(1, $content['user_id']); | 609 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp()); |
610 | $this->assertSame($this->getUserId(), $content['user_id']); | ||
537 | } | 611 | } |
538 | 612 | ||
539 | public function testPostArchivedAndStarredEntryWithoutQuotes() | 613 | public function testPostArchivedAndStarredEntryWithoutQuotes() |
@@ -582,7 +656,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
582 | $entry = $this->client->getContainer() | 656 | $entry = $this->client->getContainer() |
583 | ->get('doctrine.orm.entity_manager') | 657 | ->get('doctrine.orm.entity_manager') |
584 | ->getRepository('WallabagCoreBundle:Entry') | 658 | ->getRepository('WallabagCoreBundle:Entry') |
585 | ->findOneByUser(1); | 659 | ->findOneByUser($this->getUserId()); |
586 | 660 | ||
587 | if (!$entry) { | 661 | if (!$entry) { |
588 | $this->markTestSkipped('No content found in db.'); | 662 | $this->markTestSkipped('No content found in db.'); |
@@ -609,7 +683,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
609 | $this->assertSame($entry->getUrl(), $content['url']); | 683 | $this->assertSame($entry->getUrl(), $content['url']); |
610 | $this->assertSame('New awesome title', $content['title']); | 684 | $this->assertSame('New awesome title', $content['title']); |
611 | $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); | 685 | $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); |
612 | $this->assertSame(1, $content['user_id']); | 686 | $this->assertSame($this->getUserId(), $content['user_id']); |
613 | $this->assertSame('de_AT', $content['language']); | 687 | $this->assertSame('de_AT', $content['language']); |
614 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); | 688 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); |
615 | $this->assertContains('sponge', $content['published_by']); | 689 | $this->assertContains('sponge', $content['published_by']); |
@@ -624,7 +698,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
624 | $entry = $this->client->getContainer() | 698 | $entry = $this->client->getContainer() |
625 | ->get('doctrine.orm.entity_manager') | 699 | ->get('doctrine.orm.entity_manager') |
626 | ->getRepository('WallabagCoreBundle:Entry') | 700 | ->getRepository('WallabagCoreBundle:Entry') |
627 | ->findOneByUser(1); | 701 | ->findOneByUser($this->getUserId()); |
628 | 702 | ||
629 | if (!$entry) { | 703 | if (!$entry) { |
630 | $this->markTestSkipped('No content found in db.'); | 704 | $this->markTestSkipped('No content found in db.'); |
@@ -658,7 +732,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
658 | $entry = $this->client->getContainer() | 732 | $entry = $this->client->getContainer() |
659 | ->get('doctrine.orm.entity_manager') | 733 | ->get('doctrine.orm.entity_manager') |
660 | ->getRepository('WallabagCoreBundle:Entry') | 734 | ->getRepository('WallabagCoreBundle:Entry') |
661 | ->findOneByUser(1); | 735 | ->findOneByUser($this->getUserId()); |
662 | 736 | ||
663 | if (!$entry) { | 737 | if (!$entry) { |
664 | $this->markTestSkipped('No content found in db.'); | 738 | $this->markTestSkipped('No content found in db.'); |
@@ -689,7 +763,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
689 | $entry = $this->client->getContainer() | 763 | $entry = $this->client->getContainer() |
690 | ->get('doctrine.orm.entity_manager') | 764 | ->get('doctrine.orm.entity_manager') |
691 | ->getRepository('WallabagCoreBundle:Entry') | 765 | ->getRepository('WallabagCoreBundle:Entry') |
692 | ->findOneByUser(1); | 766 | ->findOneByUser($this->getUserId()); |
693 | 767 | ||
694 | if (!$entry) { | 768 | if (!$entry) { |
695 | $this->markTestSkipped('No content found in db.'); | 769 | $this->markTestSkipped('No content found in db.'); |
@@ -721,7 +795,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
721 | $entry = $this->client->getContainer() | 795 | $entry = $this->client->getContainer() |
722 | ->get('doctrine.orm.entity_manager') | 796 | ->get('doctrine.orm.entity_manager') |
723 | ->getRepository('WallabagCoreBundle:Entry') | 797 | ->getRepository('WallabagCoreBundle:Entry') |
724 | ->findOneByUser(1); | 798 | ->findOneByUser($this->getUserId()); |
725 | 799 | ||
726 | if (!$entry) { | 800 | if (!$entry) { |
727 | $this->markTestSkipped('No content found in db.'); | 801 | $this->markTestSkipped('No content found in db.'); |
@@ -766,7 +840,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
766 | $entry = $this->client->getContainer() | 840 | $entry = $this->client->getContainer() |
767 | ->get('doctrine.orm.entity_manager') | 841 | ->get('doctrine.orm.entity_manager') |
768 | ->getRepository('WallabagCoreBundle:Entry') | 842 | ->getRepository('WallabagCoreBundle:Entry') |
769 | ->findOneByUser(1); | 843 | ->findOneByUser($this->getUserId()); |
770 | 844 | ||
771 | if (!$entry) { | 845 | if (!$entry) { |
772 | $this->markTestSkipped('No content found in db.'); | 846 | $this->markTestSkipped('No content found in db.'); |
@@ -783,7 +857,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
783 | $content = json_decode($this->client->getResponse()->getContent(), true); | 857 | $content = json_decode($this->client->getResponse()->getContent(), true); |
784 | 858 | ||
785 | $this->assertArrayHasKey('tags', $content); | 859 | $this->assertArrayHasKey('tags', $content); |
786 | $this->assertSame($nbTags + 3, \count($content['tags'])); | 860 | $this->assertCount($nbTags + 3, $content['tags']); |
787 | 861 | ||
788 | $entryDB = $this->client->getContainer() | 862 | $entryDB = $this->client->getContainer() |
789 | ->get('doctrine.orm.entity_manager') | 863 | ->get('doctrine.orm.entity_manager') |
@@ -823,7 +897,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
823 | $content = json_decode($this->client->getResponse()->getContent(), true); | 897 | $content = json_decode($this->client->getResponse()->getContent(), true); |
824 | 898 | ||
825 | $this->assertArrayHasKey('tags', $content); | 899 | $this->assertArrayHasKey('tags', $content); |
826 | $this->assertSame($nbTags - 1, \count($content['tags'])); | 900 | $this->assertCount($nbTags - 1, $content['tags']); |
827 | } | 901 | } |
828 | 902 | ||
829 | public function testSaveIsArchivedAfterPost() | 903 | public function testSaveIsArchivedAfterPost() |
@@ -831,7 +905,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
831 | $entry = $this->client->getContainer() | 905 | $entry = $this->client->getContainer() |
832 | ->get('doctrine.orm.entity_manager') | 906 | ->get('doctrine.orm.entity_manager') |
833 | ->getRepository('WallabagCoreBundle:Entry') | 907 | ->getRepository('WallabagCoreBundle:Entry') |
834 | ->findOneBy(['user' => 1, 'isArchived' => true]); | 908 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); |
835 | 909 | ||
836 | if (!$entry) { | 910 | if (!$entry) { |
837 | $this->markTestSkipped('No content found in db.'); | 911 | $this->markTestSkipped('No content found in db.'); |
@@ -853,7 +927,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
853 | $entry = $this->client->getContainer() | 927 | $entry = $this->client->getContainer() |
854 | ->get('doctrine.orm.entity_manager') | 928 | ->get('doctrine.orm.entity_manager') |
855 | ->getRepository('WallabagCoreBundle:Entry') | 929 | ->getRepository('WallabagCoreBundle:Entry') |
856 | ->findOneBy(['user' => 1, 'isStarred' => true]); | 930 | ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); |
857 | 931 | ||
858 | if (!$entry) { | 932 | if (!$entry) { |
859 | $this->markTestSkipped('No content found in db.'); | 933 | $this->markTestSkipped('No content found in db.'); |
@@ -875,7 +949,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
875 | $entry = $this->client->getContainer() | 949 | $entry = $this->client->getContainer() |
876 | ->get('doctrine.orm.entity_manager') | 950 | ->get('doctrine.orm.entity_manager') |
877 | ->getRepository('WallabagCoreBundle:Entry') | 951 | ->getRepository('WallabagCoreBundle:Entry') |
878 | ->findOneBy(['user' => 1, 'isArchived' => true]); | 952 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); |
879 | 953 | ||
880 | if (!$entry) { | 954 | if (!$entry) { |
881 | $this->markTestSkipped('No content found in db.'); | 955 | $this->markTestSkipped('No content found in db.'); |
@@ -901,7 +975,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
901 | $entry = $this->client->getContainer() | 975 | $entry = $this->client->getContainer() |
902 | ->get('doctrine.orm.entity_manager') | 976 | ->get('doctrine.orm.entity_manager') |
903 | ->getRepository('WallabagCoreBundle:Entry') | 977 | ->getRepository('WallabagCoreBundle:Entry') |
904 | ->findOneBy(['user' => 1, 'isStarred' => true]); | 978 | ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); |
905 | 979 | ||
906 | if (!$entry) { | 980 | if (!$entry) { |
907 | $this->markTestSkipped('No content found in db.'); | 981 | $this->markTestSkipped('No content found in db.'); |
@@ -920,6 +994,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
920 | 994 | ||
921 | public function dataForEntriesExistWithUrl() | 995 | public function dataForEntriesExistWithUrl() |
922 | { | 996 | { |
997 | $url = hash('sha1', 'http://0.0.0.0/entry2'); | ||
998 | |||
923 | return [ | 999 | return [ |
924 | 'with_id' => [ | 1000 | 'with_id' => [ |
925 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', | 1001 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', |
@@ -929,6 +1005,14 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
929 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', | 1005 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', |
930 | 'expectedValue' => true, | 1006 | 'expectedValue' => true, |
931 | ], | 1007 | ], |
1008 | 'hashed_url_with_id' => [ | ||
1009 | 'url' => '/api/entries/exists?hashed_url=' . $url . '&return_id=1', | ||
1010 | 'expectedValue' => 2, | ||
1011 | ], | ||
1012 | 'hashed_url_without_id' => [ | ||
1013 | 'url' => '/api/entries/exists?hashed_url=' . $url . '', | ||
1014 | 'expectedValue' => true, | ||
1015 | ], | ||
932 | ]; | 1016 | ]; |
933 | } | 1017 | } |
934 | 1018 | ||
@@ -950,6 +1034,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
950 | { | 1034 | { |
951 | $url1 = 'http://0.0.0.0/entry2'; | 1035 | $url1 = 'http://0.0.0.0/entry2'; |
952 | $url2 = 'http://0.0.0.0/entry10'; | 1036 | $url2 = 'http://0.0.0.0/entry10'; |
1037 | |||
953 | $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); | 1038 | $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); |
954 | 1039 | ||
955 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 1040 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
@@ -958,7 +1043,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
958 | 1043 | ||
959 | $this->assertArrayHasKey($url1, $content); | 1044 | $this->assertArrayHasKey($url1, $content); |
960 | $this->assertArrayHasKey($url2, $content); | 1045 | $this->assertArrayHasKey($url2, $content); |
961 | $this->assertSame(2, $content[$url1]); | 1046 | // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value |
1047 | $this->assertGreaterThan(1, $content[$url1]); | ||
962 | $this->assertNull($content[$url2]); | 1048 | $this->assertNull($content[$url2]); |
963 | } | 1049 | } |
964 | 1050 | ||
@@ -978,6 +1064,38 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
978 | $this->assertFalse($content[$url2]); | 1064 | $this->assertFalse($content[$url2]); |
979 | } | 1065 | } |
980 | 1066 | ||
1067 | public function testGetEntriesExistsWithManyUrlsHashed() | ||
1068 | { | ||
1069 | $url1 = 'http://0.0.0.0/entry2'; | ||
1070 | $url2 = 'http://0.0.0.0/entry10'; | ||
1071 | $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2) . '&return_id=1'); | ||
1072 | |||
1073 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1074 | |||
1075 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1076 | |||
1077 | $this->assertArrayHasKey(hash('sha1', $url1), $content); | ||
1078 | $this->assertArrayHasKey(hash('sha1', $url2), $content); | ||
1079 | $this->assertSame(2, $content[hash('sha1', $url1)]); | ||
1080 | $this->assertNull($content[hash('sha1', $url2)]); | ||
1081 | } | ||
1082 | |||
1083 | public function testGetEntriesExistsWithManyUrlsHashedReturnBool() | ||
1084 | { | ||
1085 | $url1 = 'http://0.0.0.0/entry2'; | ||
1086 | $url2 = 'http://0.0.0.0/entry10'; | ||
1087 | $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2)); | ||
1088 | |||
1089 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1090 | |||
1091 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1092 | |||
1093 | $this->assertArrayHasKey(hash('sha1', $url1), $content); | ||
1094 | $this->assertArrayHasKey(hash('sha1', $url2), $content); | ||
1095 | $this->assertTrue($content[hash('sha1', $url1)]); | ||
1096 | $this->assertFalse($content[hash('sha1', $url2)]); | ||
1097 | } | ||
1098 | |||
981 | public function testGetEntriesExistsWhichDoesNotExists() | 1099 | public function testGetEntriesExistsWhichDoesNotExists() |
982 | { | 1100 | { |
983 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); | 1101 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); |
@@ -989,6 +1107,17 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
989 | $this->assertFalse($content['exists']); | 1107 | $this->assertFalse($content['exists']); |
990 | } | 1108 | } |
991 | 1109 | ||
1110 | public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl() | ||
1111 | { | ||
1112 | $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2')); | ||
1113 | |||
1114 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1115 | |||
1116 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1117 | |||
1118 | $this->assertFalse($content['exists']); | ||
1119 | } | ||
1120 | |||
992 | public function testGetEntriesExistsWithNoUrl() | 1121 | public function testGetEntriesExistsWithNoUrl() |
993 | { | 1122 | { |
994 | $this->client->request('GET', '/api/entries/exists?url='); | 1123 | $this->client->request('GET', '/api/entries/exists?url='); |
@@ -996,11 +1125,18 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
996 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); | 1125 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); |
997 | } | 1126 | } |
998 | 1127 | ||
1128 | public function testGetEntriesExistsWithNoHashedUrl() | ||
1129 | { | ||
1130 | $this->client->request('GET', '/api/entries/exists?hashed_url='); | ||
1131 | |||
1132 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); | ||
1133 | } | ||
1134 | |||
999 | public function testReloadEntryErrorWhileFetching() | 1135 | public function testReloadEntryErrorWhileFetching() |
1000 | { | 1136 | { |
1001 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1137 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1002 | ->getRepository('WallabagCoreBundle:Entry') | 1138 | ->getRepository('WallabagCoreBundle:Entry') |
1003 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1139 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1004 | 1140 | ||
1005 | if (!$entry) { | 1141 | if (!$entry) { |
1006 | $this->markTestSkipped('No content found in db.'); | 1142 | $this->markTestSkipped('No content found in db.'); |
@@ -1036,7 +1172,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1036 | { | 1172 | { |
1037 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1173 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1038 | ->getRepository('WallabagCoreBundle:Entry') | 1174 | ->getRepository('WallabagCoreBundle:Entry') |
1039 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1175 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1040 | 1176 | ||
1041 | $tags = $entry->getTags(); | 1177 | $tags = $entry->getTags(); |
1042 | 1178 | ||
@@ -1060,7 +1196,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1060 | 1196 | ||
1061 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1197 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1062 | ->getRepository('WallabagCoreBundle:Entry') | 1198 | ->getRepository('WallabagCoreBundle:Entry') |
1063 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1199 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1064 | 1200 | ||
1065 | $tags = $entry->getTags(); | 1201 | $tags = $entry->getTags(); |
1066 | $this->assertCount(4, $tags); | 1202 | $this->assertCount(4, $tags); |
@@ -1080,7 +1216,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1080 | public function testDeleteEntriesTagsListAction() | 1216 | public function testDeleteEntriesTagsListAction() |
1081 | { | 1217 | { |
1082 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1218 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1083 | $entry = new Entry($em->getReference(User::class, 1)); | 1219 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
1084 | $entry->setUrl('http://0.0.0.0/test-entry'); | 1220 | $entry->setUrl('http://0.0.0.0/test-entry'); |
1085 | $entry->addTag((new Tag())->setLabel('foo-tag')); | 1221 | $entry->addTag((new Tag())->setLabel('foo-tag')); |
1086 | $entry->addTag((new Tag())->setLabel('bar-tag')); | 1222 | $entry->addTag((new Tag())->setLabel('bar-tag')); |
@@ -1148,7 +1284,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1148 | public function testDeleteEntriesListAction() | 1284 | public function testDeleteEntriesListAction() |
1149 | { | 1285 | { |
1150 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1286 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1151 | $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1')); | 1287 | $em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1')); |
1152 | 1288 | ||
1153 | $em->flush(); | 1289 | $em->flush(); |
1154 | $em->clear(); | 1290 | $em->clear(); |
@@ -1206,7 +1342,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1206 | public function testRePostEntryAndReUsePublishedAt() | 1342 | public function testRePostEntryAndReUsePublishedAt() |
1207 | { | 1343 | { |
1208 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1344 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1209 | $entry = new Entry($em->getReference(User::class, 1)); | 1345 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
1210 | $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); | 1346 | $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); |
1211 | $entry->setContent('hihi'); | 1347 | $entry->setContent('hihi'); |
1212 | $entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html'); | 1348 | $entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html'); |