fix tests

This commit is contained in:
Thomas Citharel 2016-09-21 19:24:19 +02:00 committed by Jeremy Benoist
parent 2c61db30b7
commit 64b1229b2d
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
6 changed files with 49 additions and 50 deletions

View file

@ -31,13 +31,13 @@ abstract class BrowserImport extends AbstractImport
public function import() public function import()
{ {
if (!$this->user) { if (!$this->user) {
$this->logger->error('WallabagImport: user is not defined'); $this->logger->error('Wallabag Browser Import: user is not defined');
return false; return false;
} }
if (!file_exists($this->filepath) || !is_readable($this->filepath)) { if (!file_exists($this->filepath) || !is_readable($this->filepath)) {
$this->logger->error('WallabagImport: unable to read file', ['filepath' => $this->filepath]); $this->logger->error('Wallabag Browser Import: unable to read file', ['filepath' => $this->filepath]);
return false; return false;
} }

View file

@ -30,26 +30,26 @@ class ChromeImport extends BrowserImport
return 'import.chrome.description'; return 'import.chrome.description';
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function prepareEntry($entry = []) protected function prepareEntry($entry = [])
{ {
$data = [ $data = [
'title' => $entry['name'], 'title' => $entry['name'],
'html' => '', 'html' => '',
'url' => $entry['url'], 'url' => $entry['url'],
'is_archived' => $this->markAsRead, 'is_archived' => $this->markAsRead,
'tags' => '', 'tags' => '',
'created_at' => $entry['date_added'], 'created_at' => $entry['date_added'],
]; ];
if (array_key_exists('tags', $entry) && $entry['tags'] != '') { if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
$data['tags'] = $entry['tags']; $data['tags'] = $entry['tags'];
} }
return $data; return $data;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}

View file

@ -107,12 +107,12 @@ services:
- "@wallabag_core.redis.client" - "@wallabag_core.redis.client"
- "wallabag.import.chrome" - "wallabag.import.chrome"
wallabag_import.producer.redis.firefox: wallabag_import.producer.redis.chrome:
class: Wallabag\ImportBundle\Redis\Producer class: Wallabag\ImportBundle\Redis\Producer
arguments: arguments:
- "@wallabag_import.queue.redis.chrome" - "@wallabag_import.queue.redis.chrome"
wallabag_import.consumer.redis.firefox: wallabag_import.consumer.redis.chrome:
class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer
arguments: arguments:
- "@doctrine.orm.entity_manager" - "@doctrine.orm.entity_manager"

View file

@ -117,7 +117,6 @@ class ChromeControllerTest extends WallabagCoreTestCase
$this->getLoggedInUserId() $this->getLoggedInUserId()
); );
$this->assertEmpty($content->getMimetype());
$this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getPreviewPicture());
$this->assertNotEmpty($content->getLanguage()); $this->assertNotEmpty($content->getLanguage());
$this->assertEquals(0, count($content->getTags())); $this->assertEquals(0, count($content->getTags()));

View file

