aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php63
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php42
2 files changed, 92 insertions, 13 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index ae4af4cd..c76be13d 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -519,9 +519,6 @@ class EntryRestControllerTest extends WallabagApiTestCase
519 $this->markTestSkipped('No content found in db.'); 519 $this->markTestSkipped('No content found in db.');
520 } 520 }
521 521
522 // hydrate the tags relations
523 $nbTags = count($entry->getTags());
524
525 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 522 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
526 'title' => 'New awesome title', 523 'title' => 'New awesome title',
527 'tags' => 'new tag ' . uniqid(), 524 'tags' => 'new tag ' . uniqid(),
@@ -532,6 +529,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
532 'authors' => 'bob,sponge', 529 'authors' => 'bob,sponge',
533 'content' => 'awesome', 530 'content' => 'awesome',
534 'public' => 0, 531 'public' => 0,
532 'published_at' => 1488833381,
535 ]); 533 ]);
536 534
537 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 535 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
@@ -541,7 +539,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
541 $this->assertSame($entry->getId(), $content['id']); 539 $this->assertSame($entry->getId(), $content['id']);
542 $this->assertSame($entry->getUrl(), $content['url']); 540 $this->assertSame($entry->getUrl(), $content['url']);
543 $this->assertSame('New awesome title', $content['title']); 541 $this->assertSame('New awesome title', $content['title']);
544 $this->assertGreaterThan($nbTags, count($content['tags'])); 542 $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag');
545 $this->assertSame(1, $content['user_id']); 543 $this->assertSame(1, $content['user_id']);
546 $this->assertSame('de_AT', $content['language']); 544 $this->assertSame('de_AT', $content['language']);
547 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); 545 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']);
@@ -549,6 +547,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
549 $this->assertContains('bob', $content['published_by']); 547 $this->assertContains('bob', $content['published_by']);
550 $this->assertSame('awesome', $content['content']); 548 $this->assertSame('awesome', $content['content']);
551 $this->assertFalse($content['is_public'], 'Entry is no more shared'); 549 $this->assertFalse($content['is_public'], 'Entry is no more shared');
550 $this->assertContains('2017-03-06', $content['published_at']);
552 } 551 }
553 552
554 public function testPatchEntryWithoutQuotes() 553 public function testPatchEntryWithoutQuotes()
@@ -562,8 +561,8 @@ class EntryRestControllerTest extends WallabagApiTestCase
562 $this->markTestSkipped('No content found in db.'); 561 $this->markTestSkipped('No content found in db.');
563 } 562 }
564 563
565 // hydrate the tags relations 564 $previousContent = $entry->getContent();
566 $nbTags = count($entry->getTags()); 565 $previousLanguage = $entry->getLanguage();
567 566
568 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 567 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
569 'title' => 'New awesome title', 568 'title' => 'New awesome title',
@@ -579,9 +578,10 @@ class EntryRestControllerTest extends WallabagApiTestCase
579 578
580 $this->assertSame($entry->getId(), $content['id']); 579 $this->assertSame($entry->getId(), $content['id']);
581 $this->assertSame($entry->getUrl(), $content['url']); 580 $this->assertSame($entry->getUrl(), $content['url']);
582 $this->assertSame('New awesome title', $content['title']); 581 $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag');
583 $this->assertGreaterThan($nbTags, count($content['tags']));
584 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); 582 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
583 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
584 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
585 } 585 }
586 586
587 public function testGetTagsEntry() 587 public function testGetTagsEntry()
@@ -727,6 +727,8 @@ class EntryRestControllerTest extends WallabagApiTestCase
727 $this->markTestSkipped('No content found in db.'); 727 $this->markTestSkipped('No content found in db.');
728 } 728 }
729 729
730 $previousTitle = $entry->getTitle();
731
730 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 732 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
731 'title' => $entry->getTitle() . '++', 733 'title' => $entry->getTitle() . '++',
732 ]); 734 ]);
@@ -736,6 +738,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
736 $content = json_decode($this->client->getResponse()->getContent(), true); 738 $content = json_decode($this->client->getResponse()->getContent(), true);
737 739
738 $this->assertSame(1, $content['is_archived']); 740 $this->assertSame(1, $content['is_archived']);
741 $this->assertSame($previousTitle . '++', $content['title']);
739 } 742 }
740 743
741 public function testSaveIsStarredAfterPatch() 744 public function testSaveIsStarredAfterPatch()
@@ -907,6 +910,17 @@ class EntryRestControllerTest extends WallabagApiTestCase
907 $this->assertCount(4, $tags); 910 $this->assertCount(4, $tags);
908 } 911 }
909 912
913 public function testPostEntriesTagsListActionNoList()
914 {
915 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode([]));
916
917 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
918
919 $content = json_decode($this->client->getResponse()->getContent(), true);
920
921 $this->assertEmpty($content);
922 }
923
910 public function testDeleteEntriesTagsListAction() 924 public function testDeleteEntriesTagsListAction()
911 { 925 {
912 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 926 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
@@ -933,6 +947,17 @@ class EntryRestControllerTest extends WallabagApiTestCase
933 $this->assertCount(0, $entry->getTags()); 947 $this->assertCount(0, $entry->getTags());
934 } 948 }
935 949
950 public function testDeleteEntriesTagsListActionNoList()
951 {
952 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode([]));
953
954 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
955
956 $content = json_decode($this->client->getResponse()->getContent(), true);
957
958 $this->assertEmpty($content);
959 }
960
936 public function testPostEntriesListAction() 961 public function testPostEntriesListAction()
937 { 962 {
938 $list = [ 963 $list = [
@@ -953,6 +978,17 @@ class EntryRestControllerTest extends WallabagApiTestCase
953 $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']); 978 $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']);
954 } 979 }
955 980
981 public function testPostEntriesListActionWithNoUrls()
982 {
983 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode([]));
984
985 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
986
987 $content = json_decode($this->client->getResponse()->getContent(), true);
988
989 $this->assertEmpty($content);
990 }
991
956 public function testDeleteEntriesListAction() 992 public function testDeleteEntriesListAction()
957 { 993 {
958 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); 994 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
@@ -978,6 +1014,17 @@ class EntryRestControllerTest extends WallabagApiTestCase
978 $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']); 1014 $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']);
979 } 1015 }
980 1016
1017 public function testDeleteEntriesListActionWithNoUrls()
1018 {
1019 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode([]));
1020
1021 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1022
1023 $content = json_decode($this->client->getResponse()->getContent(), true);
1024
1025 $this->assertEmpty($content);
1026 }
1027
981 public function testLimitBulkAction() 1028 public function testLimitBulkAction()
982 { 1029 {
983 $list = [ 1030 $list = [
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index c63671c4..f94c2137 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -221,12 +221,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
221 ->method('tag'); 221 ->method('tag');
222 222
223 $validator = $this->getValidator(); 223 $validator = $this->getValidator();
224 $validator->expects($this->exactly(2)) 224 $validator->expects($this->once())
225 ->method('validate') 225 ->method('validate')
226 ->will($this->onConsecutiveCalls( 226 ->willReturn(new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')]));
227 new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')]),
228 new ConstraintViolationList()
229 ));
230 227
231 $graby = $this->getMockBuilder('Graby\Graby') 228 $graby = $this->getMockBuilder('Graby\Graby')
232 ->setMethods(['fetchContent']) 229 ->setMethods(['fetchContent'])
@@ -498,6 +495,41 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
498 $this->assertSame('1.1.1.1', $entry->getDomainName()); 495 $this->assertSame('1.1.1.1', $entry->getDomainName());
499 } 496 }
500 497
498 public function testWithImageAsContent()
499 {
500 $tagger = $this->getTaggerMock();
501 $tagger->expects($this->once())
502 ->method('tag');
503
504 $graby = $this->getMockBuilder('Graby\Graby')
505 ->setMethods(['fetchContent'])
506 ->disableOriginalConstructor()
507 ->getMock();
508
509 $graby->expects($this->any())
510 ->method('fetchContent')
511 ->willReturn([
512 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>',
513 'title' => 'this is my title',
514 'url' => 'http://1.1.1.1/image.jpg',
515 'content_type' => 'image/jpeg',
516 'status' => '200',
517 'open_graph' => [],
518 ]);
519
520 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
521 $entry = new Entry(new User());
522 $proxy->updateEntry($entry, 'http://0.0.0.0');
523
524 $this->assertSame('http://1.1.1.1/image.jpg', $entry->getUrl());
525 $this->assertSame('this is my title', $entry->getTitle());
526 $this->assertContains('http://1.1.1.1/image.jpg', $entry->getContent());
527 $this->assertSame('http://1.1.1.1/image.jpg', $entry->getPreviewPicture());
528 $this->assertSame('image/jpeg', $entry->getMimetype());
529 $this->assertSame('200', $entry->getHttpStatus());
530 $this->assertSame('1.1.1.1', $entry->getDomainName());
531 }
532
501 private function getTaggerMock() 533 private function getTaggerMock()
502 { 534 {
503 return $this->getMockBuilder(RuleBasedTagger::class) 535 return $this->getMockBuilder(RuleBasedTagger::class)