aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/PocketImportTest.php')
-rw-r--r--tests/Wallabag/ImportBundle/Import/PocketImportTest.php150
1 files changed, 75 insertions, 75 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
index b81ebe15..fe59f867 100644
--- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
@@ -2,19 +2,19 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\UserBundle\Entity\User;
6use Wallabag\CoreBundle\Entity\Entry;
7use Wallabag\CoreBundle\Entity\Config;
8use Wallabag\ImportBundle\Import\PocketImport;
9use GuzzleHttp\Client; 5use GuzzleHttp\Client;
10use GuzzleHttp\Subscriber\Mock;
11use GuzzleHttp\Message\Response; 6use GuzzleHttp\Message\Response;
12use GuzzleHttp\Stream\Stream; 7use GuzzleHttp\Stream\Stream;
13use Wallabag\ImportBundle\Redis\Producer; 8use GuzzleHttp\Subscriber\Mock;
14use Monolog\Logger; 9use M6Web\Component\RedisMock\RedisMockFactory;
15use Monolog\Handler\TestHandler; 10use Monolog\Handler\TestHandler;
11use Monolog\Logger;
16use Simpleue\Queue\RedisQueue; 12use Simpleue\Queue\RedisQueue;
17use M6Web\Component\RedisMock\RedisMockFactory; 13use Wallabag\CoreBundle\Entity\Config;
14use Wallabag\CoreBundle\Entity\Entry;
15use Wallabag\ImportBundle\Import\PocketImport;
16use Wallabag\ImportBundle\Redis\Producer;
17use Wallabag\UserBundle\Entity\User;
18 18
19class PocketImportTest extends \PHPUnit_Framework_TestCase 19class PocketImportTest extends \PHPUnit_Framework_TestCase
20{ 20{
@@ -26,66 +26,13 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
26 protected $tagsAssigner; 26 protected $tagsAssigner;
27 protected $uow; 27 protected $uow;
28 28
29 private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0)
30 {
31 $this->user = new User();
32
33 $config = new Config($this->user);
34 $config->setPocketConsumerKey('xxx');
35
36 $this->user->setConfig($config);
37
38 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
39 ->disableOriginalConstructor()
40 ->getMock();
41
42 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
43 ->disableOriginalConstructor()
44 ->getMock();
45
46 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
47 ->disableOriginalConstructor()
48 ->getMock();
49
50 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
51 ->disableOriginalConstructor()
52 ->getMock();
53
54 $this->em
55 ->expects($this->any())
56 ->method('getUnitOfWork')
57 ->willReturn($this->uow);
58
59 $this->uow
60 ->expects($this->any())
61 ->method('getScheduledEntityInsertions')
62 ->willReturn([]);
63
64 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
65 ->disableOriginalConstructor()
66 ->getMock();
67
68 $dispatcher
69 ->expects($this->exactly($dispatched))
70 ->method('dispatch');
71
72 $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
73 $pocket->setUser($this->user);
74
75 $this->logHandler = new TestHandler();
76 $logger = new Logger('test', [$this->logHandler]);
77 $pocket->setLogger($logger);
78
79 return $pocket;
80 }
81
82 public function testInit() 29 public function testInit()
83 { 30 {
84 $pocketImport = $this->getPocketImport(); 31 $pocketImport = $this->getPocketImport();
85 32
86 $this->assertEquals('Pocket', $pocketImport->getName()); 33 $this->assertSame('Pocket', $pocketImport->getName());
87 $this->assertNotEmpty($pocketImport->getUrl()); 34 $this->assertNotEmpty($pocketImport->getUrl());
88 $this->assertEquals('import.pocket.description', $pocketImport->getDescription()); 35 $this->assertSame('import.pocket.description', $pocketImport->getDescription());
89 } 36 }
90 37
91 public function testOAuthRequest() 38 public function testOAuthRequest()
@@ -103,7 +50,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
103 50
104 $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); 51 $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect');
105 52
106 $this->assertEquals('wunderbar_code', $code); 53 $this->assertSame('wunderbar_code', $code);
107 } 54 }
108 55
109 public function testOAuthRequestBadResponse() 56 public function testOAuthRequestBadResponse()
@@ -125,7 +72,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
125 72
126 $records = $this->logHandler->getRecords(); 73 $records = $this->logHandler->getRecords();
127 $this->assertContains('PocketImport: Failed to request token', $records[0]['message']); 74 $this->assertContains('PocketImport: Failed to request token', $records[0]['message']);
128 $this->assertEquals('ERROR', $records[0]['level_name']); 75 $this->assertSame('ERROR', $records[0]['level_name']);
129 } 76 }
130 77
131 public function testOAuthAuthorize() 78 public function testOAuthAuthorize()
@@ -144,7 +91,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
144 $res = $pocketImport->authorize('wunderbar_code'); 91 $res = $pocketImport->authorize('wunderbar_code');
145 92
146 $this->assertTrue($res); 93 $this->assertTrue($res);
147 $this->assertEquals('wunderbar_token', $pocketImport->getAccessToken()); 94 $this->assertSame('wunderbar_token', $pocketImport->getAccessToken());
148 } 95 }
149 96
150 public function testOAuthAuthorizeBadResponse() 97 public function testOAuthAuthorizeBadResponse()
@@ -166,7 +113,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
166 113
167 $records = $this->logHandler->getRecords(); 114 $records = $this->logHandler->getRecords();
168 $this->assertContains('PocketImport: Failed to authorize client', $records[0]['message']); 115 $this->assertContains('PocketImport: Failed to authorize client', $records[0]['message']);
169 $this->assertEquals('ERROR', $records[0]['level_name']); 116 $this->assertSame('ERROR', $records[0]['level_name']);
170 } 117 }
171 118
172 /** 119 /**
@@ -291,7 +238,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
291 $res = $pocketImport->import(); 238 $res = $pocketImport->import();
292 239
293 $this->assertTrue($res); 240 $this->assertTrue($res);
294 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); 241 $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary());
295 } 242 }
296 243
297 /** 244 /**
@@ -386,7 +333,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
386 $res = $pocketImport->setMarkAsRead(true)->import(); 333 $res = $pocketImport->setMarkAsRead(true)->import();
387 334
388 $this->assertTrue($res); 335 $this->assertTrue($res);
389 $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); 336 $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary());
390 } 337 }
391 338
392 /** 339 /**
@@ -425,7 +372,7 @@ JSON;
425 { 372 {
426 "status": 1, 373 "status": 1,
427 "list": { 374 "list": {
428 "229279690": '.$body.' 375 "229279690": ' . $body . '
429 } 376 }
430 } 377 }
431 ')), 378 ')),
@@ -472,7 +419,7 @@ JSON;
472 $res = $pocketImport->setMarkAsRead(true)->import(); 419 $res = $pocketImport->setMarkAsRead(true)->import();
473 420
474 $this->assertTrue($res); 421 $this->assertTrue($res);
475 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); 422 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary());
476 } 423 }
477 424
478 /** 425 /**
@@ -511,7 +458,7 @@ JSON;
511 { 458 {
512 "status": 1, 459 "status": 1,
513 "list": { 460 "list": {
514 "229279690": '.$body.' 461 "229279690": ' . $body . '
515 } 462 }
516 } 463 }
517 ')), 464 ')),
@@ -551,7 +498,7 @@ JSON;
551 $res = $pocketImport->setMarkAsRead(true)->import(); 498 $res = $pocketImport->setMarkAsRead(true)->import();
552 499
553 $this->assertTrue($res); 500 $this->assertTrue($res);
554 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); 501 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary());
555 502
556 $this->assertNotEmpty($redisMock->lpop('pocket')); 503 $this->assertNotEmpty($redisMock->lpop('pocket'));
557 } 504 }
@@ -577,7 +524,7 @@ JSON;
577 524
578 $records = $this->logHandler->getRecords(); 525 $records = $this->logHandler->getRecords();
579 $this->assertContains('PocketImport: Failed to import', $records[0]['message']); 526 $this->assertContains('PocketImport: Failed to import', $records[0]['message']);
580 $this->assertEquals('ERROR', $records[0]['level_name']); 527 $this->assertSame('ERROR', $records[0]['level_name']);
581 } 528 }
582 529
583 public function testImportWithExceptionFromGraby() 530 public function testImportWithExceptionFromGraby()
@@ -630,6 +577,59 @@ JSON;
630 $res = $pocketImport->import(); 577 $res = $pocketImport->import();
631 578
632 $this->assertTrue($res); 579 $this->assertTrue($res);
633 $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;
634 } 634 }
635} 635}