diff options
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 5cc04aa5..fab50a45 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | |||
@@ -2,14 +2,14 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Import; | 3 | namespace Tests\Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use Wallabag\ImportBundle\Import\WallabagV2Import; | 5 | use M6Web\Component\RedisMock\RedisMockFactory; |
6 | use Wallabag\UserBundle\Entity\User; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | ||
8 | use Wallabag\ImportBundle\Redis\Producer; | ||
9 | use Monolog\Logger; | ||
10 | use Monolog\Handler\TestHandler; | 6 | use Monolog\Handler\TestHandler; |
7 | use Monolog\Logger; | ||
11 | use Simpleue\Queue\RedisQueue; | 8 | use Simpleue\Queue\RedisQueue; |
12 | use M6Web\Component\RedisMock\RedisMockFactory; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Wallabag\ImportBundle\Import\WallabagV2Import; | ||
11 | use Wallabag\ImportBundle\Redis\Producer; | ||
12 | use Wallabag\UserBundle\Entity\User; | ||
13 | 13 | ||
14 | class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | 14 | class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase |
15 | { | 15 | { |
@@ -20,70 +20,19 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
20 | protected $tagsAssigner; | 20 | protected $tagsAssigner; |
21 | protected $uow; | 21 | protected $uow; |
22 | 22 | ||
23 | private function getWallabagV2Import($unsetUser = false, $dispatched = 0) | ||
24 | { | ||
25 | $this->user = new User(); | ||
26 | |||
27 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
28 | ->disableOriginalConstructor() | ||
29 | ->getMock(); | ||
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 | |||
45 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
46 | ->disableOriginalConstructor() | ||
47 | ->getMock(); | ||
48 | |||
49 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
50 | ->disableOriginalConstructor() | ||
51 | ->getMock(); | ||
52 | |||
53 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
54 | ->disableOriginalConstructor() | ||
55 | ->getMock(); | ||
56 | |||
57 | $dispatcher | ||
58 | ->expects($this->exactly($dispatched)) | ||
59 | ->method('dispatch'); | ||
60 | |||
61 | $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); | ||
62 | |||
63 | $this->logHandler = new TestHandler(); | ||
64 | $logger = new Logger('test', [$this->logHandler]); | ||
65 | $wallabag->setLogger($logger); | ||
66 | |||
67 | if (false === $unsetUser) { | ||
68 | $wallabag->setUser($this->user); | ||
69 | } | ||
70 | |||
71 | return $wallabag; | ||
72 | } | ||
73 | |||
74 | public function testInit() | 23 | public function testInit() |
75 | { | 24 | { |
76 | $wallabagV2Import = $this->getWallabagV2Import(); | 25 | $wallabagV2Import = $this->getWallabagV2Import(); |
77 | 26 | ||
78 | $this->assertEquals('wallabag v2', $wallabagV2Import->getName()); | 27 | $this->assertSame('wallabag v2', $wallabagV2Import->getName()); |
79 | $this->assertNotEmpty($wallabagV2Import->getUrl()); | 28 | $this->assertNotEmpty($wallabagV2Import->getUrl()); |
80 | $this->assertEquals('import.wallabag_v2.description', $wallabagV2Import->getDescription()); | 29 | $this->assertSame('import.wallabag_v2.description', $wallabagV2Import->getDescription()); |
81 | } | 30 | } |
82 | 31 | ||
83 | public function testImport() | 32 | public function testImport() |
84 | { | 33 | { |
85 | $wallabagV2Import = $this->getWallabagV2Import(false, 2); | 34 | $wallabagV2Import = $this->getWallabagV2Import(false, 2); |
86 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | 35 | $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); |
87 | 36 | ||
88 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 37 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
89 | ->disableOriginalConstructor() | 38 | ->disableOriginalConstructor() |
@@ -106,13 +55,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
106 | $res = $wallabagV2Import->import(); | 55 | $res = $wallabagV2Import->import(); |
107 | 56 | ||
108 | $this->assertTrue($res); | 57 | $this->assertTrue($res); |
109 | $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); | 58 | $this->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
110 | } | 59 | } |
111 | 60 | ||
112 | public function testImportAndMarkAllAsRead() | 61 | public function testImportAndMarkAllAsRead() |
113 | { | 62 | { |
114 | $wallabagV2Import = $this->getWallabagV2Import(false, 2); | 63 | $wallabagV2Import = $this->getWallabagV2Import(false, 2); |
115 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json'); | 64 | $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2-read.json'); |
116 | 65 | ||
117 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 66 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
118 | ->disableOriginalConstructor() | 67 | ->disableOriginalConstructor() |
@@ -144,13 +93,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
144 | 93 | ||
145 | $this->assertTrue($res); | 94 | $this->assertTrue($res); |
146 | 95 | ||
147 | $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); | 96 | $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
148 | } | 97 | } |
149 | 98 | ||
150 | public function testImportWithRabbit() | 99 | public function testImportWithRabbit() |
151 | { | 100 | { |
152 | $wallabagV2Import = $this->getWallabagV2Import(); | 101 | $wallabagV2Import = $this->getWallabagV2Import(); |
153 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | 102 | $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); |
154 | 103 | ||
155 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 104 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
156 | ->disableOriginalConstructor() | 105 | ->disableOriginalConstructor() |
@@ -180,13 +129,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
180 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | 129 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); |
181 | 130 | ||
182 | $this->assertTrue($res); | 131 | $this->assertTrue($res); |
183 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); | 132 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); |
184 | } | 133 | } |
185 | 134 | ||
186 | public function testImportWithRedis() | 135 | public function testImportWithRedis() |
187 | { | 136 | { |
188 | $wallabagV2Import = $this->getWallabagV2Import(); | 137 | $wallabagV2Import = $this->getWallabagV2Import(); |
189 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | 138 | $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); |
190 | 139 | ||
191 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 140 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
192 | ->disableOriginalConstructor() | 141 | ->disableOriginalConstructor() |
@@ -214,7 +163,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
214 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | 163 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); |
215 | 164 | ||
216 | $this->assertTrue($res); | 165 | $this->assertTrue($res); |
217 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); | 166 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary()); |
218 | 167 | ||
219 | $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); | 168 | $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); |
220 | } | 169 | } |
@@ -222,7 +171,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
222 | public function testImportBadFile() | 171 | public function testImportBadFile() |
223 | { | 172 | { |
224 | $wallabagV1Import = $this->getWallabagV2Import(); | 173 | $wallabagV1Import = $this->getWallabagV2Import(); |
225 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.jsonx'); | 174 | $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.jsonx'); |
226 | 175 | ||
227 | $res = $wallabagV1Import->import(); | 176 | $res = $wallabagV1Import->import(); |
228 | 177 | ||
@@ -230,13 +179,13 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
230 | 179 | ||
231 | $records = $this->logHandler->getRecords(); | 180 | $records = $this->logHandler->getRecords(); |
232 | $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); | 181 | $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); |
233 | $this->assertEquals('ERROR', $records[0]['level_name']); | 182 | $this->assertSame('ERROR', $records[0]['level_name']); |
234 | } | 183 | } |
235 | 184 | ||
236 | public function testImportUserNotDefined() | 185 | public function testImportUserNotDefined() |
237 | { | 186 | { |
238 | $wallabagV1Import = $this->getWallabagV2Import(true); | 187 | $wallabagV1Import = $this->getWallabagV2Import(true); |
239 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | 188 | $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); |
240 | 189 | ||
241 | $res = $wallabagV1Import->import(); | 190 | $res = $wallabagV1Import->import(); |
242 | 191 | ||
@@ -244,24 +193,24 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
244 | 193 | ||
245 | $records = $this->logHandler->getRecords(); | 194 | $records = $this->logHandler->getRecords(); |
246 | $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); | 195 | $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); |
247 | $this->assertEquals('ERROR', $records[0]['level_name']); | 196 | $this->assertSame('ERROR', $records[0]['level_name']); |
248 | } | 197 | } |
249 | 198 | ||
250 | public function testImportEmptyFile() | 199 | public function testImportEmptyFile() |
251 | { | 200 | { |
252 | $wallabagV2Import = $this->getWallabagV2Import(); | 201 | $wallabagV2Import = $this->getWallabagV2Import(); |
253 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-empty.json'); | 202 | $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2-empty.json'); |
254 | 203 | ||
255 | $res = $wallabagV2Import->import(); | 204 | $res = $wallabagV2Import->import(); |
256 | 205 | ||
257 | $this->assertFalse($res); | 206 | $this->assertFalse($res); |
258 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); | 207 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); |
259 | } | 208 | } |
260 | 209 | ||
261 | public function testImportWithExceptionFromGraby() | 210 | public function testImportWithExceptionFromGraby() |
262 | { | 211 | { |
263 | $wallabagV2Import = $this->getWallabagV2Import(false, 2); | 212 | $wallabagV2Import = $this->getWallabagV2Import(false, 2); |
264 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | 213 | $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json'); |
265 | 214 | ||
266 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 215 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
267 | ->disableOriginalConstructor() | 216 | ->disableOriginalConstructor() |
@@ -284,6 +233,57 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
284 | $res = $wallabagV2Import->import(); | 233 | $res = $wallabagV2Import->import(); |
285 | 234 | ||
286 | $this->assertTrue($res); | 235 | $this->assertTrue($res); |
287 | $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); | 236 | $this->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
237 | } | ||
238 | |||
239 | private function getWallabagV2Import($unsetUser = false, $dispatched = 0) | ||
240 | { | ||
241 | $this->user = new User(); | ||
242 | |||
243 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
244 | ->disableOriginalConstructor() | ||
245 | ->getMock(); | ||
246 | |||
247 | $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') | ||
248 | ->disableOriginalConstructor() | ||
249 | ->getMock(); | ||
250 | |||
251 | $this->em | ||
252 | ->expects($this->any()) | ||
253 | ->method('getUnitOfWork') | ||
254 | ->willReturn($this->uow); | ||
255 | |||
256 | $this->uow | ||
257 | ->expects($this->any()) | ||
258 | ->method('getScheduledEntityInsertions') | ||
259 | ->willReturn([]); | ||
260 | |||
261 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
262 | ->disableOriginalConstructor() | ||
263 | ->getMock(); | ||
264 | |||
265 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
266 | ->disableOriginalConstructor() | ||
267 | ->getMock(); | ||
268 | |||
269 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
270 | ->disableOriginalConstructor() | ||
271 | ->getMock(); | ||
272 | |||
273 | $dispatcher | ||
274 | ->expects($this->exactly($dispatched)) | ||
275 | ->method('dispatch'); | ||
276 | |||
277 | $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); | ||
278 | |||
279 | $this->logHandler = new TestHandler(); | ||
280 | $logger = new Logger('test', [$this->logHandler]); | ||
281 | $wallabag->setLogger($logger); | ||
282 | |||
283 | if (false === $unsetUser) { | ||
284 | $wallabag->setUser($this->user); | ||
285 | } | ||
286 | |||
287 | return $wallabag; | ||
288 | } | 288 | } |
289 | } | 289 | } |