From 6bc6fb1f60e7b81a21f844dca025671a2f4a4564 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 27 May 2017 22:08:14 +0200 Subject: Move Tags assigner to a separate file Signed-off-by: Thomas Citharel --- tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php') diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index d1bbe648..254f0a25 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -17,6 +17,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $logHandler; protected $contentProxy; + protected $tagsAssigner; private function getReadabilityImport($unsetUser = false, $dispatched = 0) { @@ -30,6 +31,10 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner') + ->disableOriginalConstructor() + ->getMock(); + $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') ->disableOriginalConstructor() ->getMock(); @@ -38,7 +43,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly($dispatched)) ->method('dispatch'); - $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $dispatcher); + $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); -- cgit v1.2.3 From e668a8124c46d47add4248963d77f3b29b37b3ce Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 11 May 2017 08:14:29 +0200 Subject: Allow other fields to be send using API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Entry API can now have these new fields: - content - language - preview_picture - published_at Re-use the ContentProxy to be able to do the same using the web UI (in the future). htmLawed is used to clean stuff from content, I hope it’ll be enough to avoid security breach. Lower content validation when we want to update an entry with content already defined. Before, language & content_type were required. If there weren’t provided, we re-fetched the content using graby. I think these fields aren’t required for an entry to be created. So I removed them. Which means some import from the v1 export won’t be re-fetched since they provide content, url & title. Also, remove liberation link from Readability import to avoid overlaping import (from wallabag v1, which had the same link) --- .../Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php') diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 254f0a25..25eedd1b 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -67,14 +67,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase public function testImport() { - $readabilityImport = $this->getReadabilityImport(false, 24); + $readabilityImport = $this->getReadabilityImport(false, 23); $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(24)) + $entryRepo->expects($this->exactly(23)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -88,14 +88,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(24)) + ->expects($this->exactly(23)) ->method('updateEntry') ->willReturn($entry); $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 23, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -165,7 +165,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(24)) + ->expects($this->exactly(23)) ->method('publish'); $readabilityImport->setProducer($producer); @@ -173,7 +173,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 23], $readabilityImport->getSummary()); } public function testImportWithRedis() @@ -211,7 +211,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 23], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } -- cgit v1.2.3 From cf05a1ae342b8f59ee0944eeba0f75aa0a1a2816 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 16 May 2017 21:17:10 +0200 Subject: Reduce imported entries Down from 2.2 minutes to 1.39 minutes --- .../Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php') diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 25eedd1b..8f466d38 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -67,14 +67,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase public function testImport() { - $readabilityImport = $this->getReadabilityImport(false, 23); + $readabilityImport = $this->getReadabilityImport(false, 3); $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(23)) + $entryRepo->expects($this->exactly(3)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -88,14 +88,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(23)) + ->expects($this->exactly(3)) ->method('updateEntry') ->willReturn($entry); $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 23, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -165,7 +165,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(23)) + ->expects($this->exactly(3)) ->method('publish'); $readabilityImport->setProducer($producer); @@ -173,7 +173,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 23], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); } public function testImportWithRedis() @@ -211,7 +211,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 23], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../ImportBundle/Import/ReadabilityImportTest.php | 114 ++++++++++----------- 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php') diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 8f466d38..1822cdaa 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -2,14 +2,14 @@ namespace Tests\Wallabag\ImportBundle\Import; -use Wallabag\ImportBundle\Import\ReadabilityImport; -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\ReadabilityImport; +use Wallabag\ImportBundle\Redis\Producer; +use Wallabag\UserBundle\Entity\User; class ReadabilityImportTest extends \PHPUnit_Framework_TestCase { @@ -19,56 +19,19 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase protected $contentProxy; protected $tagsAssigner; - private function getReadabilityImport($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 ReadabilityImport($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; - } - public function testInit() { $readabilityImport = $this->getReadabilityImport(); - $this->assertEquals('Readability', $readabilityImport->getName()); + $this->assertSame('Readability', $readabilityImport->getName()); $this->assertNotEmpty($readabilityImport->getUrl()); - $this->assertEquals('import.readability.description', $readabilityImport->getDescription()); + $this->assertSame('import.readability.description', $readabilityImport->getDescription()); } public function testImport() { $readabilityImport = $this->getReadabilityImport(false, 3); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -95,13 +58,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 3, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() { $readabilityImport = $this->getReadabilityImport(false, 1); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability-read.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -133,13 +96,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportWithRabbit() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -173,13 +136,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); } public function testImportWithRedis() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -211,7 +174,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); + $this->assertSame(['skipped' => 0, 'imported' => 0, 'queued' => 3], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } @@ -219,7 +182,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase public function testImportBadFile() { $readabilityImport = $this->getReadabilityImport(); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/wallabag-v1.jsonx'); $res = $readabilityImport->import(); @@ -227,13 +190,13 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('ReadabilityImport: unable to read file', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $readabilityImport = $this->getReadabilityImport(true); - $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $readabilityImport->setFilepath(__DIR__ . '/../fixtures/readability.json'); $res = $readabilityImport->import(); @@ -241,6 +204,43 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $records = $this->logHandler->getRecords(); $this->assertContains('ReadabilityImport: user is not defined', $records[0]['message']); - $this->assertEquals('ERROR', $records[0]['level_name']); + $this->assertSame('ERROR', $records[0]['level_name']); + } + + private function getReadabilityImport($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 ReadabilityImport($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; } } -- cgit v1.2.3