aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php4
-rw-r--r--src/Wallabag/ImportBundle/Import/ChromeImport.php40
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/redis.yml4
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php1
-rw-r--r--tests/Wallabag/ImportBundle/Import/ChromeImportTest.php30
-rw-r--r--tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php24
6 files changed, 51 insertions, 52 deletions
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index 3e1cb12b..198e148e 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -31,13 +31,13 @@ abstract class BrowserImport extends AbstractImport
31 public function import() 31 public function import()
32 { 32 {
33 if (!$this->user) { 33 if (!$this->user) {
34 $this->logger->error('WallabagImport: user is not defined'); 34 $this->logger->error('Wallabag Browser Import: user is not defined');
35 35
36 return false; 36 return false;
37 } 37 }
38 38
39 if (!file_exists($this->filepath) || !is_readable($this->filepath)) { 39 if (!file_exists($this->filepath) || !is_readable($this->filepath)) {
40 $this->logger->error('WallabagImport: unable to read file', ['filepath' => $this->filepath]); 40 $this->logger->error('Wallabag Browser Import: unable to read file', ['filepath' => $this->filepath]);
41 41
42 return false; 42 return false;
43 } 43 }
diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php
index 941d68d3..1af7cc87 100644
--- a/src/Wallabag/ImportBundle/Import/ChromeImport.php
+++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php
@@ -30,26 +30,26 @@ class ChromeImport extends BrowserImport
30 return 'import.chrome.description'; 30 return 'import.chrome.description';
31 } 31 }
32 32
33 /** 33 /**
34 * {@inheritdoc} 34 * {@inheritdoc}
35 */ 35 */
36 protected function prepareEntry($entry = []) 36 protected function prepareEntry($entry = [])
37 { 37 {
38 $data = [ 38 $data = [
39 'title' => $entry['name'], 39 'title' => $entry['name'],
40 'html' => '', 40 'html' => '',
41 'url' => $entry['url'], 41 'url' => $entry['url'],
42 'is_archived' => $this->markAsRead, 42 'is_archived' => $this->markAsRead,
43 'tags' => '', 43 'tags' => '',
44 'created_at' => $entry['date_added'], 44 'created_at' => $entry['date_added'],
45 ]; 45 ];
46 46
47 if (array_key_exists('tags', $entry) && $entry['tags'] != '') { 47 if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
48 $data['tags'] = $entry['tags']; 48 $data['tags'] = $entry['tags'];
49 } 49 }
50 50
51 return $data; 51 return $data;
52 } 52 }
53 53
54 /** 54 /**
55 * {@inheritdoc} 55 * {@inheritdoc}
diff --git a/src/Wallabag/ImportBundle/Resources/config/redis.yml b/src/Wallabag/ImportBundle/Resources/config/redis.yml
index c47778b8..c9c2cf26 100644
--- a/src/Wallabag/ImportBundle/Resources/config/redis.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/redis.yml
@@ -107,12 +107,12 @@ services:
107 - "@wallabag_core.redis.client" 107 - "@wallabag_core.redis.client"
108 - "wallabag.import.chrome" 108 - "wallabag.import.chrome"
109 109
110 wallabag_import.producer.redis.firefox: 110 wallabag_import.producer.redis.chrome:
111 class: Wallabag\ImportBundle\Redis\Producer 111 class: Wallabag\ImportBundle\Redis\Producer
112 arguments: 112 arguments:
113 - "@wallabag_import.queue.redis.chrome" 113 - "@wallabag_import.queue.redis.chrome"
114 114
115 wallabag_import.consumer.redis.firefox: 115 wallabag_import.consumer.redis.chrome:
116 class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer 116 class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer
117 arguments: 117 arguments:
118 - "@doctrine.orm.entity_manager" 118 - "@doctrine.orm.entity_manager"
diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
index 448e559f..8890c5b1 100644
--- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
@@ -117,7 +117,6 @@ class ChromeControllerTest extends WallabagCoreTestCase
117 $this->getLoggedInUserId() 117 $this->getLoggedInUserId()
118 ); 118 );
119 119
120 $this->assertEmpty($content->getMimetype());
121 $this->assertNotEmpty($content->getPreviewPicture()); 120 $this->assertNotEmpty($content->getPreviewPicture());
122 $this->assertNotEmpty($content->getLanguage()); 121 $this->assertNotEmpty($content->getLanguage());
123 $this->assertEquals(0, count($content->getTags())); 122 $this->assertEquals(0, count($content->getTags()));
diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
index f781a4d2..1e52615c 100644
--- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
@@ -61,7 +61,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
61 ->disableOriginalConstructor() 61 ->disableOriginalConstructor()
62 ->getMock(); 62 ->getMock();
63 63
64 $entryRepo->expects($this->exactly(4)) 64 $entryRepo->expects($this->exactly(1))
65 ->method('findByUrlAndUserId') 65 ->method('findByUrlAndUserId')
66 ->willReturn(false); 66 ->willReturn(false);
67 67
@@ -75,26 +75,26 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
75 ->getMock(); 75 ->getMock();
76 76
77 $this->contentProxy 77 $this->contentProxy
78 ->expects($this->exactly(4)) 78 ->expects($this->exactly(1))
79 ->method('updateEntry') 79 ->method('updateEntry')
80 ->willReturn($entry); 80 ->willReturn($entry);
81 81
82 $res = $chromeImport->import(); 82 $res = $chromeImport->import();
83 83
84 $this->assertTrue($res); 84 $this->assertTrue($res);
85 $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary()); 85 $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
86 } 86 }
87 87
88 public function testImportAndMarkAllAsRead() 88 public function testImportAndMarkAllAsRead()
89 { 89 {
90 $chromeImport = $this->getChromeImport(); 90 $chromeImport = $this->getChromeImport();
91 $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); 91 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
92 92
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
94 ->disableOriginalConstructor() 94 ->disableOriginalConstructor()
95 ->getMock(); 95 ->getMock();
96 96
97 $entryRepo->expects($this->exactly(2)) 97 $entryRepo->expects($this->exactly(1))
98 ->method('findByUrlAndUserId') 98 ->method('findByUrlAndUserId')
99 ->will($this->onConsecutiveCalls(false, true)); 99 ->will($this->onConsecutiveCalls(false, true));
100 100
@@ -120,13 +120,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
120 120
121 $this->assertTrue($res); 121 $this->assertTrue($res);
122 122
123 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); 123 $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
124 } 124 }
125 125
126 public function testImportWithRabbit() 126 public function testImportWithRabbit()
127 { 127 {
128 $chromeImport = $this->getChromeImport(); 128 $chromeImport = $this->getChromeImport();
129 $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 129 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
130 130
131 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 131 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
132 ->disableOriginalConstructor() 132 ->disableOriginalConstructor()
@@ -152,20 +152,20 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
152 ->getMock(); 152 ->getMock();
153 153
154 $producer 154 $producer
155 ->expects($this->exactly(4)) 155 ->expects($this->exactly(1))
156 ->method('publish'); 156 ->method('publish');
157 157
158 $chromeImport->setProducer($producer); 158 $chromeImport->setProducer($producer);
159 159
160 $res = $readabilityImport->setMarkAsRead(true)->import(); 160 $res = $chromeImport->setMarkAsRead(true)->import();
161 161
162 $this->assertTrue($res); 162 $this->assertTrue($res);
163 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); 163 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary());
164 } 164 }
165 165
166 public function testImportWithRedis() 166 public function testImportWithRedis()
167 { 167 {
168 $chromeImport = $this->getReadabilityImport(); 168 $chromeImport = $this->getChromeImport();
169 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 169 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
170 170
171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -198,7 +198,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
198 $res = $chromeImport->setMarkAsRead(true)->import(); 198 $res = $chromeImport->setMarkAsRead(true)->import();
199 199
200 $this->assertTrue($res); 200 $this->assertTrue($res);
201 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); 201 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary());
202 202
203 $this->assertNotEmpty($redisMock->lpop('chrome')); 203 $this->assertNotEmpty($redisMock->lpop('chrome'));
204 } 204 }
@@ -213,21 +213,21 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
213 $this->assertFalse($res); 213 $this->assertFalse($res);
214 214
215 $records = $this->logHandler->getRecords(); 215 $records = $this->logHandler->getRecords();
216 $this->assertContains('ChromeImport: unable to read file', $records[0]['message']); 216 $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']);
217 $this->assertEquals('ERROR', $records[0]['level_name']); 217 $this->assertEquals('ERROR', $records[0]['level_name']);
218 } 218 }
219 219
220 public function testImportUserNotDefined() 220 public function testImportUserNotDefined()
221 { 221 {
222 $chromeImport = $this->getChromeImport(true); 222 $chromeImport = $this->getChromeImport(true);
223 $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 223 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
224 224
225 $res = $chromeImport->import(); 225 $res = $chromeImport->import();
226 226
227 $this->assertFalse($res); 227 $this->assertFalse($res);
228 228
229 $records = $this->logHandler->getRecords(); 229 $records = $this->logHandler->getRecords();
230 $this->assertContains('ChromeImport: user is not defined', $records[0]['message']); 230 $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']);
231 $this->assertEquals('ERROR', $records[0]['level_name']); 231 $this->assertEquals('ERROR', $records[0]['level_name']);
232 } 232 }
233} 233}
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
index 0b4a28b4..e8f0f3c7 100644
--- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
@@ -88,13 +88,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
88 public function testImportAndMarkAllAsRead() 88 public function testImportAndMarkAllAsRead()
89 { 89 {
90 $firefoxImport = $this->getFirefoxImport(); 90 $firefoxImport = $this->getFirefoxImport();
91 $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); 91 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
92 92
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
94 ->disableOriginalConstructor() 94 ->disableOriginalConstructor()
95 ->getMock(); 95 ->getMock();
96 96
97 $entryRepo->expects($this->exactly(2)) 97 $entryRepo->expects($this->exactly(4))
98 ->method('findByUrlAndUserId') 98 ->method('findByUrlAndUserId')
99 ->will($this->onConsecutiveCalls(false, true)); 99 ->will($this->onConsecutiveCalls(false, true));
100 100
@@ -120,13 +120,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
120 120
121 $this->assertTrue($res); 121 $this->assertTrue($res);
122 122
123 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); 123 $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary());
124 } 124 }
125 125
126 public function testImportWithRabbit() 126 public function testImportWithRabbit()
127 { 127 {
128 $firefoxImport = $this->getFirefoxImport(); 128 $firefoxImport = $this->getFirefoxImport();
129 $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 129 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
130 130
131 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 131 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
132 ->disableOriginalConstructor() 132 ->disableOriginalConstructor()
@@ -152,20 +152,20 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
152 ->getMock(); 152 ->getMock();
153 153
154 $producer 154 $producer
155 ->expects($this->exactly(4)) 155 ->expects($this->exactly(1))
156 ->method('publish'); 156 ->method('publish');
157 157
158 $firefoxImport->setProducer($producer); 158 $firefoxImport->setProducer($producer);
159 159
160 $res = $readabilityImport->setMarkAsRead(true)->import(); 160 $res = $firefoxImport->setMarkAsRead(true)->import();
161 161
162 $this->assertTrue($res); 162 $this->assertTrue($res);
163 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); 163 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary());
164 } 164 }
165 165
166 public function testImportWithRedis() 166 public function testImportWithRedis()
167 { 167 {
168 $firefoxImport = $this->getReadabilityImport(); 168 $firefoxImport = $this->getFirefoxImport();
169 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 169 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
170 170
171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -198,7 +198,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
198 $res = $firefoxImport->setMarkAsRead(true)->import(); 198 $res = $firefoxImport->setMarkAsRead(true)->import();
199 199
200 $this->assertTrue($res); 200 $this->assertTrue($res);
201 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); 201 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary());
202 202
203 $this->assertNotEmpty($redisMock->lpop('firefox')); 203 $this->assertNotEmpty($redisMock->lpop('firefox'));
204 } 204 }
@@ -213,21 +213,21 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
213 $this->assertFalse($res); 213 $this->assertFalse($res);
214 214
215 $records = $this->logHandler->getRecords(); 215 $records = $this->logHandler->getRecords();
216 $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']); 216 $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']);
217 $this->assertEquals('ERROR', $records[0]['level_name']); 217 $this->assertEquals('ERROR', $records[0]['level_name']);
218 } 218 }
219 219
220 public function testImportUserNotDefined() 220 public function testImportUserNotDefined()
221 { 221 {
222 $firefoxImport = $this->getFirefoxImport(true); 222 $firefoxImport = $this->getFirefoxImport(true);
223 $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 223 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
224 224
225 $res = $firefoxImport->import(); 225 $res = $firefoxImport->import();
226 226
227 $this->assertFalse($res); 227 $this->assertFalse($res);
228 228
229 $records = $this->logHandler->getRecords(); 229 $records = $this->logHandler->getRecords();
230 $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']); 230 $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']);
231 $this->assertEquals('ERROR', $records[0]['level_name']); 231 $this->assertEquals('ERROR', $records[0]['level_name']);
232 } 232 }
233} 233}