]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #3168 from wallabag/instapaper-tags-import
authorNicolas Lœuillet <nicolas@loeuillet.org>
Wed, 31 May 2017 10:32:09 +0000 (12:32 +0200)
committerGitHub <noreply@github.com>
Wed, 31 May 2017 10:32:09 +0000 (12:32 +0200)
Add support for tag in Instapaper import

13 files changed:
src/Wallabag/ImportBundle/Import/InstapaperImport.php
tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php
tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php
tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php
tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv

index 70a53f1af5309e64f1734ede1eb8686facc88b84..c8e0cd5b26a02a6961999c5d9abe6fa4fc83c458 100644 (file)
@@ -68,6 +68,14 @@ class InstapaperImport extends AbstractImport
                 continue;
             }
 
+            // last element in the csv is the folder where the content belong
+            // BUT it can also be the status (since status = folder in Instapaper)
+            // and we don't want archive, unread & starred to become a tag
+            $tags = null;
+            if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'])) {
+                $tags = [$data[3]];
+            }
+
             $entries[] = [
                 'url' => $data[0],
                 'title' => $data[1],
@@ -75,6 +83,7 @@ class InstapaperImport extends AbstractImport
                 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred',
                 'is_starred' => $data[3] === 'Starred',
                 'html' => false,
+                'tags' => $tags,
             ];
         }
         fclose($handle);
@@ -118,6 +127,14 @@ class InstapaperImport extends AbstractImport
         // update entry with content (in case fetching failed, the given entry will be return)
         $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry);
 
+        if (!empty($importedEntry['tags'])) {
+            $this->tagsAssigner->assignTagsToEntry(
+                $entry,
+                $importedEntry['tags'],
+                $this->em->getUnitOfWork()->getScheduledEntityInsertions()
+            );
+        }
+
         $entry->setArchived($importedEntry['is_archived']);
         $entry->setStarred($importedEntry['is_starred']);
 
index b21f3318554dc7210892185d6fb35cea611c4baf..284efac4b6a591e4a22a2e198d42c593b3233fac 100644 (file)
@@ -10,7 +10,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 class ExportCommandTest extends WallabagCoreTestCase
 {
     /**
-     * @expectedException Symfony\Component\Console\Exception\RuntimeException
+     * @expectedException \Symfony\Component\Console\Exception\RuntimeException
      * @expectedExceptionMessage Not enough arguments (missing: "username")
      */
     public function testExportCommandWithoutUsername()
index ec31708f93d1240ccd5332317b67abb4b2f5efd6..4cde3679202895bfb2c46aba11961a5682812626 100644 (file)
@@ -10,7 +10,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
 class TagAllCommandTest extends WallabagCoreTestCase
 {
     /**
-     * @expectedException Symfony\Component\Console\Exception\RuntimeException
+     * @expectedException \Symfony\Component\Console\Exception\RuntimeException
      * @expectedExceptionMessage Not enough arguments (missing: "username")
      */
     public function testRunTagAllCommandWithoutUsername()
index 77dfd5bf91404544d5ddbd2232adb429da3fa94f..44fca0737280f8c3507e0cbec4270753e936cc63 100644 (file)
@@ -7,7 +7,6 @@ use Wallabag\CoreBundle\Helper\ContentProxy;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
 use Wallabag\UserBundle\Entity\User;
-use Wallabag\CoreBundle\Repository\TagRepository;
 use Wallabag\CoreBundle\Helper\RuleBasedTagger;
 
 class ContentProxyTest extends \PHPUnit_Framework_TestCase
index 2e6fccfb152fe8830efddad032b8b15e9e95bb17..ca8e0d50b5bba11894202ee4c26e5e4a0faf1f65 100644 (file)
@@ -136,7 +136,7 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
+     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
      * @expectedExceptionMessage User not found
      */
     public function testApplyUserNotFound()
index 749528478d470c8e20209b5769fe128a1c1ab89a..e5e251a0f9d3bd86a768253f832e8a0827ec7f53 100644 (file)
@@ -11,7 +11,7 @@ use M6Web\Component\RedisMock\RedisMockFactory;
 class RedisWorkerCommandTest extends WallabagCoreTestCase
 {
     /**
-     * @expectedException Symfony\Component\Console\Exception\RuntimeException
+     * @expectedException \Symfony\Component\Console\Exception\RuntimeException
      * @expectedExceptionMessage Not enough arguments (missing: "serviceName")
      */
     public function testRunRedisWorkerCommandWithoutArguments()
@@ -28,7 +28,7 @@ class RedisWorkerCommandTest extends WallabagCoreTestCase
     }
 
     /**
-     * @expectedException Symfony\Component\Config\Definition\Exception\Exception
+     * @expectedException \Symfony\Component\Config\Definition\Exception\Exception
      * @expectedExceptionMessage No queue or consumer found for service name
      */
     public function testRunRedisWorkerCommandWithBadService()
index c2e5fdb752f8f8461150ca917e00f67b7ebceb86..84742e0a7903847ea1a82641de7e84041f80d28f 100644 (file)
@@ -107,6 +107,9 @@ class InstapaperControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->followRedirect();
 
+        $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
+        $this->assertContains('flashes.import.notice.summary', $body[0]);
+
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
             ->getRepository('WallabagCoreBundle:Entry')
@@ -115,14 +118,25 @@ class InstapaperControllerTest extends WallabagCoreTestCase
                 $this->getLoggedInUserId()
             );
 
-        $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
-        $this->assertContains('flashes.import.notice.summary', $body[0]);
-
         $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.liberation.fr is ok');
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.liberation.fr is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.liberation.fr is ok');
+        $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag');
         $this->assertEquals(1, count($content->getTags()));
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
+
+        $content = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findByUrlAndUserId(
+                'http://www.20minutes.fr/high-tech/2077615-20170531-dis-donc-donald-trump-quoi-exactement-covfefe',
+                $this->getLoggedInUserId()
+            );
+
+        $this->assertContains('foot', $content->getTags());
+        $this->assertContains('test_tag', $content->getTags());
+
+        $this->assertEquals(2, count($content->getTags()));
     }
 
     public function testImportInstapaperWithFileAndMarkAllAsRead()
