]>
Commit | Line | Data |
---|---|---|
7019c7cf JB |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\ImportBundle\Controller; |
7019c7cf | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
7019c7cf JB |
6 | |
7 | class PocketControllerTest extends WallabagCoreTestCase | |
8 | { | |
9 | public function testImportPocket() | |
10 | { | |
11 | $this->logInAs('admin'); | |
12 | $client = $this->getClient(); | |
13 | ||
14 | $crawler = $client->request('GET', '/import/pocket'); | |
15 | ||
16 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
17 | $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); | |
18 | } | |
19 | ||
13470c35 JB |
20 | public function testImportPocketWithRabbitEnabled() |
21 | { | |
22 | $this->logInAs('admin'); | |
23 | $client = $this->getClient(); | |
24 | ||
b3437d58 | 25 | $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); |
13470c35 JB |
26 | |
27 | $crawler = $client->request('GET', '/import/pocket'); | |
28 | ||
29 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
30 | $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); | |
31 | ||
b3437d58 JB |
32 | $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); |
33 | } | |
34 | ||
35 | public function testImportPocketWithRedisEnabled() | |
36 | { | |
37 | $this->logInAs('admin'); | |
38 | $client = $this->getClient(); | |
39 | ||
40 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); | |
41 | ||
42 | $crawler = $client->request('GET', '/import/pocket'); | |
43 | ||
44 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
45 | $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); | |
46 | ||
47 | $client->getContainer()->get('craue_config')->set('import_with_redis', 0); | |
13470c35 JB |
48 | } |
49 | ||
4d0ec0e7 JB |
50 | public function testImportPocketAuthBadToken() |
51 | { | |
52 | $this->logInAs('admin'); | |
53 | $client = $this->getClient(); | |
54 | ||
fdc90ceb | 55 | $client->request('GET', '/import/pocket/auth'); |
4d0ec0e7 JB |
56 | |
57 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
58 | } | |
59 | ||
7019c7cf JB |
60 | public function testImportPocketAuth() |
61 | { | |
62 | $this->logInAs('admin'); | |
63 | $client = $this->getClient(); | |
64 | ||
4d0ec0e7 JB |
65 | $pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport') |
66 | ->disableOriginalConstructor() | |
67 | ->getMock(); | |
68 | ||
69 | $pocketImport | |
70 | ->expects($this->once()) | |
71 | ->method('getRequestToken') | |
72 | ->willReturn('token'); | |
73 | ||
fdc90ceb | 74 | static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport); |
4d0ec0e7 | 75 | |
fdc90ceb | 76 | $client->request('GET', '/import/pocket/auth'); |
7019c7cf JB |
77 | |
78 | $this->assertEquals(301, $client->getResponse()->getStatusCode()); | |
79 | $this->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location')); | |
80 | } | |
81 | ||
82 | public function testImportPocketCallbackWithBadToken() | |
83 | { | |
84 | $this->logInAs('admin'); | |
85 | $client = $this->getClient(); | |
86 | ||
fdc90ceb JB |
87 | $pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport') |
88 | ->disableOriginalConstructor() | |
89 | ->getMock(); | |
90 | ||
91 | $pocketImport | |
92 | ->expects($this->once()) | |
93 | ->method('authorize') | |
94 | ->willReturn(false); | |
95 | ||
96 | static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport); | |
97 | ||
98 | $client->request('GET', '/import/pocket/callback'); | |
7019c7cf JB |
99 | |
100 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
fdc90ceb | 101 | $this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage'); |
4204a06b | 102 | $this->assertEquals('flashes.import.notice.failed', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]); |
7019c7cf | 103 | } |
fdc90ceb JB |
104 | |
105 | public function testImportPocketCallback() | |
106 | { | |
107 | $this->logInAs('admin'); | |
108 | $client = $this->getClient(); | |
109 | ||
110 | $pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport') | |
111 | ->disableOriginalConstructor() | |
112 | ->getMock(); | |
113 | ||
114 | $pocketImport | |
115 | ->expects($this->once()) | |
116 | ->method('authorize') | |
117 | ->willReturn(true); | |
118 | ||
119 | $pocketImport | |
120 | ->expects($this->once()) | |
121 | ->method('setMarkAsRead') | |
122 | ->with(false) | |
123 | ->willReturn($pocketImport); | |
124 | ||
125 | $pocketImport | |
126 | ->expects($this->once()) | |
127 | ->method('import') | |
128 | ->willReturn(true); | |
129 | ||
130 | static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport); | |
131 | ||
132 | $client->request('GET', '/import/pocket/callback'); | |
133 | ||
134 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
135 | $this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage'); | |
136 | $this->assertEquals('flashes.import.notice.summary', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]); | |
137 | } | |
7019c7cf | 138 | } |