diff options
Diffstat (limited to 'tests/Wallabag')
4 files changed, 109 insertions, 2 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 2413d735..c0133af4 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | |||
@@ -28,16 +28,32 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
28 | * | 28 | * |
29 | * http://stackoverflow.com/a/14374832/569101 | 29 | * http://stackoverflow.com/a/14374832/569101 |
30 | */ | 30 | */ |
31 | $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.'); | 31 | $this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.'); |
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | /** | ||
36 | * Ensure next tests will have a clean database | ||
37 | */ | ||
35 | public static function tearDownAfterClass() | 38 | public static function tearDownAfterClass() |
36 | { | 39 | { |
37 | $application = new Application(static::$kernel); | 40 | $application = new Application(static::$kernel); |
38 | $application->setAutoExit(false); | 41 | $application->setAutoExit(false); |
39 | 42 | ||
40 | $code = $application->run(new ArrayInput([ | 43 | $application->run(new ArrayInput([ |
44 | 'command' => 'doctrine:schema:drop', | ||
45 | '--no-interaction' => true, | ||
46 | '--force' => true, | ||
47 | '--env' => 'test', | ||
48 | ]), new NullOutput()); | ||
49 | |||
50 | $application->run(new ArrayInput([ | ||
51 | 'command' => 'doctrine:schema:create', | ||
52 | '--no-interaction' => true, | ||
53 | '--env' => 'test', | ||
54 | ]), new NullOutput()); | ||
55 | |||
56 | $application->run(new ArrayInput([ | ||
41 | 'command' => 'doctrine:fixtures:load', | 57 | 'command' => 'doctrine:fixtures:load', |
42 | '--no-interaction' => true, | 58 | '--no-interaction' => true, |
43 | '--env' => 'test', | 59 | '--env' => 'test', |
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 41f9b51f..8534e1c8 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php | |||
@@ -390,4 +390,55 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase | |||
390 | $this->assertContains('PocketImport: Failed to import', $records[0]['message']); | 390 | $this->assertContains('PocketImport: Failed to import', $records[0]['message']); |
391 | $this->assertEquals('ERROR', $records[0]['level_name']); | 391 | $this->assertEquals('ERROR', $records[0]['level_name']); |
392 | } | 392 | } |
393 | |||
394 | public function testImportWithExceptionFromGraby() | ||
395 | { | ||
396 | $client = new Client(); | ||
397 | |||
398 | $mock = new Mock([ | ||
399 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | ||
400 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | ||
401 | { | ||
402 | "status": 1, | ||
403 | "list": { | ||
404 | "229279689": { | ||
405 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" | ||
406 | } | ||
407 | } | ||
408 | } | ||
409 | ')), | ||
410 | ]); | ||
411 | |||
412 | $client->getEmitter()->attach($mock); | ||
413 | |||
414 | $pocketImport = $this->getPocketImport(); | ||
415 | |||
416 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
417 | ->disableOriginalConstructor() | ||
418 | ->getMock(); | ||
419 | |||
420 | $entryRepo->expects($this->once()) | ||
421 | ->method('findByUrlAndUserId') | ||
422 | ->will($this->onConsecutiveCalls(false, true)); | ||
423 | |||
424 | $this->em | ||
425 | ->expects($this->once()) | ||
426 | ->method('getRepository') | ||
427 | ->willReturn($entryRepo); | ||
428 | |||
429 | $entry = new Entry($this->user); | ||
430 | |||
431 | $this->contentProxy | ||
432 | ->expects($this->once()) | ||
433 | ->method('updateEntry') | ||
434 | ->will($this->throwException(new \Exception())); | ||
435 | |||
436 | $pocketImport->setClient($client); | ||
437 | $pocketImport->authorize('wunderbar_code'); | ||
438 | |||
439 | $res = $pocketImport->import(); | ||
440 | |||
441 | $this->assertTrue($res); | ||
442 | $this->assertEquals(['skipped' => 1, 'imported' => 0], $pocketImport->getSummary()); | ||
443 | } | ||
393 | } | 444 | } |
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 8ec66b12..4a45e0f0 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | |||
@@ -143,4 +143,44 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase | |||
143 | $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); | 143 | $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); |
144 | $this->assertEquals('ERROR', $records[0]['level_name']); | 144 | $this->assertEquals('ERROR', $records[0]['level_name']); |
145 | } | 145 | } |
146 | |||
147 | public function testImportEmptyFile() | ||
148 | { | ||
149 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
150 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-empty.json'); | ||
151 | |||
152 | $res = $wallabagV2Import->import(); | ||
153 | |||
154 | $this->assertFalse($res); | ||
155 | $this->assertEquals(['skipped' => 0, 'imported' => 0], $wallabagV2Import->getSummary()); | ||
156 | } | ||
157 | |||
158 | public function testImportWithExceptionFromGraby() | ||
159 | { | ||
160 | $wallabagV2Import = $this->getWallabagV2Import(); | ||
161 | $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); | ||
162 | |||
163 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
164 | ->disableOriginalConstructor() | ||
165 | ->getMock(); | ||
166 | |||
167 | $entryRepo->expects($this->exactly(24)) | ||
168 | ->method('findByUrlAndUserId') | ||
169 | ->will($this->onConsecutiveCalls(false, true, false)); | ||
170 | |||
171 | $this->em | ||
172 | ->expects($this->any()) | ||
173 | ->method('getRepository') | ||
174 | ->willReturn($entryRepo); | ||
175 | |||
176 | $this->contentProxy | ||
177 | ->expects($this->exactly(2)) | ||
178 | ->method('updateEntry') | ||
179 | ->will($this->throwException(new \Exception())); | ||
180 | |||
181 | $res = $wallabagV2Import->import(); | ||
182 | |||
183 | $this->assertTrue($res); | ||
184 | $this->assertEquals(['skipped' => 24, 'imported' => 0], $wallabagV2Import->getSummary()); | ||
185 | } | ||
146 | } | 186 | } |
diff --git a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-empty.json b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-empty.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-empty.json | |||