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