diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-07-12 13:51:05 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-25 12:28:54 +0200 |
commit | ae669126e718ede5dbf76929215d8514cd960976 (patch) | |
tree | f7da9fa833014eaec0cc2cfade514df2cc117188 /tests | |
parent | 9d7dd6b0d2480d3efff5b0ab1461f2ef99bfd57a (diff) | |
download | wallabag-ae669126e718ede5dbf76929215d8514cd960976.tar.gz wallabag-ae669126e718ede5dbf76929215d8514cd960976.tar.zst wallabag-ae669126e718ede5dbf76929215d8514cd960976.zip |
Import Firefox & Chrome bookmarks into wallabag
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php | 94 | ||||
-rw-r--r-- | tests/Wallabag/ImportBundle/fixtures/Bookmarks | 61 |
2 files changed, 155 insertions, 0 deletions
diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php new file mode 100644 index 00000000..8016227c --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php | |||
@@ -0,0 +1,94 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ImportBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
7 | |||
8 | class BrowserControllerTest extends WallabagCoreTestCase | ||
9 | { | ||
10 | public function testImportWallabag() | ||
11 | { | ||
12 | $this->logInAs('admin'); | ||
13 | $client = $this->getClient(); | ||
14 | |||
15 | $crawler = $client->request('GET', '/import/browser'); | ||
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/browser'); | ||
28 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
29 | |||
30 | $file = new UploadedFile(__DIR__.'/../fixtures/Bookmarks', 'Bookmarks'); | ||
31 | |||
32 | $data = [ | ||
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, $body = $crawler->filter('body')->extract(['_text'])); | ||
43 | $this->assertContains('flashes.import.notice.summary', $body[0]); | ||
44 | |||
45 | $content = $client->getContainer() | ||
46 | ->get('doctrine.orm.entity_manager') | ||
47 | ->getRepository('WallabagCoreBundle:Entry') | ||
48 | ->findByUrlAndUserId( | ||
49 | 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', | ||
50 | $this->getLoggedInUserId() | ||
51 | ); | ||
52 | |||
53 | $this->assertNotEmpty($content->getMimetype()); | ||
54 | $this->assertNotEmpty($content->getPreviewPicture()); | ||
55 | $this->assertNotEmpty($content->getLanguage()); | ||
56 | $this->assertEquals(0, count($content->getTags())); | ||
57 | |||
58 | $content = $client->getContainer() | ||
59 | ->get('doctrine.orm.entity_manager') | ||
60 | ->getRepository('WallabagCoreBundle:Entry') | ||
61 | ->findByUrlAndUserId( | ||
62 | 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', | ||
63 | $this->getLoggedInUserId() | ||
64 | ); | ||
65 | |||
66 | $this->assertNotEmpty($content->getMimetype()); | ||
67 | $this->assertNotEmpty($content->getPreviewPicture()); | ||
68 | $this->assertEmpty($content->getLanguage()); | ||
69 | } | ||
70 | |||
71 | public function testImportWallabagWithEmptyFile() | ||
72 | { | ||
73 | $this->logInAs('admin'); | ||
74 | $client = $this->getClient(); | ||
75 | |||
76 | $crawler = $client->request('GET', '/import/browser'); | ||
77 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
78 | |||
79 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | ||
80 | |||
81 | $data = [ | ||
82 | 'upload_import_file[file]' => $file, | ||
83 | ]; | ||
84 | |||
85 | $client->submit($form, $data); | ||
86 | |||
87 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
88 | |||
89 | $crawler = $client->followRedirect(); | ||
90 | |||
91 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
92 | $this->assertContains('flashes.import.notice.failed', $body[0]); | ||
93 | } | ||
94 | } | ||
diff --git a/tests/Wallabag/ImportBundle/fixtures/Bookmarks b/tests/Wallabag/ImportBundle/fixtures/Bookmarks new file mode 100644 index 00000000..8b78b8a4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/Bookmarks | |||
@@ -0,0 +1,61 @@ | |||
1 | { | ||
2 | "checksum": "ef1e30cddf64cb94c63d7835640165be", | ||
3 | "roots": { | ||
4 | "bookmark_bar": { | ||
5 | "children": [ { | ||
6 | "date_added": "13112787540531997", | ||
7 | "id": "7", | ||
8 | "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", | ||
9 | "type": "url", | ||
10 | "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" | ||
11 | } ], | ||
12 | "date_added": "13112787380480144", | ||
13 | "date_modified": "13112787542724942", | ||
14 | "id": "1", | ||
15 | "name": "Bookmarks bar", | ||
16 | "type": "folder" | ||
17 | }, | ||
18 | "other": { | ||
19 | "children": [ { | ||
20 | "date_added": "13112787503900822", | ||
21 | "id": "6", | ||
22 | "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", | ||
23 | "type": "url", | ||
24 | "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" | ||
25 | }, { | ||
26 | "children": [ { | ||
27 | "date_added": "13112787564443378", | ||
28 | "id": "9", | ||
29 | "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", | ||
30 | "type": "url", | ||
31 | "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" | ||
32 | } ], | ||
33 | "date_added": "13112787556763735", | ||
34 | "date_modified": "13112794390493325", | ||
35 | "id": "8", | ||
36 | "name": "test", | ||
37 | "type": "folder" | ||
38 | }, { | ||
39 | "date_added": "13112794390493325", | ||
40 | "id": "12", | ||
41 | "name": "JSON Formatter & Validator", | ||
42 | "type": "url", | ||
43 | "url": "https://jsonformatter.curiousconcept.com/" | ||
44 | } ], | ||
45 | "date_added": "13112787380480151", | ||
46 | "date_modified": "13112794393509988", | ||
47 | "id": "2", | ||
48 | "name": "Other bookmarks", | ||
49 | "type": "folder" | ||
50 | }, | ||
51 | "synced": { | ||
52 | "children": [ ], | ||
53 | "date_added": "13112787380480155", | ||
54 | "date_modified": "0", | ||
55 | "id": "3", | ||
56 | "name": "Mobile bookmarks", | ||
57 | "type": "folder" | ||
58 | } | ||
59 | }, | ||
60 | "version": 1 | ||
61 | } | ||