diff options
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/PocketImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 26c6b825..5ad3e435 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php | |||
@@ -343,6 +343,87 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
343 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); | 343 | $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); |
344 | } | 344 | } |
345 | 345 | ||
346 | /** | ||
347 | * Will sample results from https://getpocket.com/developer/docs/v3/retrieve. | ||
348 | */ | ||
349 | public function testImportWithRabbit() | ||
350 | { | ||
351 | $client = new Client(); | ||
352 | |||
353 | $body = <<<'JSON' | ||
354 | { | ||
355 | "item_id": "229279689", | ||
356 | "resolved_id": "229279689", | ||
357 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
358 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | ||
359 | "favorite": "1", | ||
360 | "status": "1", | ||
361 | "resolved_title": "The Massive Ryder Cup Preview", | ||
362 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
363 | "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.", | ||
364 | "is_article": "1", | ||
365 | "has_video": "0", | ||
366 | "has_image": "0", | ||
367 | "word_count": "3197" | ||
368 | } | ||
369 | JSON; | ||
370 | |||
371 | $mock = new Mock([ | ||
372 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | ||
373 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | ||
374 | { | ||
375 | "status": 1, | ||
376 | "list": { | ||
377 | "229279690": '.$body.' | ||
378 | } | ||
379 | } | ||
380 | ')), | ||
381 | ]); | ||
382 | |||
383 | $client->getEmitter()->attach($mock); | ||
384 | |||
385 | $pocketImport = $this->getPocketImport(); | ||
386 | |||
387 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
388 | ->disableOriginalConstructor() | ||
389 | ->getMock(); | ||
390 | |||
391 | $entryRepo->expects($this->never()) | ||
392 | ->method('findByUrlAndUserId'); | ||
393 | |||
394 | $this->em | ||
395 | ->expects($this->never()) | ||
396 | ->method('getRepository'); | ||
397 | |||
398 | $entry = new Entry($this->user); | ||
399 | |||
400 | $this->contentProxy | ||
401 | ->expects($this->never()) | ||
402 | ->method('updateEntry'); | ||
403 | |||
404 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
405 | ->disableOriginalConstructor() | ||
406 | ->getMock(); | ||
407 | |||
408 | $bodyAsArray = json_decode($body, true); | ||
409 | // because with just use `new User()` so it doesn't have an id | ||
410 | $bodyAsArray['userId'] = null; | ||
411 | |||
412 | $producer | ||
413 | ->expects($this->once()) | ||
414 | ->method('publish') | ||
415 | ->with(json_encode($bodyAsArray)); | ||
416 | |||
417 | $pocketImport->setClient($client); | ||
418 | $pocketImport->setRabbitmqProducer($producer); | ||
419 | $pocketImport->authorize('wunderbar_code'); | ||
420 | |||
421 | $res = $pocketImport->setMarkAsRead(true)->import(); | ||
422 | |||
423 | $this->assertTrue($res); | ||
424 | $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); | ||
425 | } | ||
426 | |||
346 | public function testImportBadResponse() | 427 | public function testImportBadResponse() |
347 | { | 428 | { |
348 | $client = new Client(); | 429 | $client = new Client(); |