index 96b32484299ebc0453f8b60b1f0a8c31c632bae9..e2b6e7b6eb1d1f6d14180a7fda4630a394896595 100644 (file)
@@ -121,7 +121,13 @@ class PinboardControllerTest extends WallabagCoreTestCase
         $this->assertNotEmpty($content->getMimetype(), 'Mimetype for https://ma.ttias.be is ok');
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://ma.ttias.be is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for https://ma.ttias.be is ok');
-        $this->assertEquals(3, count($content->getTags()));
+
+        $tags = $content->getTags();
+        $this->assertContains('foot', $tags, 'It includes the "foot" tag');
+        $this->assertContains('varnish', $tags, 'It includes the "varnish" tag');
+        $this->assertContains('PHP', $tags, 'It includes the "PHP" tag');
+        $this->assertEquals(3, count($tags));
+
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
         $this->assertEquals('2016-10-26', $content->getCreatedAt()->format('Y-m-d'));
     }
index e6d33fe99933f4e6735e658edda17c9ff5bf885f..bde0a60011fd1b273f939bad79cc6c64feff453c 100644 (file)
@@ -121,7 +121,11 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
         $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.zataz.com is ok');
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.zataz.com is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.zataz.com is ok');
-        $this->assertEquals(1, count($content->getTags()));
+
+        $tags = $content->getTags();
+        $this->assertContains('foot', $tags, 'It includes the "foot" tag');
+        $this->assertEquals(1, count($tags));
+
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
         $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
     }
index 0c7f97ed6a87ec67dfa422ca54f8e6e456529202..4ca6e623e02251a8076ec00f730697178a0fc541 100644 (file)
@@ -116,20 +116,18 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
                 $this->getLoggedInUserId()
             );
 
-        $tag = $client->getContainer()
-            ->get('doctrine.orm.entity_manager')
-            ->getRepository('WallabagCoreBundle:Tag')
-            ->findOneByLabel('Framabag');
-
-        $this->assertTrue($content->getTags()->contains($tag));
-
         $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
         $this->assertContains('flashes.import.notice.summary', $body[0]);
 
         $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.framablog.org is ok');
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.framablog.org is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.framablog.org is ok');
-        $this->assertEquals(2, count($content->getTags()));
+
+        $tags = $content->getTags();
+        $this->assertContains('foot', $tags, 'It includes the "foot" tag');
+        $this->assertContains('Framabag', $tags, 'It includes the "Framabag" tag');
+        $this->assertEquals(2, count($tags));
+
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
     }
 
index 335115fecfc0ead6595e87d5c132d330bd280185..18a025226c5c3fdad89977cc632bfae44a0fc126 100644 (file)
@@ -122,7 +122,10 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
         $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.liberation.fr is ok');
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.liberation.fr is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.liberation.fr is ok');
-        $this->assertEquals(1, count($content->getTags()));
+
+        $tags = $content->getTags();
+        $this->assertContains('foot', $tags, 'It includes the "foot" tag');
+        $this->assertEquals(1, count($tags));
 
         $content = $client->getContainer()
             ->get('doctrine.orm.entity_manager')