@ -61,7 +61,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$entryRepo->expects($this->exactly(4)) $entryRepo->expects($this->exactly(1))
->method('findByUrlAndUserId') ->method('findByUrlAndUserId')
->willReturn(false); ->willReturn(false);
@ -75,26 +75,26 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
->getMock(); ->getMock();
$this->contentProxy $this->contentProxy
->expects($this->exactly(4)) ->expects($this->exactly(1))
->method('updateEntry') ->method('updateEntry')
->willReturn($entry); ->willReturn($entry);
$res = $chromeImport->import(); $res = $chromeImport->import();
$this->assertTrue($res); $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() public function testImportAndMarkAllAsRead()
{ {
$chromeImport = $this->getChromeImport(); $chromeImport = $this->getChromeImport();
$chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$entryRepo->expects($this->exactly(2)) $entryRepo->expects($this->exactly(1))
->method('findByUrlAndUserId') ->method('findByUrlAndUserId')
->will($this->onConsecutiveCalls(false, true)); ->will($this->onConsecutiveCalls(false, true));
@ -120,13 +120,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($res); $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() public function testImportWithRabbit()
{ {
$chromeImport = $this->getChromeImport(); $chromeImport = $this->getChromeImport();
$chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -152,20 +152,20 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
->getMock(); ->getMock();
$producer $producer
->expects($this->exactly(4)) ->expects($this->exactly(1))
->method('publish'); ->method('publish');
$chromeImport->setProducer($producer); $chromeImport->setProducer($producer);
$res = $readabilityImport->setMarkAsRead(true)->import(); $res = $chromeImport->setMarkAsRead(true)->import();
$this->assertTrue($res); $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() public function testImportWithRedis()
{ {
$chromeImport = $this->getReadabilityImport(); $chromeImport = $this->getChromeImport();
$chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -198,7 +198,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
$res = $chromeImport->setMarkAsRead(true)->import(); $res = $chromeImport->setMarkAsRead(true)->import();
$this->assertTrue($res); $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->assertNotEmpty($redisMock->lpop('chrome'));
} }
@ -213,21 +213,21 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($res); $this->assertFalse($res);
$records = $this->logHandler->getRecords(); $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']); $this->assertEquals('ERROR', $records[0]['level_name']);
} }
public function testImportUserNotDefined() public function testImportUserNotDefined()
{ {
$chromeImport = $this->getChromeImport(true); $chromeImport = $this->getChromeImport(true);
$chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
$res = $chromeImport->import(); $res = $chromeImport->import();
$this->assertFalse($res); $this->assertFalse($res);
$records = $this->logHandler->getRecords(); $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']); $this->assertEquals('ERROR', $records[0]['level_name']);
} }
} }

View file

@ -88,13 +88,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
public function testImportAndMarkAllAsRead() public function testImportAndMarkAllAsRead()
{ {
$firefoxImport = $this->getFirefoxImport(); $firefoxImport = $this->getFirefoxImport();
$firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$entryRepo->expects($this->exactly(2)) $entryRepo->expects($this->exactly(4))
->method('findByUrlAndUserId') ->method('findByUrlAndUserId')
->will($this->onConsecutiveCalls(false, true)); ->will($this->onConsecutiveCalls(false, true));
@ -120,13 +120,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($res); $this->assertTrue($res);
$this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary());
} }
public function testImportWithRabbit() public function testImportWithRabbit()
{ {
$firefoxImport = $this->getFirefoxImport(); $firefoxImport = $this->getFirefoxImport();
$firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -152,20 +152,20 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
->getMock(); ->getMock();
$producer $producer
->expects($this->exactly(4)) ->expects($this->exactly(1))
->method('publish'); ->method('publish');
$firefoxImport->setProducer($producer); $firefoxImport->setProducer($producer);
$res = $readabilityImport->setMarkAsRead(true)->import(); $res = $firefoxImport->setMarkAsRead(true)->import();
$this->assertTrue($res); $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() public function testImportWithRedis()
{ {
$firefoxImport = $this->getReadabilityImport(); $firefoxImport = $this->getFirefoxImport();
$firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@ -198,7 +198,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
$res = $firefoxImport->setMarkAsRead(true)->import(); $res = $firefoxImport->setMarkAsRead(true)->import();
$this->assertTrue($res); $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->assertNotEmpty($redisMock->lpop('firefox'));
} }
@ -213,21 +213,21 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($res); $this->assertFalse($res);
$records = $this->logHandler->getRecords(); $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']); $this->assertEquals('ERROR', $records[0]['level_name']);
} }
public function testImportUserNotDefined() public function testImportUserNotDefined()
{ {
$firefoxImport = $this->getFirefoxImport(true); $firefoxImport = $this->getFirefoxImport(true);
$firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
$res = $firefoxImport->import(); $res = $firefoxImport->import();
$this->assertFalse($res); $this->assertFalse($res);
$records = $this->logHandler->getRecords(); $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']); $this->assertEquals('ERROR', $records[0]['level_name']);
} }
} }