aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ImportBundle/Import
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import')
-rw-r--r--tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php35
-rw-r--r--tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php14
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php25
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php14
4 files changed, 56 insertions, 32 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
index 6777a02e..9158c8a2 100644
--- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
@@ -18,6 +18,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 protected $tagsAssigner; 20 protected $tagsAssigner;
21 protected $uow;
21 22
22 private function getInstapaperImport($unsetUser = false, $dispatched = 0) 23 private function getInstapaperImport($unsetUser = false, $dispatched = 0)
23 { 24 {
@@ -27,6 +28,20 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
27 ->disableOriginalConstructor() 28 ->disableOriginalConstructor()
28 ->getMock(); 29 ->getMock();
29 30
31 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
32 ->disableOriginalConstructor()
33 ->getMock();
34
35 $this->em
36 ->expects($this->any())
37 ->method('getUnitOfWork')
38 ->willReturn($this->uow);
39
40 $this->uow
41 ->expects($this->any())
42 ->method('getScheduledEntityInsertions')
43 ->willReturn([]);
44
30 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') 45 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
31 ->disableOriginalConstructor() 46 ->disableOriginalConstructor()
32 ->getMock(); 47 ->getMock();
@@ -67,14 +82,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
67 82
68 public function testImport() 83 public function testImport()
69 { 84 {
70 $instapaperImport = $this->getInstapaperImport(false, 3); 85 $instapaperImport = $this->getInstapaperImport(false, 4);
71 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 86 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
72 87
73 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 88 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
74 ->disableOriginalConstructor() 89 ->disableOriginalConstructor()
75 ->getMock(); 90 ->getMock();
76 91
77 $entryRepo->expects($this->exactly(3)) 92 $entryRepo->expects($this->exactly(4))
78 ->method('findByUrlAndUserId') 93 ->method('findByUrlAndUserId')
79 ->willReturn(false); 94 ->willReturn(false);
80 95
@@ -88,14 +103,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
88 ->getMock(); 103 ->getMock();
89 104
90 $this->contentProxy 105 $this->contentProxy
91 ->expects($this->exactly(3)) 106 ->expects($this->exactly(4))
92 ->method('updateEntry') 107 ->method('updateEntry')
93 ->willReturn($entry); 108 ->willReturn($entry);
94 109
95 $res = $instapaperImport->import(); 110 $res = $instapaperImport->import();
96 111
97 $this->assertTrue($res); 112 $this->assertTrue($res);
98 $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary()); 113 $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary());
99 } 114 }
100 115
101 public function testImportAndMarkAllAsRead() 116 public function testImportAndMarkAllAsRead()
@@ -107,9 +122,9 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
107 ->disableOriginalConstructor() 122 ->disableOriginalConstructor()
108 ->getMock(); 123 ->getMock();
109 124
110 $entryRepo->expects($this->exactly(3)) 125 $entryRepo->expects($this->exactly(4))
111 ->method('findByUrlAndUserId') 126 ->method('findByUrlAndUserId')
112 ->will($this->onConsecutiveCalls(false, true, true)); 127 ->will($this->onConsecutiveCalls(false, true, true, true));
113 128
114 $this->em 129 $this->em
115 ->expects($this->any()) 130 ->expects($this->any())
@@ -133,7 +148,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
133 148
134 $this->assertTrue($res); 149 $this->assertTrue($res);
135 150
136 $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); 151 $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary());
137 } 152 }
138 153
139 public function testImportWithRabbit() 154 public function testImportWithRabbit()
@@ -165,7 +180,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
165 ->getMock(); 180 ->getMock();
166 181
167 $producer 182 $producer
168 ->expects($this->exactly(3)) 183 ->expects($this->exactly(4))
169 ->method('publish'); 184 ->method('publish');
170 185
171 $instapaperImport->setProducer($producer); 186 $instapaperImport->setProducer($producer);
@@ -173,7 +188,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
173 $res = $instapaperImport->setMarkAsRead(true)->import(); 188 $res = $instapaperImport->setMarkAsRead(true)->import();
174 189
175 $this->assertTrue($res); 190 $this->assertTrue($res);
176 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); 191 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary());
177 } 192 }
178 193
179 public function testImportWithRedis() 194 public function testImportWithRedis()
@@ -211,7 +226,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
211 $res = $instapaperImport->setMarkAsRead(true)->import(); 226 $res = $instapaperImport->setMarkAsRead(true)->import();
212 227
213 $this->assertTrue($res); 228 $this->assertTrue($res);
214 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); 229 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary());
215 230
216 $this->assertNotEmpty($redisMock->lpop('instapaper')); 231 $this->assertNotEmpty($redisMock->lpop('instapaper'));
217 } 232 }
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
index 254f0a25..8f466d38 100644
--- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
@@ -67,14 +67,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
67 67
68 public function testImport() 68 public function testImport()
69 { 69 {
70 $readabilityImport = $this->getReadabilityImport(false, 24); 70 $readabilityImport = $this->getReadabilityImport(false, 3);
71 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 71 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
72 72
73 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 73 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
74 ->disableOriginalConstructor() 74 ->disableOriginalConstructor()
75 ->getMock(); 75 ->getMock();
76 76
77 $entryRepo->expects($this->exactly(24)) 77 $entryRepo->expects($this->exactly(3))
78 ->method('findByUrlAndUserId') 78 ->method('findByUrlAndUserId')
79 ->willReturn(false); 79 ->willReturn(false);
80 80
@@ -88,14 +88,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
88 ->getMock(); 88 ->getMock();
89 89
90 $this->contentProxy 90 $this->contentProxy
91 ->expects($this->exactly(24)) 91 ->expects($this->exactly(3))
92 ->method('updateEntry') 92 ->method('updateEntry')
93 ->willReturn($entry); 93 ->willReturn($entry);
94 94
95 $res = $readabilityImport->import(); 95 $res = $readabilityImport->import();
96 96
97 $this->assertTrue($res); 97 $this->assertTrue($res);
98 $this->assertEquals(['skipped' => 0, 'imported' => 24, 'queued' => 0], $readabilityImport->getSummary()); 98 $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary());
99 } 99 }
100 100
101 public function testImportAndMarkAllAsRead() 101 public function testImportAndMarkAllAsRead()
@@ -165,7 +165,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
165 ->getMock(); 165 ->getMock();
166 166
167 $producer 167 $producer
168 ->expects($this->exactly(24)) 168 ->expects($this->exactly(3))
169 ->method('publish'); 169 ->method('publish');
170 170
171 $readabilityImport->setProducer($producer); 171 $readabilityImport->setProducer($producer);
@@ -173,7 +173,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
173 $res = $readabilityImport->setMarkAsRead(true)->import(); 173 $res = $readabilityImport->setMarkAsRead(true)->import();
174 174
175 $this->assertTrue($res); 175 $this->assertTrue($res);
176 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); 176 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary());
177 } 177 }
178 178
179 public function testImportWithRedis() 179 public function testImportWithRedis()
@@ -211,7 +211,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
211 $res = $readabilityImport->setMarkAsRead(true)->import(); 211 $res = $readabilityImport->setMarkAsRead(true)->import();
212 212
213 $this->assertTrue($res); 213 $this->assertTrue($res);
214 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); 214 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary());
215 215
216 $this->assertNotEmpty($redisMock->lpop('readability')); 216 $this->assertNotEmpty($redisMock->lpop('readability'));
217 } 217 }
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
index 9f0c5bac..834b7ef5 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
@@ -19,6 +19,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
19 protected $contentProxy; 19 protected $contentProxy;
20 protected $tagsAssigner; 20 protected $tagsAssigner;
21 protected $uow; 21 protected $uow;
22 protected $fetchingErrorMessageTitle = 'No title found';
23 protected $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/master/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>.';
22 24
23 private function getWallabagV1Import($unsetUser = false, $dispatched = 0) 25 private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
24 { 26 {
@@ -58,7 +60,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
58 ->expects($this->exactly($dispatched)) 60 ->expects($this->exactly($dispatched))
59 ->method('dispatch'); 61 ->method('dispatch');
60 62
61 $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); 63 $wallabag = new WallabagV1Import(
64 $this->em,
65 $this->contentProxy,
66 $this->tagsAssigner,
67 $dispatcher,
68 $this->fetchingErrorMessageTitle,
69 $this->fetchingErrorMessage
70 );
62 71
63 $this->logHandler = new TestHandler(); 72 $this->logHandler = new TestHandler();
64 $logger = new Logger('test', [$this->logHandler]); 73 $logger = new Logger('test', [$this->logHandler]);
@@ -82,14 +91,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
82 91
83 public function testImport() 92 public function testImport()
84 { 93 {
85 $wallabagV1Import = $this->getWallabagV1Import(false, 3); 94 $wallabagV1Import = $this->getWallabagV1Import(false, 1);
86 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 95 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json');
87 96
88 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 97 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
89 ->disableOriginalConstructor() 98 ->disableOriginalConstructor()
90 ->getMock(); 99 ->getMock();
91 100
92 $entryRepo->expects($this->exactly(4)) 101 $entryRepo->expects($this->exactly(2))
93 ->method('findByUrlAndUserId') 102 ->method('findByUrlAndUserId')
94 ->will($this->onConsecutiveCalls(false, true, false, false)); 103 ->will($this->onConsecutiveCalls(false, true, false, false));
95 104
@@ -103,14 +112,14 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
103 ->getMock(); 112 ->getMock();
104 113
105 $this->contentProxy 114 $this->contentProxy
106 ->expects($this->exactly(3)) 115 ->expects($this->exactly(1))
107 ->method('updateEntry') 116 ->method('updateEntry')
108 ->willReturn($entry); 117 ->willReturn($entry);
109 118
110 $res = $wallabagV1Import->import(); 119 $res = $wallabagV1Import->import();
111 120
112 $this->assertTrue($res); 121 $this->assertTrue($res);
113 $this->assertEquals(['skipped' => 1, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); 122 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary());
114 } 123 }
115 124
116 public function testImportAndMarkAllAsRead() 125 public function testImportAndMarkAllAsRead()
@@ -180,7 +189,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
180 ->getMock(); 189 ->getMock();
181 190
182 $producer 191 $producer
183 ->expects($this->exactly(4)) 192 ->expects($this->exactly(2))
184 ->method('publish'); 193 ->method('publish');
185 194
186 $wallabagV1Import->setProducer($producer); 195 $wallabagV1Import->setProducer($producer);
@@ -188,7 +197,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
188 $res = $wallabagV1Import->setMarkAsRead(true)->import(); 197 $res = $wallabagV1Import->setMarkAsRead(true)->import();
189 198
190 $this->assertTrue($res); 199 $this->assertTrue($res);
191 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); 200 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary());
192 } 201 }
193 202
194 public function testImportWithRedis() 203 public function testImportWithRedis()
@@ -226,7 +235,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
226 $res = $wallabagV1Import->setMarkAsRead(true)->import(); 235 $res = $wallabagV1Import->setMarkAsRead(true)->import();
227 236
228 $this->assertTrue($res); 237 $this->assertTrue($res);
229 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); 238 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary());
230 239
231 $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); 240 $this->assertNotEmpty($redisMock->lpop('wallabag_v1'));
232 } 241 }
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
index efcaeb9e..5cc04aa5 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
@@ -89,7 +89,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
89 ->disableOriginalConstructor() 89 ->disableOriginalConstructor()
90 ->getMock(); 90 ->getMock();
91 91
92 $entryRepo->expects($this->exactly(24)) 92 $entryRepo->expects($this->exactly(6))
93 ->method('findByUrlAndUserId') 93 ->method('findByUrlAndUserId')
94 ->will($this->onConsecutiveCalls(false, true, false)); 94 ->will($this->onConsecutiveCalls(false, true, false));
95 95
@@ -106,7 +106,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
106 $res = $wallabagV2Import->import(); 106 $res = $wallabagV2Import->import();
107 107
108 $this->assertTrue($res); 108 $this->assertTrue($res);
109 $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); 109 $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary());
110 } 110 }
111 111
112 public function testImportAndMarkAllAsRead() 112 public function testImportAndMarkAllAsRead()
@@ -172,7 +172,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
172 ->getMock(); 172 ->getMock();
173 173
174 $producer 174 $producer
175 ->expects($this->exactly(24)) 175 ->expects($this->exactly(6))
176 ->method('publish'); 176 ->method('publish');
177 177
178 $wallabagV2Import->setProducer($producer); 178 $wallabagV2Import->setProducer($producer);
@@ -180,7 +180,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
180 $res = $wallabagV2Import->setMarkAsRead(true)->import(); 180 $res = $wallabagV2Import->setMarkAsRead(true)->import();
181 181
182 $this->assertTrue($res); 182 $this->assertTrue($res);
183 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); 183 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary());
184 } 184 }
185 185
186 public function testImportWithRedis() 186 public function testImportWithRedis()
@@ -214,7 +214,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
214 $res = $wallabagV2Import->setMarkAsRead(true)->import(); 214 $res = $wallabagV2Import->setMarkAsRead(true)->import();
215 215
216 $this->assertTrue($res); 216 $this->assertTrue($res);
217 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); 217 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 6], $wallabagV2Import->getSummary());
218 218
219 $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); 219 $this->assertNotEmpty($redisMock->lpop('wallabag_v2'));
220 } 220 }
@@ -267,7 +267,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
267 ->disableOriginalConstructor() 267 ->disableOriginalConstructor()
268 ->getMock(); 268 ->getMock();
269 269
270 $entryRepo->expects($this->exactly(24)) 270 $entryRepo->expects($this->exactly(6))
271 ->method('findByUrlAndUserId') 271 ->method('findByUrlAndUserId')
272 ->will($this->onConsecutiveCalls(false, true, false)); 272 ->will($this->onConsecutiveCalls(false, true, false));
273 273
@@ -284,6 +284,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
284 $res = $wallabagV2Import->import(); 284 $res = $wallabagV2Import->import();
285 285
286 $this->assertTrue($res); 286 $this->assertTrue($res);
287 $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); 287 $this->assertEquals(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary());
288 } 288 }
289} 289}