@@ -135,7 +138,13 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
         $this->assertNotEmpty($content->getMimetype(), 'Mimetype for https://www.mediapart.fr is ok');
         $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.mediapart.fr is ok');
         $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.mediapart.fr is ok');
-        $this->assertEquals(3, count($content->getTags()));
+
+        $tags = $content->getTags();
+        $this->assertContains('foot', $tags, 'It includes the "foot" tag');
+        $this->assertContains('mediapart', $tags, 'It includes the "mediapart" tag');
+        $this->assertContains('blog', $tags, 'It includes the "blog" tag');
+        $this->assertEquals(3, count($tags));
+
         $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
         $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
         $this->assertTrue($content->isStarred(), 'Entry is starred');
index 6777a02e880a7c3e0fb14f4356eedeb067ad0f3b..9158c8a23277f411f3a41f28176aca93ed3b01e7 100644 (file)
@@ -18,6 +18,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
     protected $logHandler;
     protected $contentProxy;
     protected $tagsAssigner;
+    protected $uow;
 
     private function getInstapaperImport($unsetUser = false, $dispatched = 0)
     {
@@ -27,6 +28,20 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
             ->disableOriginalConstructor()
             ->getMock();
 
+        $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $this->em
+            ->expects($this->any())
+            ->method('getUnitOfWork')
+            ->willReturn($this->uow);
+
+        $this->uow
+            ->expects($this->any())
+            ->method('getScheduledEntityInsertions')
+            ->willReturn([]);
+
         $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
             ->disableOriginalConstructor()
             ->getMock();
@@ -67,14 +82,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
 
     public function testImport()
     {
-        $instapaperImport = $this->getInstapaperImport(false, 3);
+        $instapaperImport = $this->getInstapaperImport(false, 4);
         $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
 
         $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
             ->disableOriginalConstructor()
             ->getMock();
 
-        $entryRepo->expects($this->exactly(3))
+        $entryRepo->expects($this->exactly(4))
             ->method('findByUrlAndUserId')
             ->willReturn(false);
 
@@ -88,14 +103,14 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
             ->getMock();
 
         $this->contentProxy
-            ->expects($this->exactly(3))
+            ->expects($this->exactly(4))
             ->method('updateEntry')
             ->willReturn($entry);
 
         $res = $instapaperImport->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $instapaperImport->getSummary());
     }
 
     public function testImportAndMarkAllAsRead()
@@ -107,9 +122,9 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
             ->disableOriginalConstructor()
             ->getMock();
 
-        $entryRepo->expects($this->exactly(3))
+        $entryRepo->expects($this->exactly(4))
             ->method('findByUrlAndUserId')
-            ->will($this->onConsecutiveCalls(false, true, true));
+            ->will($this->onConsecutiveCalls(false, true, true, true));
 
         $this->em
             ->expects($this->any())
@@ -133,7 +148,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
 
         $this->assertTrue($res);
 
-        $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary());
+        $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary());
     }
 
     public function testImportWithRabbit()
@@ -165,7 +180,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
             ->getMock();
 
         $producer
-            ->expects($this->exactly(3))
+            ->expects($this->exactly(4))
             ->method('publish');
 
         $instapaperImport->setProducer($producer);
@@ -173,7 +188,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
         $res = $instapaperImport->setMarkAsRead(true)->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary());
     }
 
     public function testImportWithRedis()
@@ -211,7 +226,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
         $res = $instapaperImport->setMarkAsRead(true)->import();
 
         $this->assertTrue($res);
-        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary());
+        $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $instapaperImport->getSummary());
 
         $this->assertNotEmpty($redisMock->lpop('instapaper'));
     }
index 28a4c8e67ea83a773a79d725bd1175e93494e43b..1a648f8aa933010633f78cf47c270878b6004a20 100644 (file)
@@ -2,3 +2,4 @@ URL,Title,Selection,Folder
 http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551,Baumettes : un tour en cellule,,Unread
 https://redditblog.com/2016/09/20/amp-and-reactredux/,AMP and React+Redux: Why Not?,,Archive
 https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c,Why Foursquare / Swarm is still my favourite social network,,Starred
+http://www.20minutes.fr/high-tech/2077615-20170531-dis-donc-donald-trump-quoi-exactement-covfefe,"Dis donc Donald Trump, c'est quoi exactement «covfefe»?",,test_tag