aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Tests/Import
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Tests/Import')
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php94
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php33
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php13
3 files changed, 132 insertions, 8 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 @@
3namespace Wallabag\ImportBundle\Tests\Import; 3namespace Wallabag\ImportBundle\Tests\Import;
4 4
5use Wallabag\UserBundle\Entity\User; 5use Wallabag\UserBundle\Entity\User;
6use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\ImportBundle\Import\PocketImport; 7use Wallabag\ImportBundle\Import\PocketImport;
7use GuzzleHttp\Client; 8use GuzzleHttp\Client;
8use GuzzleHttp\Subscriber\Mock; 9use 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();
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
index 9a563a11..fbcd270d 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
@@ -81,6 +81,39 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
81 $this->assertEquals(['skipped' => 1, 'imported' => 3], $wallabagV1Import->getSummary()); 81 $this->assertEquals(['skipped' => 1, 'imported' => 3], $wallabagV1Import->getSummary());
82 } 82 }
83 83
84 public function testImportAndMarkAllAsRead()
85 {
86 $wallabagV1Import = $this->getWallabagV1Import();
87 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json');
88
89 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
90 ->disableOriginalConstructor()
91 ->getMock();
92
93 $entryRepo->expects($this->exactly(3))
94 ->method('findByUrlAndUserId')
95 ->will($this->onConsecutiveCalls(false, false, false));
96
97 $this->em
98 ->expects($this->any())
99 ->method('getRepository')
100 ->willReturn($entryRepo);
101
102 // check that every entry persisted are archived
103 $this->em
104 ->expects($this->any())
105 ->method('persist')
106 ->with($this->callback(function($persistedEntry) {
107 return $persistedEntry->isArchived();
108 }));
109
110 $res = $wallabagV1Import->setMarkAsRead(true)->import();
111
112 $this->assertTrue($res);
113
114 $this->assertEquals(['skipped' => 0, 'imported' => 3], $wallabagV1Import->getSummary());
115 }
116
84 public function testImportBadFile() 117 public function testImportBadFile()
85 { 118 {
86 $wallabagV1Import = $this->getWallabagV1Import(); 119 $wallabagV1Import = $this->getWallabagV1Import();
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php
index 8728364b..c461168c 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php
@@ -90,15 +90,18 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
90 ->method('getRepository') 90 ->method('getRepository')
91 ->willReturn($entryRepo); 91 ->willReturn($entryRepo);
92 92
93 // check that every entry persisted are archived
94 $this->em
95 ->expects($this->any())
96 ->method('persist')
97 ->with($this->callback(function($persistedEntry) {
98 return $persistedEntry->isArchived();
99 }));
100
93 $res = $wallabagV2Import->setMarkAsRead(true)->import(); 101 $res = $wallabagV2Import->setMarkAsRead(true)->import();
94 102
95 $this->assertTrue($res); 103 $this->assertTrue($res);
96 104
97 $this->em
98 ->expects($this->any())
99 ->method('getBuilderForArchiveByUser')
100 ->willReturn($entryRepo);
101
102 $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); 105 $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary());
103 } 106 }
104 107