diff options
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 97 |
1 files changed, 93 insertions, 4 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 4a45e0f0..bea89efb 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | |||
@@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; | |||
5 | use Wallabag\ImportBundle\Import\WallabagV2Import; | 5 | use Wallabag\ImportBundle\Import\WallabagV2Import; |
6 | use Wallabag\UserBundle\Entity\User; | 6 | use Wallabag\UserBundle\Entity\User; |
7 | use Wallabag\CoreBundle\Entity\Entry; | 7 | use Wallabag\CoreBundle\Entity\Entry; |
8 | use Wallabag\ImportBundle\Redis\Producer; | ||
8 | use Monolog\Logger; | 9 | use Monolog\Logger; |
9 | use Monolog\Handler\TestHandler; | 10 | use Monolog\Handler\TestHandler; |
11 | use Simpleue\Queue\RedisQueue; | ||
12 | use M6Web\Component\RedisMock\RedisMockFactory; | ||
10 | 13 | ||
11 | class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | 14 | class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase |
12 | { | 15 | { |
@@ -23,6 +26,20 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
23 | ->disableOriginalConstructor() | 26 | ->disableOriginalConstructor() |
24 | ->getMock(); | 27 | ->getMock(); |
25 | 28 | ||
29 | $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') | ||
30 | ->disableOriginalConstructor() | ||
31 | ->getMock(); | ||
32 | |||
33 | $this->em | ||
34 | ->expects($this->any()) | ||
35 | ->method('getUnitOfWork') | ||
36 | ->willReturn($this->uow); | ||
37 | |||
38 | $this->uow | ||
39 | ->expects($this->any()) | ||
40 | ->method('getScheduledEntityInsertions') | ||
41 | ->willReturn([]); | ||
42 | |||
26 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | 43 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') |
27 | ->disableOriginalConstructor() | 44 | ->disableOriginalConstructor() |
28 | ->getMock(); | 45 | ->getMock(); |
@@ -75,7 +92,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
75 | $res = $wallabagV2Import->import(); | 92 | $res = $wallabagV2Import->import(); |
76 | 93 | ||
77 | $this->assertTrue($res); | 94 | $this->assertTrue($res); |
78 | $this->assertEquals(['skipped' => 22, 'imported' => 2], $wallabagV2Import->getSummary()); | 95 | $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
79 | } | 96 | } |
80 | 97 | ||
81 | public function testImportAndMarkAllAsRead() | 98 | public function testImportAndMarkAllAsRead() |
@@ -113,7 +130,79 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
113 | 130 | ||
114 | $this->assertTrue($res); | 131 | $this->assertTrue($res); |
115 | 132 | ||
116 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); | 133 | $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
134 | } | ||
135 | |||
136 | public function testImportWithRabbit() | ||
137 | { | ||
138 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
139 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | ||
140 | |||
141 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
142 | ->disableOriginalConstructor() | ||
143 | ->getMock(); | ||
144 | |||
145 | $entryRepo->expects($this->never()) | ||
146 | ->method('findByUrlAndUserId'); | ||
147 | |||
148 | $this->em | ||
149 | ->expects($this->never()) | ||
150 | ->method('getRepository'); | ||
151 | |||
152 | $this->contentProxy | ||
153 | ->expects($this->never()) | ||
154 | ->method('updateEntry'); | ||
155 | |||
156 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
157 | ->disableOriginalConstructor() | ||
158 | ->getMock(); | ||
159 | |||
160 | $producer | ||
161 | ->expects($this->exactly(24)) | ||
162 | ->method('publish'); | ||
163 | |||
164 | $wallabagV2Import->setProducer($producer); | ||
165 | |||
166 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | ||
167 | |||
168 | $this->assertTrue($res); | ||
169 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); | ||
170 | } | ||
171 | |||
172 | public function testImportWithRedis() | ||
173 | { | ||
174 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
175 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | ||
176 | |||
177 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
178 | ->disableOriginalConstructor() | ||
179 | ->getMock(); | ||
180 | |||
181 | $entryRepo->expects($this->never()) | ||
182 | ->method('findByUrlAndUserId'); | ||
183 | |||
184 | $this->em | ||
185 | ->expects($this->never()) | ||
186 | ->method('getRepository'); | ||
187 | |||
188 | $this->contentProxy | ||
189 | ->expects($this->never()) | ||
190 | ->method('updateEntry'); | ||
191 | |||
192 | $factory = new RedisMockFactory(); | ||
193 | $redisMock = $factory->getAdapter('Predis\Client', true); | ||
194 | |||
195 | $queue = new RedisQueue($redisMock, 'wallabag_v2'); | ||
196 | $producer = new Producer($queue); | ||
197 | |||
198 | $wallabagV2Import->setProducer($producer); | ||
199 | |||
200 | $res = $wallabagV2Import->setMarkAsRead(true)->import(); | ||
201 | |||
202 | $this->assertTrue($res); | ||
203 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); | ||
204 | |||
205 | $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); | ||
117 | } | 206 | } |
118 | 207 | ||
119 | public function testImportBadFile() | 208 | public function testImportBadFile() |
@@ -152,7 +241,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
152 | $res = $wallabagV2Import->import(); | 241 | $res = $wallabagV2Import->import(); |
153 | 242 | ||
154 | $this->assertFalse($res); | 243 | $this->assertFalse($res); |
155 | $this->assertEquals(['skipped' => 0, 'imported' => 0], $wallabagV2Import->getSummary()); | 244 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); |
156 | } | 245 | } |
157 | 246 | ||
158 | public function testImportWithExceptionFromGraby() | 247 | public function testImportWithExceptionFromGraby() |
@@ -181,6 +270,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
181 | $res = $wallabagV2Import->import(); | 270 | $res = $wallabagV2Import->import(); |
182 | 271 | ||
183 | $this->assertTrue($res); | 272 | $this->assertTrue($res); |
184 | $this->assertEquals(['skipped' => 24, 'imported' => 0], $wallabagV2Import->getSummary()); | 273 | $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); |
185 | } | 274 | } |
186 | } | 275 | } |