]>
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 | { | |
0e0102b6 | 37 | $this->checkRedis(); |
b3437d58 JB |
38 | $this->logInAs('admin'); |
39 | $client = $this->getClient(); | |
40 | ||
41 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); | |
42 | ||
43 | $crawler = $client->request('GET', '/import/pocket'); | |
44 | ||
45 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
46 | $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); | |
47 | ||
48 | $client->getContainer()->get('craue_config')->set('import_with_redis', 0); | |
13470c35 JB |
49 | } |
50 | ||
4d0ec0e7 JB |
51 | public function testImportPocketAuthBadToken() |
52 | { | |
53 | $this->logInAs('admin'); | |
54 | $client = $this->getClient(); | |
55 | ||
fdc90ceb | 56 | $client->request('GET', '/import/pocket/auth'); |
4d0ec0e7 JB |
57 | |
58 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
59 | } | |
60 | ||
7019c7cf JB |
61 | public function testImportPocketAuth() |
62 | { | |
63 | $this->logInAs('admin'); | |
64 | $client = $this->getClient(); | |
65 | ||
4d0ec0e7 JB |
66 | $pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport') |
67 | ->disableOriginalConstructor() | |
68 | ->getMock(); | |
69 | ||
70 | $pocketImport | |
71 | ->expects($this->once()) | |
72 | ->method('getRequestToken') | |
73 | ->willReturn('token'); | |
74 | ||
fdc90ceb | 75 | static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport); |
4d0ec0e7 | 76 | |
fdc90ceb | 77 | $client->request('GET', '/import/pocket/auth'); |
7019c7cf JB |
78 | |
79 | $this->assertEquals(301, $client->getResponse()->getStatusCode()); | |
80 | $this->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location')); | |
81 | } | |
82 | ||
83 | public function testImportPocketCallbackWithBadToken() | |
84 | { | |
85 | $this->logInAs('admin'); | |
86 | $client = $this->getClient(); | |
87 | ||
fdc90ceb JB |
88 | $pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport') |
89 | ->disableOriginalConstructor() | |
90 | ->getMock(); | |
91 | ||
92 | $pocketImport | |
93 | ->expects($this->once()) | |
94 | ->method('authorize') | |
95 | ->willReturn(false); | |
96 | ||
97 | static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport); | |
98 | ||
99 | $client->request('GET', '/import/pocket/callback'); | |
7019c7cf JB |
100 | |
101 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
fdc90ceb | 102 | $this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage'); |
4204a06b | 103 | $this->assertEquals('flashes.import.notice.failed', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]); |
7019c7cf | 104 | } |
fdc90ceb JB |
105 | |
106 | public function testImportPocketCallback() | |
107 | { | |
108 | $this->logInAs('admin'); | |
109 | $client = $this->getClient(); | |
110 | ||
111 | $pocketImport = $this->getMockBuilder('Wallabag\ImportBundle\Import\PocketImport') | |
112 | ->disableOriginalConstructor() | |
113 | ->getMock(); | |
114 | ||
115 | $pocketImport | |
116 | ->expects($this->once()) | |
117 | ->method('authorize') | |
118 | ->willReturn(true); | |
119 | ||
120 | $pocketImport | |
121 | ->expects($this->once()) | |
122 | ->method('setMarkAsRead') | |
123 | ->with(false) | |
124 | ->willReturn($pocketImport); | |
125 | ||
126 | $pocketImport | |
127 | ->expects($this->once()) | |
128 | ->method('import') | |
129 | ->willReturn(true); | |
130 | ||
131 | static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport); | |
132 | ||
133 | $client->request('GET', '/import/pocket/callback'); | |
134 | ||
135 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
136 | $this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage'); | |
137 | $this->assertEquals('flashes.import.notice.summary', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]); | |
138 | } | |
7019c7cf | 139 | } |