]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added tests for Chrome bookmarks import
authorNicolas Lœuillet <nicolas@loeuillet.org>
Tue, 20 Sep 2016 14:45:13 +0000 (16:45 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 25 Sep 2016 10:29:18 +0000 (12:29 +0200)
tests/Wallabag/ImportBundle/Command/ImportCommandTest.php
tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php
tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks [new file with mode: 0644]
tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json [moved from tests/Wallabag/ImportBundle/fixtures/bookmarks.json with 100% similarity]

index eb7fce79f117cf57eb6485b5ee2915780f4dbb7d..7be1eb18f6f4a0e682966b0ac1f3639d04b859ee 100644 (file)
@@ -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
 {
index 46c831f8f2edcd6f0a8617986a56a07388db6b94..b686fcd90907e2491536b4a2a0200c5b73d79352 100644 (file)
@@ -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 (file)
index 0000000..0478eb4
--- /dev/null
@@ -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
+}