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