aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Tests
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-24 15:24:18 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:27:41 +0100
commit7ec2897ee0ad190dcb9f77032d785f2f9661b754 (patch)
tree7f91eabb9d555628d0c2a1e5da8deb6fc2a41b3c /src/Wallabag/ImportBundle/Tests
parent0aa344dc247c77376fcbf2112191f9f8b3dfc846 (diff)
downloadwallabag-7ec2897ee0ad190dcb9f77032d785f2f9661b754.tar.gz
wallabag-7ec2897ee0ad190dcb9f77032d785f2f9661b754.tar.zst
wallabag-7ec2897ee0ad190dcb9f77032d785f2f9661b754.zip
First test on PocketImport
Giving ability to define the Client add abitliy to easliy test the import.
Diffstat (limited to 'src/Wallabag/ImportBundle/Tests')
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
new file mode 100644
index 00000000..4c718fa3
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php
@@ -0,0 +1,117 @@
1<?php
2
3namespace Wallabag\ImportBundle\Tests\Import;
4
5use Wallabag\UserBundle\Entity\User;
6use Wallabag\ImportBundle\Import\PocketImport;
7use Symfony\Component\HttpFoundation\Session\Session;
8use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
9use GuzzleHttp\Client;
10use GuzzleHttp\Subscriber\Mock;
11use GuzzleHttp\Message\Response;
12use GuzzleHttp\Stream\Stream;
13
14class PocketImportTest extends \PHPUnit_Framework_TestCase
15{
16 protected $token;
17 protected $user;
18 protected $session;
19 protected $em;
20
21 private function getPocketImport($consumerKey = 'ConsumerKey')
22 {
23 $this->user = new User();
24
25 $this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $token->expects($this->once())
34 ->method('getUser')
35 ->willReturn($this->user);
36
37 $this->tokenStorage->expects($this->once())
38 ->method('getToken')
39 ->willReturn($token);
40
41 $this->session = new Session(new MockArraySessionStorage());
42
43 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
44 ->disableOriginalConstructor()
45 ->getMock();
46
47 return new PocketImport(
48 $this->tokenStorage,
49 $this->session,
50 $this->em,
51 $consumerKey
52 );
53 }
54
55 public function testInit()
56 {
57 $pocketImport = $this->getPocketImport();
58
59 $this->assertEquals('Pocket', $pocketImport->getName());
60 $this->assertEquals('This importer will import all your <a href="https://getpocket.com">Pocket</a> data.', $pocketImport->getDescription());
61 }
62
63 public function testOAuthRequest()
64 {
65 $client = new Client();
66
67 $mock = new Mock([
68 new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['code' => 'wunderbar']))),
69 ]);
70
71 $client->getEmitter()->attach($mock);
72
73 $pocketImport = $this->getPocketImport();
74 $pocketImport->setClient($client);
75
76 $url = $pocketImport->oAuthRequest('http://0.0.0.0./redirect', 'http://0.0.0.0./callback');
77
78 $this->assertEquals('https://getpocket.com/auth/authorize?request_token=wunderbar&redirect_uri=http://0.0.0.0./callback', $url);
79 $this->assertEquals('wunderbar', $this->session->get('pocketCode'));
80 }
81
82 public function testOAuthAuthorize()
83 {
84 $client = new Client();
85
86 $mock = new Mock([
87 new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar']))),
88 ]);
89
90 $client->getEmitter()->attach($mock);
91
92 $pocketImport = $this->getPocketImport();
93 $pocketImport->setClient($client);
94
95 $accessToken = $pocketImport->oAuthAuthorize();
96
97 $this->assertEquals('wunderbar', $accessToken);
98 }
99
100 public function testImport()
101 {
102 $client = new Client();
103
104 $mock = new Mock([
105 new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['list' => []]))),
106 ]);
107
108 $client->getEmitter()->attach($mock);
109
110 $pocketImport = $this->getPocketImport();
111 $pocketImport->setClient($client);
112
113 $pocketImport->import('wunderbar');
114
115 $this->assertEquals('0 entries imported, 0 already saved.', $this->session->getFlashBag()->get('notice')[0]);
116 }
117}