diff options
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 101 |
1 files changed, 99 insertions, 2 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index bdc47dac..82dc4c7e 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | |||
@@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; | |||
5 | use Wallabag\ImportBundle\Import\WallabagV1Import; | 5 | use Wallabag\ImportBundle\Import\WallabagV1Import; |
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 WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | 14 | class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase |
12 | { | 15 | { |
@@ -23,6 +26,20 @@ class WallabagV1ImportTest 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(); |
@@ -79,7 +96,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
79 | $res = $wallabagV1Import->import(); | 96 | $res = $wallabagV1Import->import(); |
80 | 97 | ||
81 | $this->assertTrue($res); | 98 | $this->assertTrue($res); |
82 | $this->assertEquals(['skipped' => 1, 'imported' => 3], $wallabagV1Import->getSummary()); | 99 | $this->assertEquals(['skipped' => 1, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); |
83 | } | 100 | } |
84 | 101 | ||
85 | public function testImportAndMarkAllAsRead() | 102 | public function testImportAndMarkAllAsRead() |
@@ -117,7 +134,87 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
117 | 134 | ||
118 | $this->assertTrue($res); | 135 | $this->assertTrue($res); |
119 | 136 | ||
120 | $this->assertEquals(['skipped' => 0, 'imported' => 3], $wallabagV1Import->getSummary()); | 137 | $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); |
138 | } | ||
139 | |||
140 | public function testImportWithRabbit() | ||
141 | { | ||
142 | $wallabagV1Import = $this->getWallabagV1Import(); | ||
143 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); | ||
144 | |||
145 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
146 | ->disableOriginalConstructor() | ||
147 | ->getMock(); | ||
148 | |||
149 | $entryRepo->expects($this->never()) | ||
150 | ->method('findByUrlAndUserId'); | ||
151 | |||
152 | $this->em | ||
153 | ->expects($this->never()) | ||
154 | ->method('getRepository'); | ||
155 | |||
156 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
157 | ->disableOriginalConstructor() | ||
158 | ->getMock(); | ||
159 | |||
160 | $this->contentProxy | ||
161 | ->expects($this->never()) | ||
162 | ->method('updateEntry'); | ||
163 | |||
164 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
165 | ->disableOriginalConstructor() | ||
166 | ->getMock(); | ||
167 | |||
168 | $producer | ||
169 | ->expects($this->exactly(4)) | ||
170 | ->method('publish'); | ||
171 | |||
172 | $wallabagV1Import->setProducer($producer); | ||
173 | |||
174 | $res = $wallabagV1Import->setMarkAsRead(true)->import(); | ||
175 | |||
176 | $this->assertTrue($res); | ||
177 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); | ||
178 | } | ||
179 | |||
180 | public function testImportWithRedis() | ||
181 | { | ||
182 | $wallabagV1Import = $this->getWallabagV1Import(); | ||
183 | $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); | ||
184 | |||
185 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
186 | ->disableOriginalConstructor() | ||
187 | ->getMock(); | ||
188 | |||
189 | $entryRepo->expects($this->never()) | ||
190 | ->method('findByUrlAndUserId'); | ||
191 | |||
192 | $this->em | ||
193 | ->expects($this->never()) | ||
194 | ->method('getRepository'); | ||
195 | |||
196 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
197 | ->disableOriginalConstructor() | ||
198 | ->getMock(); | ||
199 | |||
200 | $this->contentProxy | ||
201 | ->expects($this->never()) | ||
202 | ->method('updateEntry'); | ||
203 | |||
204 | $factory = new RedisMockFactory(); | ||
205 | $redisMock = $factory->getAdapter('Predis\Client', true); | ||
206 | |||
207 | $queue = new RedisQueue($redisMock, 'wallabag_v1'); | ||
208 | $producer = new Producer($queue); | ||
209 | |||
210 | $wallabagV1Import->setProducer($producer); | ||
211 | |||
212 | $res = $wallabagV1Import->setMarkAsRead(true)->import(); | ||
213 | |||
214 | $this->assertTrue($res); | ||
215 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); | ||
216 | |||
217 | $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); | ||
121 | } | 218 | } |
122 | 219 | ||
123 | public function testImportBadFile() | 220 | public function testImportBadFile() |