+ $this->assertSame('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->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary());
+ }
+
+ public function testImportWithExceptionFromGraby()
+ {
+ $wallabagV2Import = $this->getWallabagV2Import(false, 2);
+ $wallabagV2Import->setFilepath(__DIR__ . '/../fixtures/wallabag-v2.json');
+
+ $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $entryRepo->expects($this->exactly(6))
+ ->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->assertSame(['skipped' => 4, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary());
+ }
+
+ private function getWallabagV2Import($unsetUser = false, $dispatched = 0)
+ {
+ $this->user = new User();
+
+ $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->em
+ ->expects($this->any())
+ ->method('getUnitOfWork')
+ ->willReturn($this->uow);
+
+ $this->uow
+ ->expects($this->any())
+ ->method('getScheduledEntityInsertions')
+ ->willReturn([]);
+
+ $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dispatcher
+ ->expects($this->exactly($dispatched))
+ ->method('dispatch');
+
+ $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
+
+ $this->logHandler = new TestHandler();
+ $logger = new Logger('test', [$this->logHandler]);
+ $wallabag->setLogger($logger);
+
+ if (false === $unsetUser) {
+ $wallabag->setUser($this->user);
+ }
+
+ return $wallabag;