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