diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php | 94 |
1 files changed, 91 insertions, 3 deletions
diff --git a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php index f44786b1..bc9e2f42 100644 --- a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php +++ b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Wallabag\ImportBundle\Tests\Import; | 3 | namespace Wallabag\ImportBundle\Tests\Import; |
4 | 4 | ||
5 | use Wallabag\UserBundle\Entity\User; | 5 | use Wallabag\UserBundle\Entity\User; |
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | use Wallabag\ImportBundle\Import\PocketImport; | 7 | use Wallabag\ImportBundle\Import\PocketImport; |
7 | use GuzzleHttp\Client; | 8 | use GuzzleHttp\Client; |
8 | use GuzzleHttp\Subscriber\Mock; | 9 | use GuzzleHttp\Subscriber\Mock; |
@@ -265,9 +266,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
265 | ->method('getRepository') | 266 | ->method('getRepository') |
266 | ->willReturn($entryRepo); | 267 | ->willReturn($entryRepo); |
267 | 268 | ||
268 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | 269 | $entry = new Entry($this->user); |
269 | ->disableOriginalConstructor() | ||
270 | ->getMock(); | ||
271 | 270 | ||
272 | $this->contentProxy | 271 | $this->contentProxy |
273 | ->expects($this->once()) | 272 | ->expects($this->once()) |
@@ -283,6 +282,95 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
283 | $this->assertEquals(['skipped' => 1, 'imported' => 1], $pocketImport->getSummary()); | 282 | $this->assertEquals(['skipped' => 1, 'imported' => 1], $pocketImport->getSummary()); |
284 | } | 283 | } |
285 | 284 | ||
285 | /** | ||
286 | * Will sample results from https://getpocket.com/developer/docs/v3/retrieve. | ||
287 | */ | ||
288 | public function testImportAndMarkAllAsRead() | ||
289 | { | ||
290 | $client = new Client(); | ||
291 | |||
292 | $mock = new Mock([ | ||
293 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | ||
294 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | ||
295 | { | ||
296 | "status": 1, | ||
297 | "list": { | ||
298 | "229279689": { | ||
299 | "item_id": "229279689", | ||
300 | "resolved_id": "229279689", | ||
301 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
302 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | ||
303 | "favorite": "1", | ||
304 | "status": "1", | ||
305 | "resolved_title": "The Massive Ryder Cup Preview", | ||
306 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
307 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", | ||
308 | "is_article": "1", | ||
309 | "has_video": "1", | ||
310 | "has_image": "1", | ||
311 | "word_count": "3197" | ||
312 | }, | ||
313 | "229279690": { | ||
314 | "item_id": "229279689", | ||
315 | "resolved_id": "229279689", | ||
316 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview/2", | ||
317 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | ||
318 | "favorite": "1", | ||
319 | "status": "0", | ||
320 | "resolved_title": "The Massive Ryder Cup Preview", | ||
321 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
322 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", | ||
323 | "is_article": "1", | ||
324 | "has_video": "0", | ||
325 | "has_image": "0", | ||
326 | "word_count": "3197" | ||
327 | } | ||
328 | } | ||
329 | } | ||
330 | ')), | ||
331 | ]); | ||
332 | |||
333 | $client->getEmitter()->attach($mock); | ||
334 | |||
335 | $pocketImport = $this->getPocketImport(); | ||
336 | |||
337 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
338 | ->disableOriginalConstructor() | ||
339 | ->getMock(); | ||
340 | |||
341 | $entryRepo->expects($this->exactly(2)) | ||
342 | ->method('findByUrlAndUserId') | ||
343 | ->will($this->onConsecutiveCalls(false, false)); | ||
344 | |||
345 | $this->em | ||
346 | ->expects($this->exactly(2)) | ||
347 | ->method('getRepository') | ||
348 | ->willReturn($entryRepo); | ||
349 | |||
350 | // check that every entry persisted are archived | ||
351 | $this->em | ||
352 | ->expects($this->any()) | ||
353 | ->method('persist') | ||
354 | ->with($this->callback(function($persistedEntry) { | ||
355 | return $persistedEntry->isArchived(); | ||
356 | })); | ||
357 | |||
358 | $entry = new Entry($this->user); | ||
359 | |||
360 | $this->contentProxy | ||
361 | ->expects($this->exactly(2)) | ||
362 | ->method('updateEntry') | ||
363 | ->willReturn($entry); | ||
364 | |||
365 | $pocketImport->setClient($client); | ||
366 | $pocketImport->authorize('wunderbar_code'); | ||
367 | |||
368 | $res = $pocketImport->setMarkAsRead(true)->import(); | ||
369 | |||
370 | $this->assertTrue($res); | ||
371 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); | ||
372 | } | ||
373 | |||
286 | public function testImportBadResponse() | 374 | public function testImportBadResponse() |
287 | { | 375 | { |
288 | $client = new Client(); | 376 | $client = new Client(); |