diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-05-31 10:38:00 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-05-31 10:38:00 +0200 |
commit | 7a8ed3cee1003aae56400e18509980e2695ea622 (patch) | |
tree | 6719b99d1a5a370ac6c9d41c965a04f689383d39 /tests/Wallabag/ImportBundle | |
parent | 7aa5607f297d5ef188d06cc3f808f9ff5bda83b2 (diff) | |
download | wallabag-7a8ed3cee1003aae56400e18509980e2695ea622.tar.gz wallabag-7a8ed3cee1003aae56400e18509980e2695ea622.tar.zst wallabag-7a8ed3cee1003aae56400e18509980e2695ea622.zip |
Add support for tag in Instapaper import
Diffstat (limited to 'tests/Wallabag/ImportBundle')
3 files changed, 43 insertions, 13 deletions
diff --git a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php index c2e5fdb7..84742e0a 100644 --- a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php | |||
@@ -107,6 +107,9 @@ class InstapaperControllerTest extends WallabagCoreTestCase | |||
107 | 107 | ||
108 | $crawler = $client->followRedirect(); | 108 | $crawler = $client->followRedirect(); |
109 | 109 | ||
110 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
111 | $this->assertContains('flashes.import.notice.summary', $body[0]); | ||
112 | |||
110 | $content = $client->getContainer() | 113 | $content = $client->getContainer() |
111 | ->get('doctrine.orm.entity_manager') | 114 | ->get('doctrine.orm.entity_manager') |
112 | ->getRepository('WallabagCoreBundle:Entry') | 115 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -115,14 +118,25 @@ class InstapaperControllerTest extends WallabagCoreTestCase | |||
115 | $this->getLoggedInUserId() | 118 | $this->getLoggedInUserId() |
116 | ); | 119 | ); |
117 | 120 | ||
118 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
119 | $this->assertContains('flashes.import.notice.summary', $body[0]); | ||
120 | |||
121 | $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.liberation.fr is ok'); | 121 | $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.liberation.fr is ok'); |
122 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.liberation.fr is ok'); | 122 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.liberation.fr is ok'); |
123 | $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.liberation.fr is ok'); | 123 | $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.liberation.fr is ok'); |
124 | $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag'); | ||
124 | $this->assertEquals(1, count($content->getTags())); | 125 | $this->assertEquals(1, count($content->getTags())); |
125 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | 126 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); |
127 | |||
128 | $content = $client->getContainer() | ||
129 | ->get('doctrine.orm.entity_manager') | ||
130 | ->getRepository('WallabagCoreBundle:Entry') | ||
131 | ->findByUrlAndUserId( | ||
132 | 'http://www.20minutes.fr/high-tech/2077615-20170531-dis-donc-donald-trump-quoi-exactement-covfefe', | ||
133 | $this->getLoggedInUserId() | ||
134 | ); | ||
135 | |||
136 | $this->assertContains('foot', $content->getTags()); | ||
137 | $this->assertContains('test_tag', $content->getTags()); | ||
138 | |||
139 | $this->assertEquals(2, count($content->getTags())); | ||
126 | } | 140 | } |
127 | 141 | ||
128 | public function testImportInstapaperWithFileAndMarkAllAsRead() | 142 | public function testImportInstapaperWithFileAndMarkAllAsRead() |
diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php index 6777a02e..9158c8a2 100644 --- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php | |||
@@ -18,6 +18,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
18 | protected $logHandler; | 18 | protected $logHandler; |
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | protected $tagsAssigner; | 20 | protected $tagsAssigner; |
21 | protected $uow; | ||
21 | 22 | ||
22 | private function getInstapaperImport($unsetUser = false, $dispatched = 0) | 23 | private function getInstapaperImport($unsetUser = false, $dispatched = 0) |
23 | { | 24 | { |
@@ -27,6 +28,20 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
27 | ->disableOriginalConstructor() | 28 | ->disableOriginalConstructor() |
28 | ->getMock(); | 29 | ->getMock(); |
29 | 30 | ||
31 | $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') | ||
32 | ->disableOriginalConstructor() | ||
33 | ->getMock(); | ||
34 | |||
35 | $this->em | ||
36 | ->expects($this->any()) | ||
37 | ->method('getUnitOfWork') | ||
38 | ->willReturn($this->uow); | ||
39 | |||
40 | $this->uow | ||
41 | ->expects($this->any()) | ||
42 | ->method('getScheduledEntityInsertions') | ||
43 | ->willReturn([]); | ||
44 | |||
30 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | 45 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') |
31 | ->disableOriginalConstructor() | 46 | ->disableOriginalConstructor() |
32 | ->getMock(); | 47 | ->getMock(); |
@@ -67,14 +82,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
67 | 82 | ||
68 | public function testImport() | 83 | public function testImport() |
69 | { | 84 | { |
70 | $instapaperImport = $this->getInstapaperImport(false, 3); | 85 | $instapaperImport = $this->getInstapaperImport(false, 4); |
71 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); | 86 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); |
72 | 87 | ||
73 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 88 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
74 | ->disableOriginalConstructor() | 89 | ->disableOriginalConstructor() |
75 | ->getMock(); | 90 | ->getMock(); |
76 | 91 | ||
77 | $entryRepo->expects($this->exactly(3)) | 92 | $entryRepo->expects($this->exactly(4)) |
78 | ->method('findByUrlAndUserId') | 93 | ->method('findByUrlAndUserId') |
79 | ->willReturn(false); | 94 | ->willReturn(false); |
80 | 95 | ||
@@ -88,14 +103,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
88 | ->getMock(); | 103 | ->getMock(); |
89 | 104 | ||
90 | $this->contentProxy | 105 | $this->contentProxy |
91 | ->expects($this->exactly(3)) | 106 | ->expects($this->exactly(4)) |
92 | ->method('updateEntry') | 107 | ->method('updateEntry') |
93 | ->willReturn($entry); | 108 | ->willReturn($entry); |
94 | 109 | ||
95 | $res = $instapaperImport->import(); | 110 | $res = $instapaperImport->import(); |
96 | 111 | ||
97 | $this->assertTrue($res); | 112 | $this->assertTrue($res); |
98 | $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary()); | 113 | $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); |
99 | } | 114 | } |
100 | 115 | ||
101 | public function testImportAndMarkAllAsRead() | 116 | public function testImportAndMarkAllAsRead() |
@@ -107,9 +122,9 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
107 | ->disableOriginalConstructor() | 122 | ->disableOriginalConstructor() |
108 | ->getMock(); | 123 | ->getMock(); |
109 | 124 | ||
110 | $entryRepo->expects($this->exactly(3)) | 125 | $entryRepo->expects($this->exactly(4)) |
111 | ->method('findByUrlAndUserId') | 126 | ->method('findByUrlAndUserId') |
112 | ->will($this->onConsecutiveCalls(false, true, true)); | 127 | ->will($this->onConsecutiveCalls(false, true, true, true)); |
113 | 128 | ||
114 | $this->em | 129 | $this->em |
115 | ->expects($this->any()) | 130 | ->expects($this->any()) |
@@ -133,7 +148,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
133 | 148 | ||
134 | $this->assertTrue($res); | 149 | $this->assertTrue($res); |
135 | 150 | ||
136 | $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); | 151 | $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); |
137 | } | 152 | } |
138 | 153 | ||
139 | public function testImportWithRabbit() | 154 | public function testImportWithRabbit() |
@@ -165,7 +180,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
165 | ->getMock(); | 180 | ->getMock(); |
166 | 181 | ||
167 | $producer | 182 | $producer |
168 | ->expects($this->exactly(3)) | 183 | ->expects($this->exactly(4)) |
169 | ->method('publish'); | 184 | ->method('publish'); |
170 | 185 | ||
171 | $instapaperImport->setProducer($producer); | 186 | $instapaperImport->setProducer($producer); |
@@ -173,7 +188,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
173 | $res = $instapaperImport->setMarkAsRead(true)->import(); | 188 | $res = $instapaperImport->setMarkAsRead(true)->import(); |
174 | 189 | ||
175 | $this->assertTrue($res); | 190 | $this->assertTrue($res); |
176 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); | 191 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); |
177 | } | 192 | } |
178 | 193 | ||
179 | public function testImportWithRedis() | 194 | public function testImportWithRedis() |
@@ -211,7 +226,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
211 | $res = $instapaperImport->setMarkAsRead(true)->import(); | 226 | $res = $instapaperImport->setMarkAsRead(true)->import(); |
212 | 227 | ||
213 | $this->assertTrue($res); | 228 | $this->assertTrue($res); |
214 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); | 229 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); |
215 | 230 | ||
216 | $this->assertNotEmpty($redisMock->lpop('instapaper')); | 231 | $this->assertNotEmpty($redisMock->lpop('instapaper')); |
217 | } | 232 | } |
diff --git a/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv b/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv index 28a4c8e6..1a648f8a 100644 --- a/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv +++ b/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv | |||
@@ -2,3 +2,4 @@ URL,Title,Selection,Folder | |||
2 | http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551,Baumettes : un tour en cellule,,Unread | 2 | http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551,Baumettes : un tour en cellule,,Unread |
3 | https://redditblog.com/2016/09/20/amp-and-reactredux/,AMP and React+Redux: Why Not?,,Archive | 3 | https://redditblog.com/2016/09/20/amp-and-reactredux/,AMP and React+Redux: Why Not?,,Archive |
4 | https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c,Why Foursquare / Swarm is still my favourite social network,,Starred | 4 | https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c,Why Foursquare / Swarm is still my favourite social network,,Starred |
5 | http://www.20minutes.fr/high-tech/2077615-20170531-dis-donc-donald-trump-quoi-exactement-covfefe,"Dis donc Donald Trump, c'est quoi exactement «covfefe»?",,test_tag | ||