X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FImportBundle%2FImport%2FChromeImportTest.php;h=5559ac7ed10c60c42d277e2e11a1823522d23c07;hb=f808b01692a835673f328d7221ba8c212caa9b61;hp=1e52615c0545d1f0739afb4660dce4cd164b323f;hpb=64b1229b2d711e6b2f0e60de482802d9e86b912f;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index 1e52615c..5559ac7e 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\ChromeImport; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\ImportBundle\Redis\Producer; -use Monolog\Logger; +use M6Web\Component\RedisMock\RedisMockFactory; use Monolog\Handler\TestHandler; +use Monolog\Logger; use Simpleue\Queue\RedisQueue; -use M6Web\Component\RedisMock\RedisMockFactory; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Import\ChromeImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class ChromeImportTest extends \PHPUnit_Framework_TestCase { @@ -17,45 +17,21 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $logHandler; protected $contentProxy; - - private function getChromeImport($unsetUser = false) - { - $this->user = new User(); - - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') - ->disableOriginalConstructor() - ->getMock(); - - $wallabag = new ChromeImport($this->em, $this->contentProxy); - - $this->logHandler = new TestHandler(); - $logger = new Logger('test', [$this->logHandler]); - $wallabag->setLogger($logger); - - if (false === $unsetUser) { - $wallabag->setUser($this->user); - } - - return $wallabag; - } + protected $tagsAssigner; public function testInit() { $chromeImport = $this->getChromeImport(); - $this->assertEquals('Chrome', $chromeImport->getName()); + $this->assertSame('Chrome', $chromeImport->getName()); $this->assertNotEmpty($chromeImport->getUrl()); - $this->assertEquals('import.chrome.description', $chromeImport->getDescription()); + $this->assertSame('import.chrome.description', $chromeImport->getDescription()); } public function testImport() { - $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport = $this->getChromeImport(false, 1); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -82,13 +58,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportAndMarkAllAsRead() { - $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport = $this->getChromeImport(false, 1); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -120,13 +96,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportWithRabbit() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -160,13 +136,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); } public function testImportWithRedis() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -198,7 +174,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('chrome')); } @@ -206,7 +182,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $chromeImport->import(); @@ -214,13 +190,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $chromeImport = $this->getChromeImport(true); - $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + $chromeImport->setFilepath(__DIR__ . '/../fixtures/chrome-bookmarks'); $res = $chromeImport->import(); @@ -228,6 +204,43 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getChromeImport($unsetUser = false, $dispatched = 0) + { + $this->user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $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 ChromeImport($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; } }