diff options
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import')
7 files changed, 100 insertions, 38 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index 6b3adda4..cec19534 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php | |||
@@ -17,6 +17,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase | |||
17 | protected $em; | 17 | protected $em; |
18 | protected $logHandler; | 18 | protected $logHandler; |
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | protected $tagsAssigner; | ||
20 | 21 | ||
21 | private function getChromeImport($unsetUser = false, $dispatched = 0) | 22 | private function getChromeImport($unsetUser = false, $dispatched = 0) |
22 | { | 23 | { |
@@ -30,6 +31,10 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase | |||
30 | ->disableOriginalConstructor() | 31 | ->disableOriginalConstructor() |
31 | ->getMock(); | 32 | ->getMock(); |
32 | 33 | ||
34 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
35 | ->disableOriginalConstructor() | ||
36 | ->getMock(); | ||
37 | |||
33 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | 38 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') |
34 | ->disableOriginalConstructor() | 39 | ->disableOriginalConstructor() |
35 | ->getMock(); | 40 | ->getMock(); |
@@ -38,7 +43,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase | |||
38 | ->expects($this->exactly($dispatched)) | 43 | ->expects($this->exactly($dispatched)) |
39 | ->method('dispatch'); | 44 | ->method('dispatch'); |
40 | 45 | ||
41 | $wallabag = new ChromeImport($this->em, $this->contentProxy, $dispatcher); | 46 | $wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); |
42 | 47 | ||
43 | $this->logHandler = new TestHandler(); | 48 | $this->logHandler = new TestHandler(); |
44 | $logger = new Logger('test', [$this->logHandler]); | 49 | $logger = new Logger('test', [$this->logHandler]); |
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index b516fbc5..c186c820 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | |||
@@ -17,6 +17,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
17 | protected $em; | 17 | protected $em; |
18 | protected $logHandler; | 18 | protected $logHandler; |
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | protected $tagsAssigner; | ||
20 | 21 | ||
21 | private function getFirefoxImport($unsetUser = false, $dispatched = 0) | 22 | private function getFirefoxImport($unsetUser = false, $dispatched = 0) |
22 | { | 23 | { |
@@ -30,6 +31,10 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
30 | ->disableOriginalConstructor() | 31 | ->disableOriginalConstructor() |
31 | ->getMock(); | 32 | ->getMock(); |
32 | 33 | ||
34 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
35 | ->disableOriginalConstructor() | ||
36 | ->getMock(); | ||
37 | |||
33 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | 38 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') |
34 | ->disableOriginalConstructor() | 39 | ->disableOriginalConstructor() |
35 | ->getMock(); | 40 | ->getMock(); |
@@ -38,7 +43,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
38 | ->expects($this->exactly($dispatched)) | 43 | ->expects($this->exactly($dispatched)) |
39 | ->method('dispatch'); | 44 | ->method('dispatch'); |
40 | 45 | ||
41 | $wallabag = new FirefoxImport($this->em, $this->contentProxy, $dispatcher); | 46 | $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); |
42 | 47 | ||
43 | $this->logHandler = new TestHandler(); | 48 | $this->logHandler = new TestHandler(); |
44 | $logger = new Logger('test', [$this->logHandler]); | 49 | $logger = new Logger('test', [$this->logHandler]); |
diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php index e262a808..9158c8a2 100644 --- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php | |||
@@ -17,6 +17,8 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
17 | protected $em; | 17 | protected $em; |
18 | protected $logHandler; | 18 | protected $logHandler; |
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | protected $tagsAssigner; | ||
21 | protected $uow; | ||
20 | 22 | ||
21 | private function getInstapaperImport($unsetUser = false, $dispatched = 0) | 23 | private function getInstapaperImport($unsetUser = false, $dispatched = 0) |
22 | { | 24 | { |
@@ -26,10 +28,28 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
26 | ->disableOriginalConstructor() | 28 | ->disableOriginalConstructor() |
27 | ->getMock(); | 29 | ->getMock(); |
28 | 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 | |||
29 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | 45 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') |
30 | ->disableOriginalConstructor() | 46 | ->disableOriginalConstructor() |
31 | ->getMock(); | 47 | ->getMock(); |
32 | 48 | ||
49 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
50 | ->disableOriginalConstructor() | ||
51 | ->getMock(); | ||
52 | |||
33 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | 53 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') |
34 | ->disableOriginalConstructor() | 54 | ->disableOriginalConstructor() |
35 | ->getMock(); | 55 | ->getMock(); |
@@ -38,7 +58,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
38 | ->expects($this->exactly($dispatched)) | 58 | ->expects($this->exactly($dispatched)) |
39 | ->method('dispatch'); | 59 | ->method('dispatch'); |
40 | 60 | ||
41 | $import = new InstapaperImport($this->em, $this->contentProxy, $dispatcher); | 61 | $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); |
42 | 62 | ||
43 | $this->logHandler = new TestHandler(); | 63 | $this->logHandler = new TestHandler(); |
44 | $logger = new Logger('test', [$this->logHandler]); | 64 | $logger = new Logger('test', [$this->logHandler]); |
@@ -62,14 +82,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
62 | 82 | ||
63 | public function testImport() | 83 | public function testImport() |
64 | { | 84 | { |
65 | $instapaperImport = $this->getInstapaperImport(false, 3); | 85 | $instapaperImport = $this->getInstapaperImport(false, 4); |
66 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); | 86 | $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); |
67 | 87 | ||
68 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 88 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
69 | ->disableOriginalConstructor() | 89 | ->disableOriginalConstructor() |
70 | ->getMock(); | 90 | ->getMock(); |
71 | 91 | ||
72 | $entryRepo->expects($this->exactly(3)) | 92 | $entryRepo->expects($this->exactly(4)) |
73 | ->method('findByUrlAndUserId') | 93 | ->method('findByUrlAndUserId') |
74 | ->willReturn(false); | 94 | ->willReturn(false); |
75 | 95 | ||
@@ -83,14 +103,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
83 | ->getMock(); | 103 | ->getMock(); |
84 | 104 | ||
85 | $this->contentProxy | 105 | $this->contentProxy |
86 | ->expects($this->exactly(3)) | 106 | ->expects($this->exactly(4)) |
87 | ->method('updateEntry') | 107 | ->method('updateEntry') |
88 | ->willReturn($entry); | 108 | ->willReturn($entry); |
89 | 109 | ||
90 | $res = $instapaperImport->import(); | 110 | $res = $instapaperImport->import(); |
91 | 111 | ||
92 | $this->assertTrue($res); | 112 | $this->assertTrue($res); |
93 | $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary()); | 113 | $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary()); |
94 | } | 114 | } |
95 | 115 | ||
96 | public function testImportAndMarkAllAsRead() | 116 | public function testImportAndMarkAllAsRead() |
@@ -102,9 +122,9 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
102 | ->disableOriginalConstructor() | 122 | ->disableOriginalConstructor() |
103 | ->getMock(); | 123 | ->getMock(); |
104 | 124 | ||
105 | $entryRepo->expects($this->exactly(3)) | 125 | $entryRepo->expects($this->exactly(4)) |
106 | ->method('findByUrlAndUserId') | 126 | ->method('findByUrlAndUserId') |
107 | ->will($this->onConsecutiveCalls(false, true, true)); | 127 | ->will($this->onConsecutiveCalls(false, true, true, true)); |
108 | 128 | ||
109 | $this->em | 129 | $this->em |
110 | ->expects($this->any()) | 130 | ->expects($this->any()) |
@@ -128,7 +148,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
128 | 148 | ||
129 | $this->assertTrue($res); | 149 | $this->assertTrue($res); |
130 | 150 | ||
131 | $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); | 151 | $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); |
132 | } | 152 | } |
133 | 153 | ||
134 | public function testImportWithRabbit() | 154 | public function testImportWithRabbit() |
@@ -160,7 +180,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
160 | ->getMock(); | 180 | ->getMock(); |
161 | 181 | ||
162 | $producer | 182 | $producer |
163 | ->expects($this->exactly(3)) | 183 | ->expects($this->exactly(4)) |
164 | ->method('publish'); | 184 | ->method('publish'); |
165 | 185 | ||
166 | $instapaperImport->setProducer($producer); | 186 | $instapaperImport->setProducer($producer); |
@@ -168,7 +188,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
168 | $res = $instapaperImport->setMarkAsRead(true)->import(); | 188 | $res = $instapaperImport->setMarkAsRead(true)->import(); |
169 | 189 | ||
170 | $this->assertTrue($res); | 190 | $this->assertTrue($res); |
171 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); | 191 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); |
172 | } | 192 | } |
173 | 193 | ||
174 | public function testImportWithRedis() | 194 | public function testImportWithRedis() |
@@ -206,7 +226,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase | |||
206 | $res = $instapaperImport->setMarkAsRead(true)->import(); | 226 | $res = $instapaperImport->setMarkAsRead(true)->import(); |
207 | 227 | ||
208 | $this->assertTrue($res); | 228 | $this->assertTrue($res); |
209 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); | 229 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary()); |
210 | 230 | ||
211 | $this->assertNotEmpty($redisMock->lpop('instapaper')); | 231 | $this->assertNotEmpty($redisMock->lpop('instapaper')); |
212 | } | 232 | } |
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 141ece36..b81ebe15 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php | |||
@@ -23,6 +23,8 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
23 | protected $em; | 23 | protected $em; |
24 | protected $contentProxy; | 24 | protected $contentProxy; |
25 | protected $logHandler; | 25 | protected $logHandler; |
26 | protected $tagsAssigner; | ||
27 | protected $uow; | ||
26 | 28 | ||
27 | private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) | 29 | private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) |
28 | { | 30 | { |
@@ -37,6 +39,10 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
37 | ->disableOriginalConstructor() | 39 | ->disableOriginalConstructor() |
38 | ->getMock(); | 40 | ->getMock(); |
39 | 41 | ||
42 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
43 | ->disableOriginalConstructor() | ||
44 | ->getMock(); | ||
45 | |||
40 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | 46 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
41 | ->disableOriginalConstructor() | 47 | ->disableOriginalConstructor() |
42 | ->getMock(); | 48 | ->getMock(); |
@@ -63,7 +69,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
63 | ->expects($this->exactly($dispatched)) | 69 | ->expects($this->exactly($dispatched)) |
64 | ->method('dispatch'); | 70 | ->method('dispatch'); |
65 | 71 | ||
66 | $pocket = new PocketImport($this->em, $this->contentProxy, $dispatcher); | 72 | $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); |
67 | $pocket->setUser($this->user); | 73 | $pocket->setUser($this->user); |
68 | 74 | ||
69 | $this->logHandler = new TestHandler(); | 75 | $this->logHandler = new TestHandler(); |
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index d1bbe648..8f466d38 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php | |||
@@ -17,6 +17,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
17 | protected $em; | 17 | protected $em; |
18 | protected $logHandler; | 18 | protected $logHandler; |
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | protected $tagsAssigner; | ||
20 | 21 | ||
21 | private function getReadabilityImport($unsetUser = false, $dispatched = 0) | 22 | private function getReadabilityImport($unsetUser = false, $dispatched = 0) |
22 | { | 23 | { |
@@ -30,6 +31,10 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
30 | ->disableOriginalConstructor() | 31 | ->disableOriginalConstructor() |
31 | ->getMock(); | 32 | ->getMock(); |
32 | 33 | ||
34 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
35 | ->disableOriginalConstructor() | ||
36 | ->getMock(); | ||
37 | |||
33 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | 38 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') |
34 | ->disableOriginalConstructor() | 39 | ->disableOriginalConstructor() |
35 | ->getMock(); | 40 | ->getMock(); |
@@ -38,7 +43,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
38 | ->expects($this->exactly($dispatched)) | 43 | ->expects($this->exactly($dispatched)) |
39 | ->method('dispatch'); | 44 | ->method('dispatch'); |
40 | 45 | ||
41 | $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $dispatcher); | 46 | $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); |
42 | 47 | ||
43 | $this->logHandler = new TestHandler(); | 48 | $this->logHandler = new TestHandler(); |
44 | $logger = new Logger('test', [$this->logHandler]); | 49 | $logger = new Logger('test', [$this->logHandler]); |
@@ -62,14 +67,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
62 | 67 | ||
63 | public function testImport() | 68 | public function testImport() |
64 | { | 69 | { |
65 | $readabilityImport = $this->getReadabilityImport(false, 24); | 70 | $readabilityImport = $this->getReadabilityImport(false, 3); |
66 | $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); | 71 | $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); |
67 | 72 | ||
68 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 73 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
69 | ->disableOriginalConstructor() | 74 | ->disableOriginalConstructor() |
70 | ->getMock(); | 75 | ->getMock(); |
71 | 76 | ||
72 | $entryRepo->expects($this->exactly(24)) | 77 | $entryRepo->expects($this->exactly(3)) |
73 | ->method('findByUrlAndUserId') | 78 | ->method('findByUrlAndUserId') |
74 | ->willReturn(false); | 79 | ->willReturn(false); |
75 | 80 | ||
@@ -83,14 +88,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
83 | ->getMock(); | 88 | ->getMock(); |
84 | 89 | ||
85 | $this->contentProxy | 90 | $this->contentProxy |
86 | ->expects($this->exactly(24)) | 91 | ->expects($this->exactly(3)) |
87 | ->method('updateEntry') | 92 | ->method('updateEntry') |
88 | ->willReturn($entry); | 93 | ->willReturn($entry); |
89 | 94 | ||
90 | $res = $readabilityImport->import(); | 95 | $res = $readabilityImport->import(); |
91 | 96 | ||
92 | $this->assertTrue($res); | 97 | $this->assertTrue($res); |
93 | $this->assertEquals(['skipped' => 0, 'imported' => 24, 'queued' => 0], $readabilityImport->getSummary()); | 98 | $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); |
94 | } | 99 | } |
95 | 100 | ||
96 | public function testImportAndMarkAllAsRead() | 101 | public function testImportAndMarkAllAsRead() |
@@ -160,7 +165,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
160 | ->getMock(); | 165 | ->getMock(); |
161 | 166 | ||
162 | $producer | 167 | $producer |
163 | ->expects($this->exactly(24)) | 168 | ->expects($this->exactly(3)) |
164 | ->method('publish'); | 169 | ->method('publish'); |
165 | 170 | ||
166 | $readabilityImport->setProducer($producer); | 171 | $readabilityImport->setProducer($producer); |
@@ -168,7 +173,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
168 | $res = $readabilityImport->setMarkAsRead(true)->import(); | 173 | $res = $readabilityImport->setMarkAsRead(true)->import(); |
169 | 174 | ||
170 | $this->assertTrue($res); | 175 | $this->assertTrue($res); |
171 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); | 176 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); |
172 | } | 177 | } |
173 | 178 | ||
174 | public function testImportWithRedis() | 179 | public function testImportWithRedis() |
@@ -206,7 +211,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase | |||
206 | $res = $readabilityImport->setMarkAsRead(true)->import(); | 211 | $res = $readabilityImport->setMarkAsRead(true)->import(); |
207 | 212 | ||
208 | $this->assertTrue($res); | 213 | $this->assertTrue($res); |
209 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); | 214 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); |
210 | 215 | ||
211 | $this->assertNotEmpty($redisMock->lpop('readability')); | 216 | $this->assertNotEmpty($redisMock->lpop('readability')); |
212 | } | 217 | } |
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 4dbced60..834b7ef5 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | |||
@@ -17,6 +17,10 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
17 | protected $em; | 17 | protected $em; |
18 | protected $logHandler; | 18 | protected $logHandler; |
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | protected $tagsAssigner; | ||
21 | protected $uow; | ||
22 | protected $fetchingErrorMessageTitle = 'No title found'; | ||
23 | protected $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/master/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>.'; | ||
20 | 24 | ||
21 | private function getWallabagV1Import($unsetUser = false, $dispatched = 0) | 25 | private function getWallabagV1Import($unsetUser = false, $dispatched = 0) |
22 | { | 26 | { |
@@ -44,6 +48,10 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
44 | ->disableOriginalConstructor() | 48 | ->disableOriginalConstructor() |
45 | ->getMock(); | 49 | ->getMock(); |
46 | 50 | ||
51 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
52 | ->disableOriginalConstructor() | ||
53 | ->getMock(); | ||
54 | |||
47 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | 55 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') |
48 | ->disableOriginalConstructor() | 56 | ->disableOriginalConstructor() |
49 | ->getMock(); | 57 | ->getMock(); |
@@ -52,7 +60,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
52 | ->expects($this->exactly($dispatched)) | 60 | ->expects($this->exactly($dispatched)) |
53 | ->method('dispatch'); | 61 | ->method('dispatch'); |
54 | 62 | ||
55 | $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $dispatcher); | 63 | $wallabag = new WallabagV1Import( |
64 | $this->em, | ||
65 | $this->contentProxy, | ||
66 | $this->tagsAssigner, | ||
67 | $dispatcher, | ||
68 | $this->fetchingErrorMessageTitle, | ||
69 | $this->fetchingErrorMessage | ||
70 | ); | ||
56 | 71 | ||
57 | $this->logHandler = new TestHandler(); | 72 | $this->logHandler = new TestHandler(); |
58 | $logger = new Logger('test', [$this->logHandler]); | 73 | $logger = new Logger('test', [$this->logHandler]); |
@@ -76,14 +91,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
76 | 91 | ||
77 | public function testImport() | 92 | public function testImport() |
78 | { | 93 | { |
79 | $wallabagV1Import = $this->getWallabagV1Import(false, 3); | 94 | $wallabagV1Import = $this->getWallabagV1Import(false, 1); |
80 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); | 95 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); |
81 | 96 | ||
82 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 97 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
83 | ->disableOriginalConstructor() | 98 | ->disableOriginalConstructor() |
84 | ->getMock(); | 99 | ->getMock(); |
85 | 100 | ||
86 | $entryRepo->expects($this->exactly(4)) | 101 | $entryRepo->expects($this->exactly(2)) |
87 | ->method('findByUrlAndUserId') | 102 | ->method('findByUrlAndUserId') |
88 | ->will($this->onConsecutiveCalls(false, true, false, false)); | 103 | ->will($this->onConsecutiveCalls(false, true, false, false)); |
89 | 104 | ||
@@ -97,14 +112,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
97 | ->getMock(); | 112 | ->getMock(); |
98 | 113 | ||
99 | $this->contentProxy | 114 | $this->contentProxy |
100 | ->expects($this->exactly(3)) | 115 | ->expects($this->exactly(1)) |
101 | ->method('updateEntry') | 116 | ->method('updateEntry') |
102 | ->willReturn($entry); | 117 | ->willReturn($entry); |
103 | 118 | ||
104 | $res = $wallabagV1Import->import(); | 119 | $res = $wallabagV1Import->import(); |
105 | 120 | ||
106 | $this->assertTrue($res); | 121 | $this->assertTrue($res); |
107 | $this->assertEquals(['skipped' => 1, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); | 122 | $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary()); |
108 | } | 123 | } |
109 | 124 | ||
110 | public function testImportAndMarkAllAsRead() | 125 | public function testImportAndMarkAllAsRead() |
@@ -174,7 +189,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
174 | ->getMock(); | 189 | ->getMock(); |
175 | 190 | ||
176 | $producer | 191 | $producer |
177 | ->expects($this->exactly(4)) | 192 | ->expects($this->exactly(2)) |
178 | ->method('publish'); | 193 | ->method('publish'); |
179 | 194 | ||
180 | $wallabagV1Import->setProducer($producer); | 195 | $wallabagV1Import->setProducer($producer); |
@@ -182,7 +197,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
182 | $res = $wallabagV1Import->setMarkAsRead(true)->import(); | 197 | $res = $wallabagV1Import->setMarkAsRead(true)->import(); |
183 | 198 | ||
184 | $this->assertTrue($res); | 199 | $this->assertTrue($res); |
185 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); | 200 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); |
186 | } | 201 | } |
187 | 202 | ||
188 | public function testImportWithRedis() | 203 | public function testImportWithRedis() |
@@ -220,7 +235,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
220 | $res = $wallabagV1Import->setMarkAsRead(true)->import(); | 235 | $res = $wallabagV1Import->setMarkAsRead(true)->import(); |
221 | 236 | ||
222 | $this->assertTrue($res); | 237 | $this->assertTrue($res); |
223 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); | 238 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); |
224 | 239 | ||
225 | $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); | 240 | $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); |
226 | } | 241 | } |
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 0e50b8b2..5cc04aa5 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | |||
@@ -17,6 +17,8 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
17 | protected $em; | 17 | protected $em; |
18 | protected $logHandler; | 18 | protected $logHandler; |
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | protected $tagsAssigner; | ||
21 | protected $uow; | ||
20 | 22 | ||
21 | private function getWallabagV2Import($unsetUser = false, $dispatched = 0) | 23 | private function getWallabagV2Import($unsetUser = false, $dispatched = 0) |
22 | { | 24 | { |
@@ -44,6 +46,10 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
44 | ->disableOriginalConstructor() | 46 | ->disableOriginalConstructor() |
45 | ->getMock(); | 47 | ->getMock(); |
46 | 48 | ||
49 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
50 | ->disableOriginalConstructor() | ||
51 | ->getMock(); | ||
52 | |||
47 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | 53 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') |
48 | ->disableOriginalConstructor() | 54 | ->disableOriginalConstructor() |
49 | ->getMock(); | 55 | ->getMock(); |
@@ -52,7 +58,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
52 | ->expects($this->exactly($dispatched)) | 58 | ->expects($this->exactly($dispatched)) |
53 | ->method('dispatch'); | 59 | ->method('dispatch'); |
54 | 60 | ||
55 | $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $dispatcher); | 61 | $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); |
56 | 62 | ||
57 | $this->logHandler = new TestHandler(); | 63 | $this->logHandler = new TestHandler(); |
58 | $logger = new Logger('test', [$this->logHandler]); | 64 | $logger = new Logger('test', [$this->logHandler]); |
@@ -83,7 +89,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
83 | ->disableOriginalConstructor() | 89 | ->disableOriginalConstructor() |
84 | ->getMock(); | 90 | ->getMock(); |
85 | 91 | ||
86 | $entryRepo->expects($this->exactly(24)) | 92 | $entryRepo->expects($this->exactly(6)) |
87 | ->method('findByUrlAndUserId') | 93 | ->method('findByUrlAndUserId') |
88 | ->will($this->onConsecutiveCalls(false, true, false)); | 94 | ->will($this->onConsecutiveCalls(false, true, false)); |
89 | 95 | ||
@@ -100,7 +106,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
100 | $res = $wallabagV2Import->import(); | 106 | $res = $wallabagV2Import->import(); |
101 | 107 | ||
102 | $this->assertTrue($res); | 108 | $this->assertTrue($res); |
103 | $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); | 109 | $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
104 | } | 110 | } |
105 | 111 | ||
106 | public function testImportAndMarkAllAsRead() | 112 | public function testImportAndMarkAllAsRead() |
@@ -166,7 +172,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
166 | ->getMock(); | 172 | ->getMock(); |
167 | 173 | ||
168 | $producer | 174 | $producer |
169 | ->expects($this->exactly(24)) | 175 | ->expects($this->exactly(6)) |
170 | ->method('publish'); | 176 | ->method('publish'); |
171 | 177 | ||
172 | $wallabagV2Import->setProducer($producer); | 178 | $wallabagV2Import->setProducer($producer); |
@@ -174,7 +180,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
174 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | 180 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); |
175 | 181 | ||
176 | $this->assertTrue($res); | 182 | $this->assertTrue($res); |
177 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); | 183 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); |
178 | } | 184 | } |
179 | 185 | ||
180 | public function testImportWithRedis() | 186 | public function testImportWithRedis() |
@@ -208,7 +214,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
208 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | 214 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); |
209 | 215 | ||
210 | $this->assertTrue($res); | 216 | $this->assertTrue($res); |
211 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); | 217 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); |
212 | 218 | ||
213 | $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); | 219 | $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); |
214 | } | 220 | } |
@@ -261,7 +267,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
261 | ->disableOriginalConstructor() | 267 | ->disableOriginalConstructor() |
262 | ->getMock(); | 268 | ->getMock(); |
263 | 269 | ||
264 | $entryRepo->expects($this->exactly(24)) | 270 | $entryRepo->expects($this->exactly(6)) |
265 | ->method('findByUrlAndUserId') | 271 | ->method('findByUrlAndUserId') |
266 | ->will($this->onConsecutiveCalls(false, true, false)); | 272 | ->will($this->onConsecutiveCalls(false, true, false)); |
267 | 273 | ||
@@ -278,6 +284,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
278 | $res = $wallabagV2Import->import(); | 284 | $res = $wallabagV2Import->import(); |
279 | 285 | ||
280 | $this->assertTrue($res); | 286 | $this->assertTrue($res); |
281 | $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); | 287 | $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
282 | } | 288 | } |
283 | } | 289 | } |