diff options
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 31 |
1 files changed, 23 insertions, 8 deletions
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 | } |