aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php128
1 files changed, 128 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 95c64501..65a3ccd9 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -36,6 +36,25 @@ class EntryRestControllerTest extends WallabagApiTestCase
36 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); 36 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
37 } 37 }
38 38
39 public function testGetOneEntryWithOriginUrl()
40 {
41 $entry = $this->client->getContainer()
42 ->get('doctrine.orm.entity_manager')
43 ->getRepository('WallabagCoreBundle:Entry')
44 ->findOneBy(['user' => 1, 'url' => 'http://0.0.0.0/entry2']);
45
46 if (!$entry) {
47 $this->markTestSkipped('No content found in db.');
48 }
49
50 $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json');
51 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
52
53 $content = json_decode($this->client->getResponse()->getContent(), true);
54
55 $this->assertSame($entry->getOriginUrl(), $content['origin_url']);
56 }
57
39 public function testExportEntry() 58 public function testExportEntry()
40 { 59 {
41 $entry = $this->client->getContainer() 60 $entry = $this->client->getContainer()
@@ -421,6 +440,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
421 $this->assertSame('New title for my article', $content['title']); 440 $this->assertSame('New title for my article', $content['title']);
422 $this->assertSame(1, $content['user_id']); 441 $this->assertSame(1, $content['user_id']);
423 $this->assertCount(2, $content['tags']); 442 $this->assertCount(2, $content['tags']);
443 $this->assertNull($content['origin_url']);
424 $this->assertSame('my content', $content['content']); 444 $this->assertSame('my content', $content['content']);
425 $this->assertSame('de', $content['language']); 445 $this->assertSame('de', $content['language']);
426 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']); 446 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
@@ -531,6 +551,29 @@ class EntryRestControllerTest extends WallabagApiTestCase
531 $this->assertSame(1, $content['is_starred']); 551 $this->assertSame(1, $content['is_starred']);
532 } 552 }
533 553
554 public function testPostEntryWithOriginUrl()
555 {
556 $this->client->request('POST', '/api/entries.json', [
557 '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',
558 'tags' => 'google',
559 'title' => 'New title for my article',
560 'content' => 'my content',
561 'language' => 'de',
562 'published_at' => '2016-09-08T11:55:58+0200',
563 'authors' => 'bob,helen',
564 'public' => 1,
565 'origin_url' => 'http://mysource.tld',
566 ]);
567
568 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
569
570 $content = json_decode($this->client->getResponse()->getContent(), true);
571
572 $this->assertGreaterThan(0, $content['id']);
573 $this->assertSame('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']);
574 $this->assertSame('http://mysource.tld', $content['origin_url']);
575 }
576
534 public function testPatchEntry() 577 public function testPatchEntry()
535 { 578 {
536 $entry = $this->client->getContainer() 579 $entry = $this->client->getContainer()
@@ -607,6 +650,91 @@ class EntryRestControllerTest extends WallabagApiTestCase
607 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); 650 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
608 } 651 }
609 652
653 public function testPatchEntryWithOriginUrl()
654 {
655 $entry = $this->client->getContainer()
656 ->get('doctrine.orm.entity_manager')
657 ->getRepository('WallabagCoreBundle:Entry')
658 ->findOneByUser(1);
659
660 if (!$entry) {
661 $this->markTestSkipped('No content found in db.');
662 }
663
664 $previousContent = $entry->getContent();
665 $previousLanguage = $entry->getLanguage();
666
667 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
668 'title' => 'Another awesome title just for profit',
669 'origin_url' => 'https://myawesomesource.example.com',
670 ]);
671
672 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
673
674 $content = json_decode($this->client->getResponse()->getContent(), true);
675
676 $this->assertSame($entry->getId(), $content['id']);
677 $this->assertSame($entry->getUrl(), $content['url']);
678 $this->assertSame('https://myawesomesource.example.com', $content['origin_url']);
679 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
680 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
681 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
682 }
683
684 public function testPatchEntryRemoveOriginUrl()
685 {
686 $entry = $this->client->getContainer()
687 ->get('doctrine.orm.entity_manager')
688 ->getRepository('WallabagCoreBundle:Entry')
689 ->findOneByUser(1);
690
691 if (!$entry) {
692 $this->markTestSkipped('No content found in db.');
693 }
694
695 $previousContent = $entry->getContent();
696 $previousLanguage = $entry->getLanguage();
697 $previousTitle = $entry->getTitle();
698
699 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
700 'origin_url' => '',
701 ]);
702
703 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
704
705 $content = json_decode($this->client->getResponse()->getContent(), true);
706
707 $this->assertSame($entry->getId(), $content['id']);
708 $this->assertSame($entry->getUrl(), $content['url']);
709 $this->assertEmpty($content['origin_url']);
710 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
711 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
712 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
713 $this->assertSame($previousTitle, $content['title'], 'Ensure title has not moved');
714 }
715
716 public function testPatchEntryNullOriginUrl()
717 {
718 $entry = $this->client->getContainer()
719 ->get('doctrine.orm.entity_manager')
720 ->getRepository('WallabagCoreBundle:Entry')
721 ->findOneByUser(1);
722
723 if (!$entry) {
724 $this->markTestSkipped('No content found in db.');
725 }
726
727 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
728 'origin_url' => null,
729 ]);
730
731 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
732
733 $content = json_decode($this->client->getResponse()->getContent(), true);
734
735 $this->assertNull($content['origin_url']);
736 }
737
610 public function testGetTagsEntry() 738 public function testGetTagsEntry()
611 { 739 {
612 $entry = $this->client->getContainer() 740 $entry = $this->client->getContainer()