]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php
Merge pull request #2301 from wallabag/fix-rss-feeds
[github/wallabag/wallabag.git] / tests / Wallabag / ImportBundle / Controller / PocketControllerTest.php
1 <?php
2
3 namespace Tests\Wallabag\ImportBundle\Controller;
4
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
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
20 public function testImportPocketWithRabbitEnabled()
21 {
22 $this->logInAs('admin');
23 $client = $this->getClient();
24
25 $client->getContainer()->get('craue_config')->set('import_with_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('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);
48 }
49
50 public function testImportPocketAuthBadToken()
51 {
52 $this->logInAs('admin');
53 $client = $this->getClient();
54
55 $client->request('GET', '/import/pocket/auth');
56
57 $this->assertEquals(302, $client->getResponse()->getStatusCode());
58 }
59
60 public function testImportPocketAuth()
61 {
62 $this->logInAs('admin');
63 $client = $this->getClient();
64
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
74 static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
75
76 $client->request('GET', '/import/pocket/auth');
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
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');
99
100 $this->assertEquals(302, $client->getResponse()->getStatusCode());
101 $this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage');
102 $this->assertEquals('flashes.import.notice.failed', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
103 }
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 }
138 }