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 | |
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')
9 files changed, 212 insertions, 2 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 | } | ||
diff --git a/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php b/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php new file mode 100644 index 00000000..702d2a9b --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/Import/ImportChainTest.php | |||
@@ -0,0 +1,21 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Tests\Import; | ||
4 | |||
5 | use Wallabag\ImportBundle\Import\ImportChain; | ||
6 | |||
7 | class ImportChainTest extends \PHPUnit_Framework_TestCase | ||
8 | { | ||
9 | public function testGetAll() | ||
10 | { | ||
11 | $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\ImportInterface') | ||
12 | ->disableOriginalConstructor() | ||
13 | ->getMock(); | ||
14 | |||
15 | $importChain = new ImportChain(); | ||
16 | $importChain->addImport($import, 'alias'); | ||
17 | |||
18 | $this->assertCount(1, $importChain->getAll()); | ||
19 | $this->assertEquals($import, $importChain->getAll()['alias']); | ||
20 | } | ||
21 | } | ||
diff --git a/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php b/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php new file mode 100644 index 00000000..bd62ab3b --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/Import/ImportCompilerPassTest.php | |||
@@ -0,0 +1,47 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Tests\Import; | ||
4 | |||
5 | use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
6 | use Wallabag\ImportBundle\Import\ImportCompilerPass; | ||
7 | |||
8 | class ImportCompilerPassTest extends \PHPUnit_Framework_TestCase | ||
9 | { | ||
10 | public function testProcessNoDefinition() | ||
11 | { | ||
12 | $container = new ContainerBuilder(); | ||
13 | $res = $this->process($container); | ||
14 | |||
15 | $this->assertNull($res); | ||
16 | } | ||
17 | |||
18 | public function testProcess() | ||
19 | { | ||
20 | $container = new ContainerBuilder(); | ||
21 | $container | ||
22 | ->register('wallabag_import.chain') | ||
23 | ->setPublic(false) | ||
24 | ; | ||
25 | |||
26 | $container | ||
27 | ->register('foo') | ||
28 | ->addTag('wallabag_import.import', array('alias' => 'pocket')) | ||
29 | ; | ||
30 | |||
31 | $this->process($container); | ||
32 | |||
33 | $this->assertTrue($container->hasDefinition('wallabag_import.chain')); | ||
34 | |||
35 | $definition = $container->getDefinition('wallabag_import.chain'); | ||
36 | $this->assertTrue($definition->hasMethodCall('addImport')); | ||
37 | |||
38 | $calls = $definition->getMethodCalls(); | ||
39 | $this->assertEquals('pocket', $calls[0][1][1]); | ||
40 | } | ||
41 | |||
42 | protected function process(ContainerBuilder $container) | ||
43 | { | ||
44 | $repeatedPass = new ImportCompilerPass(); | ||
45 | $repeatedPass->process($container); | ||
46 | } | ||
47 | } | ||
diff --git a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php index cf706fa9..6ee70db0 100644 --- a/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php +++ b/src/Wallabag/ImportBundle/Tests/Import/PocketImportTest.php | |||
@@ -74,7 +74,8 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
74 | $pocketImport = $this->getPocketImport(); | 74 | $pocketImport = $this->getPocketImport(); |
75 | 75 | ||
76 | $this->assertEquals('Pocket', $pocketImport->getName()); | 76 | $this->assertEquals('Pocket', $pocketImport->getName()); |
77 | $this->assertEquals('This importer will import all your <a href="https://getpocket.com">Pocket</a> data.', $pocketImport->getDescription()); | 77 | $this->assertNotEmpty($pocketImport->getUrl()); |
78 | $this->assertContains('This importer will import all your <a href="https://getpocket.com">Pocket</a> data.', $pocketImport->getDescription()); | ||
78 | } | 79 | } |
79 | 80 | ||
80 | public function testOAuthRequest() | 81 | public function testOAuthRequest() |
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php index fc66d402..8a8eb3fa 100644 --- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php +++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php | |||
@@ -39,7 +39,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase | |||
39 | $wallabagV1Import = $this->getWallabagV1Import(); | 39 | $wallabagV1Import = $this->getWallabagV1Import(); |
40 | 40 | ||
41 | $this->assertEquals('Wallabag v1', $wallabagV1Import->getName()); | 41 | $this->assertEquals('Wallabag v1', $wallabagV1Import->getName()); |
42 | $this->assertEquals('This importer will import all your wallabag v1 articles.', $wallabagV1Import->getDescription()); | 42 | $this->assertNotEmpty($wallabagV1Import->getUrl()); |
43 | $this->assertContains('This importer will import all your wallabag v1 articles.', $wallabagV1Import->getDescription()); | ||
43 | } | 44 | } |
44 | 45 | ||
45 | public function testImport() | 46 | public function testImport() |
diff --git a/src/Wallabag/ImportBundle/Tests/fixtures/test.html b/src/Wallabag/ImportBundle/Tests/fixtures/test.html new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/fixtures/test.html | |||
diff --git a/src/Wallabag/ImportBundle/Tests/fixtures/test.txt b/src/Wallabag/ImportBundle/Tests/fixtures/test.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/Wallabag/ImportBundle/Tests/fixtures/test.txt | |||