]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php
Fixed tests
[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->assertSame(200, $client->getResponse()->getStatusCode());
17 $this->assertSame(1, $crawler->filter('button[name=action]')->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->assertSame(200, $client->getResponse()->getStatusCode());
30 $this->assertSame(1, $crawler->filter('button[name=action]')->count());
31
32 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
33 }
34
35 public function testImportPocketWithRedisEnabled()
36 {
37 $this->checkRedis();
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->assertSame(200, $client->getResponse()->getStatusCode());
46 $this->assertSame(1, $crawler->filter('button[name=action]')->count());
47
48 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
49 }
50
51 public function testImportPocketAuthBadToken()
52 {
53 $this->logInAs('admin');
54 $client = $this->getClient();
55
56 $client->request('GET', '/import/pocket/auth');
57
58 $this->assertSame(302, $client->getResponse()->getStatusCode());
59 }
60
61 public function testImportPocketAuth()
62 {
63 $this->logInAs('admin');
64 $client = $this->getClient();
65
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
75 static::$kernel->getContainer()->set('wallabag_import.pocket.import', $pocketImport);
76
77 $client->request('GET', '/import/pocket/auth');
78
79 $this->assertSame(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
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');
100
101 $this->assertSame(302, $client->getResponse()->getStatusCode());
102 $this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage');
103 $this->assertSame('flashes.import.notice.failed', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
104 }
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->assertSame(302, $client->getResponse()->getStatusCode());
136 $this->assertContains('/', $client->getResponse()->headers->get('location'), 'Import is ok, redirect to homepage');
137 $this->assertSame('flashes.import.notice.summary', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]);
138 }
139 }