X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FImportBundle%2FTests%2FImport%2FPocketImportTest.php;h=43b60ec3eac0b5404d24150001a32017caa14166;hb=0d42217e4e8210dd2cf86f35ba9662ca02c8a2dc;hp=cf706fa9490bb53bad0ea2585a142557b41d42e8;hpb=252ebd60719d32ec954d0519c9edf2b52b03310c;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php index cf706fa9..43b60ec3 100644 --- a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php +++ b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php @@ -3,6 +3,7 @@ namespace Wallabag\ImportBundle\Tests\Import; use Wallabag\UserBundle\Entity\User; +use Wallabag\CoreBundle\Entity\Entry; use Wallabag\ImportBundle\Import\PocketImport; use GuzzleHttp\Client; use GuzzleHttp\Subscriber\Mock; @@ -55,11 +56,20 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $config = $this->getMockBuilder('Craue\ConfigBundle\Util\Config') + ->disableOriginalConstructor() + ->getMock(); + + $config->expects($this->any()) + ->method('get') + ->with('pocket_consumer_key') + ->willReturn($consumerKey); + $pocket = new PocketImportMock( $this->tokenStorage, $this->em, $this->contentProxy, - $consumerKey + $config ); $this->logHandler = new TestHandler(); @@ -74,7 +84,8 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $pocketImport = $this->getPocketImport(); $this->assertEquals('Pocket', $pocketImport->getName()); - $this->assertEquals('This importer will import all your Pocket data.', $pocketImport->getDescription()); + $this->assertNotEmpty($pocketImport->getUrl()); + $this->assertEquals('import.pocket.description', $pocketImport->getDescription()); } public function testOAuthRequest() @@ -247,42 +258,113 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $entryRepo->expects($this->exactly(2)) - ->method('existByUrlAndUserId') + ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); - $tag = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Tag') - ->disableOriginalConstructor() - ->getMock(); + $this->em + ->expects($this->exactly(2)) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = new Entry($this->user); + + $this->contentProxy + ->expects($this->once()) + ->method('updateEntry') + ->willReturn($entry); + + $pocketImport->setClient($client); + $pocketImport->authorize('wunderbar_code'); + + $res = $pocketImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 1, 'imported' => 1], $pocketImport->getSummary()); + } + + /** + * Will sample results from https://getpocket.com/developer/docs/v3/retrieve. + */ + public function testImportAndMarkAllAsRead() + { + $client = new Client(); - $tagRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') + $mock = new Mock([ + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' + { + "status": 1, + "list": { + "229279689": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "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.", + "is_article": "1", + "has_video": "1", + "has_image": "1", + "word_count": "3197" + }, + "229279690": { + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview/2", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "0", + "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.", + "is_article": "1", + "has_video": "0", + "has_image": "0", + "word_count": "3197" + } + } + } + ')), + ]); + + $client->getEmitter()->attach($mock); + + $pocketImport = $this->getPocketImport(); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $tagRepo->expects($this->exactly(2)) - ->method('findOneByLabelAndUserId') - ->will($this->onConsecutiveCalls(false, $tag)); + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, false)); $this->em - ->expects($this->any()) + ->expects($this->exactly(2)) ->method('getRepository') - ->will($this->onConsecutiveCalls($entryRepo, $tagRepo, $tagRepo, $entryRepo)); + ->willReturn($entryRepo); - $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') - ->disableOriginalConstructor() - ->getMock(); + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $entry = new Entry($this->user); $this->contentProxy - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('updateEntry') ->willReturn($entry); $pocketImport->setClient($client); $pocketImport->authorize('wunderbar_code'); - $res = $pocketImport->import(); + $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); } public function testImportBadResponse()