protected $em;
protected $logHandler;
protected $contentProxy;
+ protected $tagsAssigner;
- private function getChromeImport($unsetUser = false)
+ private function getChromeImport($unsetUser = false, $dispatched = 0)
{
$this->user = new User();
->disableOriginalConstructor()
->getMock();
- $wallabag = new ChromeImport($this->em, $this->contentProxy);
+ $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 ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]);
public function testImport()
{
- $chromeImport = $this->getChromeImport();
+ $chromeImport = $this->getChromeImport(false, 1);
$chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor()
->getMock();
- $entryRepo->expects($this->exactly(4))
+ $entryRepo->expects($this->exactly(1))
->method('findByUrlAndUserId')
->willReturn(false);
->getMock();
$this->contentProxy
- ->expects($this->exactly(4))
+ ->expects($this->exactly(1))
->method('updateEntry')
->willReturn($entry);
$res = $chromeImport->import();
$this->assertTrue($res);
- $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary());
+ $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
}
public function testImportAndMarkAllAsRead()
{
- $chromeImport = $this->getChromeImport();
- $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
+ $chromeImport = $this->getChromeImport(false, 1);
+ $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor()
->getMock();
- $entryRepo->expects($this->exactly(2))
+ $entryRepo->expects($this->exactly(1))
->method('findByUrlAndUserId')
->will($this->onConsecutiveCalls(false, true));
$this->assertTrue($res);
- $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
+ $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
}
public function testImportWithRabbit()
{
$chromeImport = $this->getChromeImport();
- $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json');
+ $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor()
->getMock();
$producer
- ->expects($this->exactly(4))
+ ->expects($this->exactly(1))
->method('publish');
$chromeImport->setProducer($producer);
- $res = $readabilityImport->setMarkAsRead(true)->import();
+ $res = $chromeImport->setMarkAsRead(true)->import();
$this->assertTrue($res);
- $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary());
+ $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary());
}
public function testImportWithRedis()
{
- $chromeImport = $this->getReadabilityImport();
+ $chromeImport = $this->getChromeImport();
$chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
$res = $chromeImport->setMarkAsRead(true)->import();
$this->assertTrue($res);
- $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary());
+ $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary());
$this->assertNotEmpty($redisMock->lpop('chrome'));
}
$this->assertFalse($res);
$records = $this->logHandler->getRecords();
- $this->assertContains('ChromeImport: unable to read file', $records[0]['message']);
+ $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']);
$this->assertEquals('ERROR', $records[0]['level_name']);
}
public function testImportUserNotDefined()
{
$chromeImport = $this->getChromeImport(true);
- $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json');
+ $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$res = $chromeImport->import();
$this->assertFalse($res);
$records = $this->logHandler->getRecords();
- $this->assertContains('ChromeImport: user is not defined', $records[0]['message']);
+ $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']);
$this->assertEquals('ERROR', $records[0]['level_name']);
}
}