diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-10-23 11:09:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 11:09:17 +0200 |
commit | 1953a872932a63792293b4aec087880265ba89f7 (patch) | |
tree | fd16599e737fcdaf193c933ef3ec4a4ee248b117 /tests/Wallabag/ImportBundle/Import/PocketImportTest.php | |
parent | d83d25dadec2c38460a32d96f5d2903426fec9d3 (diff) | |
parent | 702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff) | |
download | wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst wallabag-1953a872932a63792293b4aec087880265ba89f7.zip |
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/PocketImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 148 |
1 files changed, 77 insertions, 71 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 141ece36..fe59f867 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php | |||
@@ -2,19 +2,19 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Import; | 3 | namespace Tests\Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use Wallabag\UserBundle\Entity\User; | ||
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
7 | use Wallabag\CoreBundle\Entity\Config; | ||
8 | use Wallabag\ImportBundle\Import\PocketImport; | ||
9 | use GuzzleHttp\Client; | 5 | use GuzzleHttp\Client; |
10 | use GuzzleHttp\Subscriber\Mock; | ||
11 | use GuzzleHttp\Message\Response; | 6 | use GuzzleHttp\Message\Response; |
12 | use GuzzleHttp\Stream\Stream; | 7 | use GuzzleHttp\Stream\Stream; |
13 | use Wallabag\ImportBundle\Redis\Producer; | 8 | use GuzzleHttp\Subscriber\Mock; |
14 | use Monolog\Logger; | 9 | use M6Web\Component\RedisMock\RedisMockFactory; |
15 | use Monolog\Handler\TestHandler; | 10 | use Monolog\Handler\TestHandler; |
11 | use Monolog\Logger; | ||
16 | use Simpleue\Queue\RedisQueue; | 12 | use Simpleue\Queue\RedisQueue; |
17 | use M6Web\Component\RedisMock\RedisMockFactory; | 13 | use Wallabag\CoreBundle\Entity\Config; |
14 | use Wallabag\CoreBundle\Entity\Entry; | ||
15 | use Wallabag\ImportBundle\Import\PocketImport; | ||
16 | use Wallabag\ImportBundle\Redis\Producer; | ||
17 | use Wallabag\UserBundle\Entity\User; | ||
18 | 18 | ||
19 | class PocketImportTest extends \PHPUnit_Framework_TestCase | 19 | class PocketImportTest extends \PHPUnit_Framework_TestCase |
20 | { | 20 | { |
@@ -23,63 +23,16 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
23 | protected $em; | 23 | protected $em; |
24 | protected $contentProxy; | 24 | protected $contentProxy; |
25 | protected $logHandler; | 25 | protected $logHandler; |
26 | 26 | protected $tagsAssigner; | |
27 | private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) | 27 | protected $uow; |
28 | { | ||
29 | $this->user = new User(); | ||
30 | |||
31 | $config = new Config($this->user); | ||
32 | $config->setPocketConsumerKey('xxx'); | ||
33 | |||
34 | $this->user->setConfig($config); | ||
35 | |||
36 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
37 | ->disableOriginalConstructor() | ||
38 | ->getMock(); | ||
39 | |||
40 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
41 | ->disableOriginalConstructor() | ||
42 | ->getMock(); | ||
43 | |||
44 | $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') | ||
45 | ->disableOriginalConstructor() | ||
46 | ->getMock(); | ||
47 | |||
48 | $this->em | ||
49 | ->expects($this->any()) | ||
50 | ->method('getUnitOfWork') | ||
51 | ->willReturn($this->uow); | ||
52 | |||
53 | $this->uow | ||
54 | ->expects($this->any()) | ||
55 | ->method('getScheduledEntityInsertions') | ||
56 | ->willReturn([]); | ||
57 | |||
58 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
59 | ->disableOriginalConstructor() | ||
60 | ->getMock(); | ||
61 | |||
62 | $dispatcher | ||
63 | ->expects($this->exactly($dispatched)) | ||
64 | ->method('dispatch'); | ||
65 | |||
66 | $pocket = new PocketImport($this->em, $this->contentProxy, $dispatcher); | ||
67 | $pocket->setUser($this->user); | ||
68 | |||
69 | $this->logHandler = new TestHandler(); | ||
70 | $logger = new Logger('test', [$this->logHandler]); | ||
71 | $pocket->setLogger($logger); | ||
72 | |||
73 | return $pocket; | ||
74 | } | ||
75 | 28 | ||
76 | public function testInit() | 29 | public function testInit() |
77 | { | 30 | { |
78 | $pocketImport = $this->getPocketImport(); | 31 | $pocketImport = $this->getPocketImport(); |
79 | 32 | ||
80 | $this->assertEquals('Pocket', $pocketImport->getName()); | 33 | $this->assertSame('Pocket', $pocketImport->getName()); |
81 | $this->assertNotEmpty($pocketImport->getUrl()); | 34 | $this->assertNotEmpty($pocketImport->getUrl()); |
82 | $this->assertEquals('import.pocket.description', $pocketImport->getDescription()); | 35 | $this->assertSame('import.pocket.description', $pocketImport->getDescription()); |
83 | } | 36 | } |
84 | 37 | ||
85 | public function testOAuthRequest() | 38 | public function testOAuthRequest() |
@@ -97,7 +50,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
97 | 50 | ||
98 | $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); | 51 | $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); |
99 | 52 | ||
100 | $this->assertEquals('wunderbar_code', $code); | 53 | $this->assertSame('wunderbar_code', $code); |
101 | } | 54 | } |
102 | 55 | ||
103 | public function testOAuthRequestBadResponse() | 56 | public function testOAuthRequestBadResponse() |
@@ -119,7 +72,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
119 | 72 | ||
120 | $records = $this->logHandler->getRecords(); | 73 | $records = $this->logHandler->getRecords(); |
121 | $this->assertContains('PocketImport: Failed to request token', $records[0]['message']); | 74 | $this->assertContains('PocketImport: Failed to request token', $records[0]['message']); |
122 | $this->assertEquals('ERROR', $records[0]['level_name']); | 75 | $this->assertSame('ERROR', $records[0]['level_name']); |
123 | } | 76 | } |
124 | 77 | ||
125 | public function testOAuthAuthorize() | 78 | public function testOAuthAuthorize() |
@@ -138,7 +91,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
138 | $res = $pocketImport->authorize('wunderbar_code'); | 91 | $res = $pocketImport->authorize('wunderbar_code'); |
139 | 92 | ||
140 | $this->assertTrue($res); | 93 | $this->assertTrue($res); |
141 | $this->assertEquals('wunderbar_token', $pocketImport->getAccessToken()); | 94 | $this->assertSame('wunderbar_token', $pocketImport->getAccessToken()); |
142 | } | 95 | } |
143 | 96 | ||
144 | public function testOAuthAuthorizeBadResponse() | 97 | public function testOAuthAuthorizeBadResponse() |
@@ -160,7 +113,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
160 | 113 | ||
161 | $records = $this->logHandler->getRecords(); | 114 | $records = $this->logHandler->getRecords(); |
162 | $this->assertContains('PocketImport: Failed to authorize client', $records[0]['message']); | 115 | $this->assertContains('PocketImport: Failed to authorize client', $records[0]['message']); |
163 | $this->assertEquals('ERROR', $records[0]['level_name']); | 116 | $this->assertSame('ERROR', $records[0]['level_name']); |
164 | } | 117 | } |
165 | 118 | ||
166 | /** | 119 | /** |
@@ -285,7 +238,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
285 | $res = $pocketImport->import(); | 238 | $res = $pocketImport->import(); |
286 | 239 | ||
287 | $this->assertTrue($res); | 240 | $this->assertTrue($res); |
288 | $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); | 241 | $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); |
289 | } | 242 | } |
290 | 243 | ||
291 | /** | 244 | /** |
@@ -380,7 +333,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
380 | $res = $pocketImport->setMarkAsRead(true)->import(); | 333 | $res = $pocketImport->setMarkAsRead(true)->import(); |
381 | 334 | ||
382 | $this->assertTrue($res); | 335 | $this->assertTrue($res); |
383 | $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); | 336 | $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); |
384 | } | 337 | } |
385 | 338 | ||
386 | /** | 339 | /** |
@@ -419,7 +372,7 @@ JSON; | |||
419 | { | 372 | { |
420 | "status": 1, | 373 | "status": 1, |
421 | "list": { | 374 | "list": { |
422 | "229279690": '.$body.' | 375 | "229279690": ' . $body . ' |
423 | } | 376 | } |
424 | } | 377 | } |
425 | ')), | 378 | ')), |
@@ -466,7 +419,7 @@ JSON; | |||
466 | $res = $pocketImport->setMarkAsRead(true)->import(); | 419 | $res = $pocketImport->setMarkAsRead(true)->import(); |
467 | 420 | ||
468 | $this->assertTrue($res); | 421 | $this->assertTrue($res); |
469 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); | 422 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); |
470 | } | 423 | } |
471 | 424 | ||
472 | /** | 425 | /** |
@@ -505,7 +458,7 @@ JSON; | |||
505 | { | 458 | { |
506 | "status": 1, | 459 | "status": 1, |
507 | "list": { | 460 | "list": { |
508 | "229279690": '.$body.' | 461 | "229279690": ' . $body . ' |
509 | } | 462 | } |
510 | } | 463 | } |
511 | ')), | 464 | ')), |
@@ -545,7 +498,7 @@ JSON; | |||
545 | $res = $pocketImport->setMarkAsRead(true)->import(); | 498 | $res = $pocketImport->setMarkAsRead(true)->import(); |
546 | 499 | ||
547 | $this->assertTrue($res); | 500 | $this->assertTrue($res); |
548 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); | 501 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); |
549 | 502 | ||
550 | $this->assertNotEmpty($redisMock->lpop('pocket')); | 503 | $this->assertNotEmpty($redisMock->lpop('pocket')); |
551 | } | 504 | } |
@@ -571,7 +524,7 @@ JSON; | |||
571 | 524 | ||
572 | $records = $this->logHandler->getRecords(); | 525 | $records = $this->logHandler->getRecords(); |
573 | $this->assertContains('PocketImport: Failed to import', $records[0]['message']); | 526 | $this->assertContains('PocketImport: Failed to import', $records[0]['message']); |
574 | $this->assertEquals('ERROR', $records[0]['level_name']); | 527 | $this->assertSame('ERROR', $records[0]['level_name']); |
575 | } | 528 | } |
576 | 529 | ||
577 | public function testImportWithExceptionFromGraby() | 530 | public function testImportWithExceptionFromGraby() |
@@ -624,6 +577,59 @@ JSON; | |||
624 | $res = $pocketImport->import(); | 577 | $res = $pocketImport->import(); |
625 | 578 | ||
626 | $this->assertTrue($res); | 579 | $this->assertTrue($res); |
627 | $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); | 580 | $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); |
581 | } | ||
582 | |||
583 | private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) | ||
584 | { | ||
585 | $this->user = new User(); | ||
586 | |||
587 | $config = new Config($this->user); | ||
588 | $config->setPocketConsumerKey('xxx'); | ||
589 | |||
590 | $this->user->setConfig($config); | ||
591 | |||
592 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
593 | ->disableOriginalConstructor() | ||
594 | ->getMock(); | ||
595 | |||
596 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
597 | ->disableOriginalConstructor() | ||
598 | ->getMock(); | ||
599 | |||
600 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
601 | ->disableOriginalConstructor() | ||
602 | ->getMock(); | ||
603 | |||
604 | $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') | ||
605 | ->disableOriginalConstructor() | ||
606 | ->getMock(); | ||
607 | |||
608 | $this->em | ||
609 | ->expects($this->any()) | ||
610 | ->method('getUnitOfWork') | ||
611 | ->willReturn($this->uow); | ||
612 | |||
613 | $this->uow | ||
614 | ->expects($this->any()) | ||
615 | ->method('getScheduledEntityInsertions') | ||
616 | ->willReturn([]); | ||
617 | |||
618 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
619 | ->disableOriginalConstructor() | ||
620 | ->getMock(); | ||
621 | |||
622 | $dispatcher | ||
623 | ->expects($this->exactly($dispatched)) | ||
624 | ->method('dispatch'); | ||
625 | |||
626 | $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); | ||
627 | $pocket->setUser($this->user); | ||
628 | |||
629 | $this->logHandler = new TestHandler(); | ||
630 | $logger = new Logger('test', [$this->logHandler]); | ||
631 | $pocket->setLogger($logger); | ||
632 | |||
633 | return $pocket; | ||
628 | } | 634 | } |
629 | } | 635 | } |