aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php')
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php156
1 files changed, 78 insertions, 78 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
index 834b7ef5..822ad694 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
@@ -2,14 +2,14 @@
2 2
3namespace Tests\Wallabag\ImportBundle\Import; 3namespace Tests\Wallabag\ImportBundle\Import;
4 4
5use Wallabag\ImportBundle\Import\WallabagV1Import; 5use M6Web\Component\RedisMock\RedisMockFactory;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler; 6use Monolog\Handler\TestHandler;
7use Monolog\Logger;
11use Simpleue\Queue\RedisQueue; 8use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\ImportBundle\Import\WallabagV1Import;
11use Wallabag\ImportBundle\Redis\Producer;
12use Wallabag\UserBundle\Entity\User;
13 13
14class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase 14class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
15{ 15{
@@ -22,77 +22,19 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
22 protected $fetchingErrorMessageTitle = 'No title found'; 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>.'; 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>.';
24 24
25 private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
26 {
27 $this->user = new User();
28
29 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $this->em
38 ->expects($this->any())
39 ->method('getUnitOfWork')
40 ->willReturn($this->uow);
41
42 $this->uow
43 ->expects($this->any())
44 ->method('getScheduledEntityInsertions')
45 ->willReturn([]);
46
47 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
48 ->disableOriginalConstructor()
49 ->getMock();
50
51 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
52 ->disableOriginalConstructor()
53 ->getMock();
54
55 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
56 ->disableOriginalConstructor()
57 ->getMock();
58
59 $dispatcher
60 ->expects($this->exactly($dispatched))
61 ->method('dispatch');
62
63 $wallabag = new WallabagV1Import(
64 $this->em,
65 $this->contentProxy,
66 $this->tagsAssigner,
67 $dispatcher,
68 $this->fetchingErrorMessageTitle,
69 $this->fetchingErrorMessage
70 );
71
72 $this->logHandler = new TestHandler();
73 $logger = new Logger('test', [$this->logHandler]);
74 $wallabag->setLogger($logger);
75
76 if (false === $unsetUser) {
77 $wallabag->setUser($this->user);
78 }
79
80 return $wallabag;
81 }
82
83 public function testInit() 25 public function testInit()
84 { 26 {
85 $wallabagV1Import = $this->getWallabagV1Import(); 27 $wallabagV1Import = $this->getWallabagV1Import();
86 28
87 $this->assertEquals('wallabag v1', $wallabagV1Import->getName()); 29 $this->assertSame('wallabag v1', $wallabagV1Import->getName());
88 $this->assertNotEmpty($wallabagV1Import->getUrl()); 30 $this->assertNotEmpty($wallabagV1Import->getUrl());
89 $this->assertEquals('import.wallabag_v1.description', $wallabagV1Import->getDescription()); 31 $this->assertSame('import.wallabag_v1.description', $wallabagV1Import->getDescription());
90 } 32 }
91 33
92 public function testImport() 34 public function testImport()
93 { 35 {
94 $wallabagV1Import = $this->getWallabagV1Import(false, 1); 36 $wallabagV1Import = $this->getWallabagV1Import(false, 1);
95 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 37 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json');
96 38
97 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 39 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
98 ->disableOriginalConstructor() 40 ->disableOriginalConstructor()
@@ -119,13 +61,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
119 $res = $wallabagV1Import->import(); 61 $res = $wallabagV1Import->import();
120 62
121 $this->assertTrue($res); 63 $this->assertTrue($res);
122 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary()); 64 $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $wallabagV1Import->getSummary());
123 } 65 }
124 66
125 public function testImportAndMarkAllAsRead() 67 public function testImportAndMarkAllAsRead()
126 { 68 {
127 $wallabagV1Import = $this->getWallabagV1Import(false, 3); 69 $wallabagV1Import = $this->getWallabagV1Import(false, 3);
128 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json'); 70 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1-read.json');
129 71
130 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 72 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
131 ->disableOriginalConstructor() 73 ->disableOriginalConstructor()
@@ -157,13 +99,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
157 99
158 $this->assertTrue($res); 100 $this->assertTrue($res);
159 101
160 $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); 102 $this->assertSame(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary());
161 } 103 }
162 104
163 public function testImportWithRabbit() 105 public function testImportWithRabbit()
164 { 106 {
165 $wallabagV1Import = $this->getWallabagV1Import(); 107 $wallabagV1Import = $this->getWallabagV1Import();
166 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 108 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json');
167 109
168 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 110 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
169 ->disableOriginalConstructor() 111 ->disableOriginalConstructor()
@@ -197,13 +139,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
197 $res = $wallabagV1Import->setMarkAsRead(true)->import(); 139 $res = $wallabagV1Import->setMarkAsRead(true)->import();
198 140
199 $this->assertTrue($res); 141 $this->assertTrue($res);
200 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); 142 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary());
201 } 143 }
202 144
203 public function testImportWithRedis() 145 public function testImportWithRedis()
204 { 146 {
205 $wallabagV1Import = $this->getWallabagV1Import(); 147 $wallabagV1Import = $this->getWallabagV1Import();
206 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 148 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json');
207 149
208 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 150 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
209 ->disableOriginalConstructor() 151 ->disableOriginalConstructor()
@@ -235,7 +177,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
235 $res = $wallabagV1Import->setMarkAsRead(true)->import(); 177 $res = $wallabagV1Import->setMarkAsRead(true)->import();
236 178
237 $this->assertTrue($res); 179 $this->assertTrue($res);
238 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary()); 180 $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 2], $wallabagV1Import->getSummary());
239 181
240 $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); 182 $this->assertNotEmpty($redisMock->lpop('wallabag_v1'));
241 } 183 }
@@ -243,7 +185,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
243 public function testImportBadFile() 185 public function testImportBadFile()
244 { 186 {
245 $wallabagV1Import = $this->getWallabagV1Import(); 187 $wallabagV1Import = $this->getWallabagV1Import();
246 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); 188 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx');
247 189
248 $res = $wallabagV1Import->import(); 190 $res = $wallabagV1Import->import();
249 191
@@ -251,13 +193,13 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
251 193
252 $records = $this->logHandler->getRecords(); 194 $records = $this->logHandler->getRecords();
253 $this->assertContains('WallabagImport: unable to read file', $records[0]['message']); 195 $this->assertContains('WallabagImport: unable to read file', $records[0]['message']);
254 $this->assertEquals('ERROR', $records[0]['level_name']); 196 $this->assertSame('ERROR', $records[0]['level_name']);
255 } 197 }
256 198
257 public function testImportUserNotDefined() 199 public function testImportUserNotDefined()
258 { 200 {
259 $wallabagV1Import = $this->getWallabagV1Import(true); 201 $wallabagV1Import = $this->getWallabagV1Import(true);
260 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 202 $wallabagV1Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.json');
261 203
262 $res = $wallabagV1Import->import(); 204 $res = $wallabagV1Import->import();
263 205
@@ -265,6 +207,64 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
265 207
266 $records = $this->logHandler->getRecords(); 208 $records = $this->logHandler->getRecords();
267 $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); 209 $this->assertContains('WallabagImport: user is not defined', $records[0]['message']);
268 $this->assertEquals('ERROR', $records[0]['level_name']); 210 $this->assertSame('ERROR', $records[0]['level_name']);
211 }
212
213 private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
214 {
215 $this->user = new User();
216
217 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
218 ->disableOriginalConstructor()
219 ->getMock();
220
221 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
222 ->disableOriginalConstructor()
223 ->getMock();
224
225 $this->em
226 ->expects($this->any())
227 ->method('getUnitOfWork')
228 ->willReturn($this->uow);
229
230 $this->uow
231 ->expects($this->any())
232 ->method('getScheduledEntityInsertions')
233 ->willReturn([]);
234
235 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
236 ->disableOriginalConstructor()
237 ->getMock();
238
239 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
240 ->disableOriginalConstructor()
241 ->getMock();
242
243 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
244 ->disableOriginalConstructor()
245 ->getMock();
246
247 $dispatcher
248 ->expects($this->exactly($dispatched))
249 ->method('dispatch');
250
251 $wallabag = new WallabagV1Import(
252 $this->em,
253 $this->contentProxy,
254 $this->tagsAssigner,
255 $dispatcher,
256 $this->fetchingErrorMessageTitle,
257 $this->fetchingErrorMessage
258 );
259
260 $this->logHandler = new TestHandler();
261 $logger = new Logger('test', [$this->logHandler]);
262 $wallabag->setLogger($logger);
263
264 if (false === $unsetUser) {
265 $wallabag->setUser($this->user);
266 }
267
268 return $wallabag;
269 } 269 }
270} 270}