diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-10-23 11:09:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 11:09:17 +0200 |
commit | 1953a872932a63792293b4aec087880265ba89f7 (patch) | |
tree | fd16599e737fcdaf193c933ef3ec4a4ee248b117 /tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | |
parent | d83d25dadec2c38460a32d96f5d2903426fec9d3 (diff) | |
parent | 702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff) | |
download | wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst wallabag-1953a872932a63792293b4aec087880265ba89f7.zip |
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php')
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | 111 |
1 files changed, 58 insertions, 53 deletions
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index b516fbc5..a1783bfc 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | |||
@@ -2,14 +2,14 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Import; | 3 | namespace Tests\Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use Wallabag\ImportBundle\Import\FirefoxImport; | 5 | use M6Web\Component\RedisMock\RedisMockFactory; |
6 | use Wallabag\UserBundle\Entity\User; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | ||
8 | use Wallabag\ImportBundle\Redis\Producer; | ||
9 | use Monolog\Logger; | ||
10 | use Monolog\Handler\TestHandler; | 6 | use Monolog\Handler\TestHandler; |
7 | use Monolog\Logger; | ||
11 | use Simpleue\Queue\RedisQueue; | 8 | use Simpleue\Queue\RedisQueue; |
12 | use M6Web\Component\RedisMock\RedisMockFactory; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Wallabag\ImportBundle\Import\FirefoxImport; | ||
11 | use Wallabag\ImportBundle\Redis\Producer; | ||
12 | use Wallabag\UserBundle\Entity\User; | ||
13 | 13 | ||
14 | class FirefoxImportTest extends \PHPUnit_Framework_TestCase | 14 | class FirefoxImportTest extends \PHPUnit_Framework_TestCase |
15 | { | 15 | { |
@@ -17,53 +17,21 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
17 | protected $em; | 17 | protected $em; |
18 | protected $logHandler; | 18 | protected $logHandler; |
19 | protected $contentProxy; | 19 | protected $contentProxy; |
20 | 20 | protected $tagsAssigner; | |
21 | private function getFirefoxImport($unsetUser = false, $dispatched = 0) | ||
22 | { | ||
23 | $this->user = new User(); | ||
24 | |||
25 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
26 | ->disableOriginalConstructor() | ||
27 | ->getMock(); | ||
28 | |||
29 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
30 | ->disableOriginalConstructor() | ||
31 | ->getMock(); | ||
32 | |||
33 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
34 | ->disableOriginalConstructor() | ||
35 | ->getMock(); | ||
36 | |||
37 | $dispatcher | ||
38 | ->expects($this->exactly($dispatched)) | ||
39 | ->method('dispatch'); | ||
40 | |||
41 | $wallabag = new FirefoxImport($this->em, $this->contentProxy, $dispatcher); | ||
42 | |||
43 | $this->logHandler = new TestHandler(); | ||
44 | $logger = new Logger('test', [$this->logHandler]); | ||
45 | $wallabag->setLogger($logger); | ||
46 | |||
47 | if (false === $unsetUser) { | ||
48 | $wallabag->setUser($this->user); | ||
49 | } | ||
50 | |||
51 | return $wallabag; | ||
52 | } | ||
53 | 21 | ||
54 | public function testInit() | 22 | public function testInit() |
55 | { | 23 | { |
56 | $firefoxImport = $this->getFirefoxImport(); | 24 | $firefoxImport = $this->getFirefoxImport(); |
57 | 25 | ||
58 | $this->assertEquals('Firefox', $firefoxImport->getName()); | 26 | $this->assertSame('Firefox', $firefoxImport->getName()); |
59 | $this->assertNotEmpty($firefoxImport->getUrl()); | 27 | $this->assertNotEmpty($firefoxImport->getUrl()); |
60 | $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); | 28 | $this->assertSame('import.firefox.description', $firefoxImport->getDescription()); |
61 | } | 29 | } |
62 | 30 | ||
63 | public function testImport() | 31 | public function testImport() |
64 | { | 32 | { |
65 | $firefoxImport = $this->getFirefoxImport(false, 2); | 33 | $firefoxImport = $this->getFirefoxImport(false, 2); |
66 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 34 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
67 | 35 | ||
68 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 36 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
69 | ->disableOriginalConstructor() | 37 | ->disableOriginalConstructor() |
@@ -90,13 +58,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
90 | $res = $firefoxImport->import(); | 58 | $res = $firefoxImport->import(); |
91 | 59 | ||
92 | $this->assertTrue($res); | 60 | $this->assertTrue($res); |
93 | $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); | 61 | $this->assertSame(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); |
94 | } | 62 | } |
95 | 63 | ||
96 | public function testImportAndMarkAllAsRead() | 64 | public function testImportAndMarkAllAsRead() |
97 | { | 65 | { |
98 | $firefoxImport = $this->getFirefoxImport(false, 1); | 66 | $firefoxImport = $this->getFirefoxImport(false, 1); |
99 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 67 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
100 | 68 | ||
101 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 69 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
102 | ->disableOriginalConstructor() | 70 | ->disableOriginalConstructor() |
@@ -128,13 +96,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
128 | 96 | ||
129 | $this->assertTrue($res); | 97 | $this->assertTrue($res); |
130 | 98 | ||
131 | $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); | 99 | $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); |
132 | } | 100 | } |
133 | 101 | ||
134 | public function testImportWithRabbit() | 102 | public function testImportWithRabbit() |
135 | { | 103 | { |
136 | $firefoxImport = $this->getFirefoxImport(); | 104 | $firefoxImport = $this->getFirefoxImport(); |
137 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 105 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
138 | 106 | ||
139 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 107 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
140 | ->disableOriginalConstructor() | 108 | ->disableOriginalConstructor() |
@@ -168,13 +136,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
168 | $res = $firefoxImport->setMarkAsRead(true)->import(); | 136 | $res = $firefoxImport->setMarkAsRead(true)->import(); |
169 | 137 | ||
170 | $this->assertTrue($res); | 138 | $this->assertTrue($res); |
171 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); | 139 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); |
172 | } | 140 | } |
173 | 141 | ||
174 | public function testImportWithRedis() | 142 | public function testImportWithRedis() |
175 | { | 143 | { |
176 | $firefoxImport = $this->getFirefoxImport(); | 144 | $firefoxImport = $this->getFirefoxImport(); |
177 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 145 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
178 | 146 | ||
179 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 147 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
180 | ->disableOriginalConstructor() | 148 | ->disableOriginalConstructor() |
@@ -206,7 +174,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
206 | $res = $firefoxImport->setMarkAsRead(true)->import(); | 174 | $res = $firefoxImport->setMarkAsRead(true)->import(); |
207 | 175 | ||
208 | $this->assertTrue($res); | 176 | $this->assertTrue($res); |
209 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); | 177 | $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); |
210 | 178 | ||
211 | $this->assertNotEmpty($redisMock->lpop('firefox')); | 179 | $this->assertNotEmpty($redisMock->lpop('firefox')); |
212 | } | 180 | } |
@@ -214,7 +182,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
214 | public function testImportBadFile() | 182 | public function testImportBadFile() |
215 | { | 183 | { |
216 | $firefoxImport = $this->getFirefoxImport(); | 184 | $firefoxImport = $this->getFirefoxImport(); |
217 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); | 185 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); |
218 | 186 | ||
219 | $res = $firefoxImport->import(); | 187 | $res = $firefoxImport->import(); |
220 | 188 | ||
@@ -222,13 +190,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
222 | 190 | ||
223 | $records = $this->logHandler->getRecords(); | 191 | $records = $this->logHandler->getRecords(); |
224 | $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); | 192 | $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); |
225 | $this->assertEquals('ERROR', $records[0]['level_name']); | 193 | $this->assertSame('ERROR', $records[0]['level_name']); |
226 | } | 194 | } |
227 | 195 | ||
228 | public function testImportUserNotDefined() | 196 | public function testImportUserNotDefined() |
229 | { | 197 | { |
230 | $firefoxImport = $this->getFirefoxImport(true); | 198 | $firefoxImport = $this->getFirefoxImport(true); |
231 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | 199 | $firefoxImport->setFilepath(__DIR__ . '/../fixtures/firefox-bookmarks.json'); |
232 | 200 | ||
233 | $res = $firefoxImport->import(); | 201 | $res = $firefoxImport->import(); |
234 | 202 | ||
@@ -236,6 +204,43 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
236 | 204 | ||
237 | $records = $this->logHandler->getRecords(); | 205 | $records = $this->logHandler->getRecords(); |
238 | $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); | 206 | $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); |
239 | $this->assertEquals('ERROR', $records[0]['level_name']); | 207 | $this->assertSame('ERROR', $records[0]['level_name']); |
208 | } | ||
209 | |||
210 | private function getFirefoxImport($unsetUser = false, $dispatched = 0) | ||
211 | { | ||
212 | $this->user = new User(); | ||
213 | |||
214 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
215 | ->disableOriginalConstructor() | ||
216 | ->getMock(); | ||
217 | |||
218 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
219 | ->disableOriginalConstructor() | ||
220 | ->getMock(); | ||
221 | |||
222 | $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') | ||
223 | ->disableOriginalConstructor() | ||
224 | ->getMock(); | ||
225 | |||
226 | $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') | ||
227 | ->disableOriginalConstructor() | ||
228 | ->getMock(); | ||
229 | |||
230 | $dispatcher | ||
231 | ->expects($this->exactly($dispatched)) | ||
232 | ->method('dispatch'); | ||
233 | |||
234 | $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); | ||
235 | |||
236 | $this->logHandler = new TestHandler(); | ||
237 | $logger = new Logger('test', [$this->logHandler]); | ||
238 | $wallabag->setLogger($logger); | ||
239 | |||
240 | if (false === $unsetUser) { | ||
241 | $wallabag->setUser($this->user); | ||
242 | } | ||
243 | |||
244 | return $wallabag; | ||
240 | } | 245 | } |
241 | } | 246 | } |