From f7c55b38122cc593c2b58bb6425fca9d243b055e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 20 Sep 2016 16:45:13 +0200 Subject: [PATCH] Added tests for Chrome bookmarks import --- .../Command/ImportCommandTest.php | 1 - .../Controller/BrowserControllerTest.php | 41 ++++++++++++++++++- .../ImportBundle/fixtures/chrome-bookmarks | 36 ++++++++++++++++ ...{bookmarks.json => firefox-bookmarks.json} | 0 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks rename tests/Wallabag/ImportBundle/fixtures/{bookmarks.json => firefox-bookmarks.json} (100%) diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index eb7fce79..7be1eb18 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -6,7 +6,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Wallabag\ImportBundle\Command\ImportCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use M6Web\Component\RedisMock\RedisMockFactory; class ImportCommandTest extends WallabagCoreTestCase { diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php index 46c831f8..b686fcd9 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -19,7 +19,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } - public function testImportWallabagWithFile() + public function testImportWallabagWithFirefoxFile() { $this->logInAs('admin'); $client = $this->getClient(); @@ -27,7 +27,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/browser'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $file = new UploadedFile(__DIR__.'/../fixtures/bookmarks.json', 'Bookmarks'); + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); $data = [ 'upload_import_file[file]' => $file, @@ -68,6 +68,43 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEmpty($content->getLanguage()); } + public function testImportWallabagWithChromeFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + } + public function testImportWallabagWithEmptyFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks b/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks new file mode 100644 index 00000000..0478eb41 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks @@ -0,0 +1,36 @@ +{ + "checksum": "f3aa0e9c0edad632a246f7e98ec64918", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13118850929335823", + "id": "6", + "name": "\"La multiplication des chefs de projet est une catastrophe managériale majeure\", affirme le sociologue François Dupuy - Ressources humaines", + "type": "url", + "url": "http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730" + } ], + "date_added": "13118829474385693", + "date_modified": "13118850929335823", + "id": "1", + "name": "Barre de favoris", + "type": "folder" + }, + "other": { + "children": [ ], + "date_added": "13118829474385701", + "date_modified": "0", + "id": "2", + "name": "Autres favoris", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13118829474385702", + "date_modified": "0", + "id": "3", + "name": "Favoris sur mobile", + "type": "folder" + } + }, + "version": 1 +} diff --git a/tests/Wallabag/ImportBundle/fixtures/bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json similarity index 100% rename from tests/Wallabag/ImportBundle/fixtures/bookmarks.json rename to tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json -- 2.41.0