protected $em;
protected $logHandler;
protected $contentProxy;
+ protected $tagsAssigner;
- private function getFirefoxImport($unsetUser = false)
+ private function getFirefoxImport($unsetUser = false, $dispatched = 0)
{
$this->user = new User();
->disableOriginalConstructor()
->getMock();
- $wallabag = new FirefoxImport($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 FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]);
public function testImport()
{
- $firefoxImport = $this->getFirefoxImport();
+ $firefoxImport = $this->getFirefoxImport(false, 2);
$firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor()
->getMock();
- $entryRepo->expects($this->exactly(4))
+ $entryRepo->expects($this->exactly(2))
->method('findByUrlAndUserId')
->willReturn(false);
->getMock();
$this->contentProxy
- ->expects($this->exactly(4))
- ->method('updateEntry')
+ ->expects($this->exactly(2))
+ ->method('importEntry')
->willReturn($entry);
$res = $firefoxImport->import();
$this->assertTrue($res);
- $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary());
+ $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary());
}
public function testImportAndMarkAllAsRead()
{
- $firefoxImport = $this->getFirefoxImport();
- $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
+ $firefoxImport = $this->getFirefoxImport(false, 1);
+ $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor()
$this->contentProxy
->expects($this->exactly(1))
- ->method('updateEntry')
+ ->method('importEntry')
->willReturn(new Entry($this->user));
// check that every entry persisted are archived
public function testImportWithRabbit()
{
$firefoxImport = $this->getFirefoxImport();
- $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json');
+ $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor()
$this->contentProxy
->expects($this->never())
- ->method('updateEntry');
+ ->method('importEntry');
$producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer')
->disableOriginalConstructor()
->getMock();
$producer
- ->expects($this->exactly(4))
+ ->expects($this->exactly(1))
->method('publish');
$firefoxImport->setProducer($producer);
- $res = $readabilityImport->setMarkAsRead(true)->import();
+ $res = $firefoxImport->setMarkAsRead(true)->import();
$this->assertTrue($res);
- $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary());
+ $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary());
}
public function testImportWithRedis()
{
- $firefoxImport = $this->getReadabilityImport();
+ $firefoxImport = $this->getFirefoxImport();
$firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
$this->contentProxy
->expects($this->never())
- ->method('updateEntry');
+ ->method('importEntry');
$factory = new RedisMockFactory();
$redisMock = $factory->getAdapter('Predis\Client', true);
$res = $firefoxImport->setMarkAsRead(true)->import();
$this->assertTrue($res);
- $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary());
+ $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary());
$this->assertNotEmpty($redisMock->lpop('firefox'));
}
$this->assertFalse($res);
$records = $this->logHandler->getRecords();
- $this->assertContains('FirefoxImport: 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()
{
$firefoxImport = $this->getFirefoxImport(true);
- $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json');
+ $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$res = $firefoxImport->import();
$this->assertFalse($res);
$records = $this->logHandler->getRecords();
- $this->assertContains('FirefoxImport: 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']);
}
}