]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
fix tests
authorThomas Citharel <tcit@tcit.fr>
Wed, 21 Sep 2016 17:24:19 +0000 (19:24 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 25 Sep 2016 10:29:19 +0000 (12:29 +0200)
src/Wallabag/ImportBundle/Import/BrowserImport.php
src/Wallabag/ImportBundle/Import/ChromeImport.php
src/Wallabag/ImportBundle/Resources/config/redis.yml
tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php

index 3e1cb12b173bb578faad14e913eaf13449a687fc..198e148e4cfed4bc4bbd5375825dfd79ce8904a2 100644 (file)
@@ -31,13 +31,13 @@ abstract class BrowserImport extends AbstractImport
     public function import()
     {
         if (!$this->user) {
-            $this->logger->error('WallabagImport: user is not defined');
+            $this->logger->error('Wallabag Browser Import: user is not defined');
 
             return false;
         }
 
         if (!file_exists($this->filepath) || !is_readable($this->filepath)) {
-            $this->logger->error('WallabagImport: unable to read file', ['filepath' => $this->filepath]);
+            $this->logger->error('Wallabag Browser Import: unable to read file', ['filepath' => $this->filepath]);
 
             return false;
         }
index 941d68d38690bc7799211c3ea391c6cf720b3190..1af7cc87ba5b023fbb3e60976171f49394d5ed34 100644 (file)
@@ -30,26 +30,26 @@ class ChromeImport extends BrowserImport
         return 'import.chrome.description';
     }
 
-      /**
-       * {@inheritdoc}
-       */
-      protected function prepareEntry($entry = [])
-      {
-          $data = [
-              'title' => $entry['name'],
-              'html' => '',
-              'url' => $entry['url'],
-              'is_archived' => $this->markAsRead,
-              'tags' => '',
-              'created_at' => $entry['date_added'],
-          ];
-
-          if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
-              $data['tags'] = $entry['tags'];
-          }
-
-          return $data;
-      }
+    /**
+     * {@inheritdoc}
+     */
+    protected function prepareEntry($entry = [])
+    {
+        $data = [
+          'title' => $entry['name'],
+          'html' => '',
+          'url' => $entry['url'],
+          'is_archived' => $this->markAsRead,
+          'tags' => '',
+          'created_at' => $entry['date_added'],
+        ];
+
+        if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
+            $data['tags'] = $entry['tags'];
+        }
+
+        return $data;
+    }
 
     /**
      * {@inheritdoc}
index c47778b83bf49162ecb909671c46053615a2c789..c9c2cf26e1f76e2f887b6b0e9301ec82e9e757b2 100644 (file)
@@ -107,12 +107,12 @@ services:
             - "@wallabag_core.redis.client"
             - "wallabag.import.chrome"
 
-    wallabag_import.producer.redis.firefox:
+    wallabag_import.producer.redis.chrome:
         class: Wallabag\ImportBundle\Redis\Producer
         arguments:
             - "@wallabag_import.queue.redis.chrome"
 
-    wallabag_import.consumer.redis.firefox:
+    wallabag_import.consumer.redis.chrome:
         class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer
         arguments:
             - "@doctrine.orm.entity_manager"
index 448e559f019031a1a75404910660efff4d3bde78..8890c5b15e7fd419442b8eebfb02681df3dbce7f 100644 (file)
@@ -117,7 +117,6 @@ class ChromeControllerTest extends WallabagCoreTestCase
                 $this->getLoggedInUserId()
             );
 
-        $this->assertEmpty($content->getMimetype());
         $this->assertNotEmpty($content->getPreviewPicture());
         $this->assertNotEmpty($content->getLanguage());
         $this->assertEquals(0, count($content->getTags()));
index f781a4d2f6fa9640404064b175ead68db562b2a1..1e52615c0545d1f0739afb4660dce4cd164b323f 100644 (file)
@@ -61,7 +61,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
             ->disableOriginalConstructor()
             ->getMock();
 
-        $entryRepo->expects($this->exactly(4))
+        $entryRepo->expects($this->exactly(1))
             ->method('findByUrlAndUserId')
             ->willReturn(false);
 
@@ -75,26 +75,26 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
             ->getMock();
 
         $this->contentProxy
-            ->expects($this->exactly(4))
+            ->expects($this->exactly(1))
             ->method('updateEntry')
             ->willReturn($entry);
 
         $res = $chromeImport->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
     }
 
     public function testImportAndMarkAllAsRead()
     {
         $chromeImport = $this->getChromeImport();
-        $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
+        $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
             ->disableOriginalConstructor()
             ->getMock();
 
-        $entryRepo->expects($this->exactly(2))
+        $entryRepo->expects($this->exactly(1))
             ->method('findByUrlAndUserId')
             ->will($this->onConsecutiveCalls(false, true));
 
@@ -120,13 +120,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
 
         $this->assertTrue($res);
 
-        $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
     }
 
     public function testImportWithRabbit()
     {
         $chromeImport = $this->getChromeImport();
-        $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json');
+        $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
             ->disableOriginalConstructor()
@@ -152,20 +152,20 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
             ->getMock();
 
         $producer
-            ->expects($this->exactly(4))
+            ->expects($this->exactly(1))
             ->method('publish');
 
         $chromeImport->setProducer($producer);
 
-        $res = $readabilityImport->setMarkAsRead(true)->import();
+        $res = $chromeImport->setMarkAsRead(true)->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary());
     }
 
     public function testImportWithRedis()
     {
-        $chromeImport = $this->getReadabilityImport();
+        $chromeImport = $this->getChromeImport();
         $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -198,7 +198,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
         $res = $chromeImport->setMarkAsRead(true)->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary());
 
         $this->assertNotEmpty($redisMock->lpop('chrome'));
     }
@@ -213,21 +213,21 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
         $this->assertFalse($res);
 
         $records = $this->logHandler->getRecords();
-        $this->assertContains('ChromeImport: unable to read file', $records[0]['message']);
+        $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']);
         $this->assertEquals('ERROR', $records[0]['level_name']);
     }
 
     public function testImportUserNotDefined()
     {
         $chromeImport = $this->getChromeImport(true);
-        $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json');
+        $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
 
         $res = $chromeImport->import();
 
         $this->assertFalse($res);
 
         $records = $this->logHandler->getRecords();
-        $this->assertContains('ChromeImport: user is not defined', $records[0]['message']);
+        $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']);
         $this->assertEquals('ERROR', $records[0]['level_name']);
     }
 }
index 0b4a28b49d586b0ce95ef6254962b72e718ecc1e..e8f0f3c7931a94ca53c7327cf8dfa86048c0df75 100644 (file)
@@ -88,13 +88,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
     public function testImportAndMarkAllAsRead()
     {
         $firefoxImport = $this->getFirefoxImport();
-        $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
+        $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
             ->disableOriginalConstructor()
             ->getMock();
 
-        $entryRepo->expects($this->exactly(2))
+        $entryRepo->expects($this->exactly(4))
             ->method('findByUrlAndUserId')
             ->will($this->onConsecutiveCalls(false, true));
 
@@ -120,13 +120,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
 
         $this->assertTrue($res);
 
-        $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary());
+        $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary());
     }
 
     public function testImportWithRabbit()
     {
         $firefoxImport = $this->getFirefoxImport();
-        $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json');
+        $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
             ->disableOriginalConstructor()
@@ -152,20 +152,20 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
             ->getMock();
 
         $producer
-            ->expects($this->exactly(4))
+            ->expects($this->exactly(1))
             ->method('publish');
 
         $firefoxImport->setProducer($producer);
 
-        $res = $readabilityImport->setMarkAsRead(true)->import();
+        $res = $firefoxImport->setMarkAsRead(true)->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary());
     }
 
     public function testImportWithRedis()
     {
-        $firefoxImport = $this->getReadabilityImport();
+        $firefoxImport = $this->getFirefoxImport();
         $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -198,7 +198,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
         $res = $firefoxImport->setMarkAsRead(true)->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary());
 
         $this->assertNotEmpty($redisMock->lpop('firefox'));
     }
@@ -213,21 +213,21 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
         $this->assertFalse($res);
 
         $records = $this->logHandler->getRecords();
-        $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']);
+        $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']);
         $this->assertEquals('ERROR', $records[0]['level_name']);
     }
 
     public function testImportUserNotDefined()
     {
         $firefoxImport = $this->getFirefoxImport(true);
-        $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json');
+        $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
 
         $res = $firefoxImport->import();
 
         $this->assertFalse($res);
 
         $records = $this->logHandler->getRecords();
-        $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']);
+        $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']);
         $this->assertEquals('ERROR', $records[0]['level_name']);
     }
 }