From 19d9efab32b5c6403e9ee95fb70a2ce56a27f14b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 19 Aug 2016 23:52:19 +0200 Subject: Avoid breaking import when fetching fail graby will throw an Exception in some case (like a bad url, a restricted url or a secured pdf). Import doesn't handle that case and break the whole import. With that commit the import isn't stopped but the entry is just skipped. Also, as a bonus, I've added extra test on WallabagImportV2 when the json is empty. --- .../ImportBundle/Import/WallabagV2ImportTest.php | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php') 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 $this->assertContains('WallabagImport: user is not defined', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } + + public function testImportEmptyFile() + { + $wallabagV2Import = $this->getWallabagV2Import(); + $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-empty.json'); + + $res = $wallabagV2Import->import(); + + $this->assertFalse($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0], $wallabagV2Import->getSummary()); + } + + public function testImportWithExceptionFromGraby() + { + $wallabagV2Import = $this->getWallabagV2Import(); + $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(24)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true, false)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(2)) + ->method('updateEntry') + ->will($this->throwException(new \Exception())); + + $res = $wallabagV2Import->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 24, 'imported' => 0], $wallabagV2Import->getSummary()); + } } -- cgit v1.2.3