diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-12-31 11:24:46 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-01-02 23:27:41 +0100 |
commit | 7019c7cf6c6af39c0f458769e20c3f9306477943 (patch) | |
tree | 12acceaa458cdf6d24367eba85f690265acddcdb /src/Wallabag/ImportBundle/Tests/Controller | |
parent | b1d05721cf37ab94ec1a6837fe79cf19474dd0ff (diff) | |
download | wallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.tar.gz wallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.tar.zst wallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.zip |
Add tagged services for import
- list services in /import
- add url to import service
- ImportBundle routing are now prefixed by /import
- optimize flush in each import (flushing each 20 contents)
- improve design of each import
- add more tests
Diffstat (limited to 'src/Wallabag/ImportBundle/Tests/Controller')
3 files changed, 140 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Tests/Controller/ImportControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/ImportControllerTest.php new file mode 100644 index 00000000..30009af4 --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/Controller/ImportControllerTest.php | |||
@@ -0,0 +1,29 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Tests\Controller; | ||
4 | |||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | ||
6 | |||
7 | class ImportControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function testLogin() | ||
10 | { | ||
11 | $client = $this->getClient(); | ||
12 | |||
13 | $client->request('GET', '/import/'); | ||
14 | |||
15 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
16 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | ||
17 | } | ||
18 | |||
19 | public function testImportList() | ||
20 | { | ||
21 | $this->logInAs('admin'); | ||
22 | $client = $this->getClient(); | ||
23 | |||
24 | $crawler = $client->request('GET', '/import/'); | ||
25 | |||
26 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
27 | $this->assertEquals(2, $crawler->filter('blockquote')->count()); | ||
28 | } | ||
29 | } | ||
diff --git a/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php new file mode 100644 index 00000000..c2acd68c --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php | |||
@@ -0,0 +1,42 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Tests\Controller; | ||
4 | |||
5 | use Wallabag\CoreBundle\Tests\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 testImportPocketAuth() | ||
21 | { | ||
22 | $this->logInAs('admin'); | ||
23 | $client = $this->getClient(); | ||
24 | |||
25 | $crawler = $client->request('GET', '/import/pocket/auth'); | ||
26 | |||
27 | $this->assertEquals(301, $client->getResponse()->getStatusCode()); | ||
28 | $this->assertContains('getpocket.com/auth/authorize', $client->getResponse()->headers->get('location')); | ||
29 | } | ||
30 | |||
31 | public function testImportPocketCallbackWithBadToken() | ||
32 | { | ||
33 | $this->logInAs('admin'); | ||
34 | $client = $this->getClient(); | ||
35 | |||
36 | $crawler = $client->request('GET', '/import/pocket/callback'); | ||
37 | |||
38 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
39 | $this->assertContains('import/pocket', $client->getResponse()->headers->get('location')); | ||
40 | $this->assertEquals('Import failed, please try again.', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]); | ||
41 | } | ||
42 | } | ||
diff --git a/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php new file mode 100644 index 00000000..e12ea429 --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php | |||
@@ -0,0 +1,69 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Tests\Controller; | ||
4 | |||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | ||
6 | use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
7 | |||
8 | class WallabagV1ControllerTest extends WallabagCoreTestCase | ||
9 | { | ||
10 | public function testImportWallabag() | ||
11 | { | ||
12 | $this->logInAs('admin'); | ||
13 | $client = $this->getClient(); | ||
14 | |||
15 | $crawler = $client->request('GET', '/import/wallabag-v1'); | ||
16 | |||
17 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
18 | $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | ||
19 | $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); | ||
20 | } | ||
21 | |||
22 | public function testImportWallabagWithFile() | ||
23 | { | ||
24 | $this->logInAs('admin'); | ||
25 | $client = $this->getClient(); | ||
26 | |||
27 | $crawler = $client->request('GET', '/import/wallabag-v1'); | ||
28 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
29 | |||
30 | $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json'); | ||
31 | |||
32 | $data = array( | ||
33 | 'upload_import_file[file]' => $file, | ||
34 | ); | ||
35 | |||
36 | $client->submit($form, $data); | ||
37 | |||
38 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
39 | |||
40 | $crawler = $client->followRedirect(); | ||
41 | |||
42 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); | ||
43 | $this->assertContains('Import summary', $alert[0]); | ||
44 | } | ||
45 | |||
46 | public function testImportWallabagWithEmptyFile() | ||
47 | { | ||
48 | $this->logInAs('admin'); | ||
49 | $client = $this->getClient(); | ||
50 | |||
51 | $crawler = $client->request('GET', '/import/wallabag-v1'); | ||
52 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
53 | |||
54 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | ||
55 | |||
56 | $data = array( | ||
57 | 'upload_import_file[file]' => $file, | ||
58 | ); | ||
59 | |||
60 | $client->submit($form, $data); | ||
61 | |||
62 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
63 | |||
64 | $crawler = $client->followRedirect(); | ||
65 | |||
66 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); | ||
67 | $this->assertContains('Import failed, please try again', $alert[0]); | ||
68 | } | ||
69 | } | ||