]> 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

src/Wallabag/CoreBundle/Controller/TagController.php
src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
src/Wallabag/CoreBundle/Helper/Redirect.php
src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
tests/Wallabag/CoreBundle/Helper/RedirectTest.php

index fb6a720b6e9d73d5b2608a505cf36a3a5836ed91..736eb1dc0b33b4e5240938386f097942d5639003 100644 (file)
@@ -70,7 +70,7 @@ class TagController extends Controller
             $em->flush();
         }
 
-        $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
+        $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true);
 
         return $this->redirect($redirectUrl);
     }
index 08a67c34b1f00275b1f61b3cf5bed3b734800560..9a7dd4e7b77e43613e7a1048a847fda7afb724d4 100644 (file)
@@ -550,7 +550,7 @@ class Entry
     }
 
     /**
-     * @return ArrayCollection<Tag>
+     * @return ArrayCollection
      */
     public function getTags()
     {
@@ -685,7 +685,7 @@ class Entry
     }
 
     /**
-     * @return int
+     * @return string
      */
     public function getHttpStatus()
     {
@@ -693,7 +693,7 @@ class Entry
     }
 
     /**
-     * @param int $httpStatus
+     * @param string $httpStatus
      *
      * @return Entry
      */
index c712bb26e2de7c66f487132da00e63e8c718d463..1c56fa9f44279c0fa800abc5726bbd9ad876e043 100644 (file)
@@ -5,7 +5,6 @@ namespace Wallabag\CoreBundle\GuzzleSiteAuthenticator;
 use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig;
 use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder;
 use Graby\SiteConfig\ConfigBuilder;
-use OutOfRangeException;
 use Psr\Log\LoggerInterface;
 
 class GrabySiteConfigBuilder implements SiteConfigBuilder
@@ -38,13 +37,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
     }
 
     /**
-     * Builds the SiteConfig for a host.
-     *
-     * @param string $host The "www." prefix is ignored
-     *
-     * @return SiteConfig
-     *
-     * @throws OutOfRangeException If there is no config for $host
+     * {@inheritdoc}
      */
     public function buildForHost($host)
     {
index f78b7fe0d8b0799879489ec3e48e223b480e1ca3..abc84d089822ab6bf6f8c425f5df6acecddfbe53 100644 (file)
@@ -21,12 +21,13 @@ class Redirect
     }
 
     /**
-     * @param string $url      URL to redirect
-     * @param string $fallback Fallback URL if $url is null
+     * @param string $url                    URL to redirect
+     * @param string $fallback               Fallback URL if $url is null
+     * @param bool   $ignoreActionMarkAsRead Ignore configured action when mark as read
      *
      * @return string
      */
-    public function to($url, $fallback = '')
+    public function to($url, $fallback = '', $ignoreActionMarkAsRead = false)
     {
         $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
 
@@ -34,7 +35,8 @@ class Redirect
             return $url;
         }
 
-        if (Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) {
+        if (!$ignoreActionMarkAsRead &&
+              Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) {
             return $this->router->generate('homepage');
         }
 
index add27db2b4ea0741a06fe1a70dc2ee928a307ca9..509d0dec9c2b70b53b7da3e5822462cd17354af7 100644 (file)
@@ -15,6 +15,7 @@ class RuleBasedTagger
     private $rulerz;
     private $tagRepository;
     private $entryRepository;
+    private $logger;
 
     public function __construct(RulerZ $rulerz, TagRepository $tagRepository, EntryRepository $entryRepository, LoggerInterface $logger)
     {
index 122a87d400239c53f6c83ab9ec790ee02154824c..71c2ffc633917c74a5d00016cd30d704932c1f5c 100644 (file)
@@ -67,18 +67,14 @@ class InstallCommandTest extends WallabagCoreTestCase
 
         $command = $application->find('wallabag:install');
 
-        // We mock the QuestionHelper
-        $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
-            ->disableOriginalConstructor()
-            ->getMock();
-        $question->expects($this->any())
-            ->method('ask')
-            ->will($this->returnValue('yes_'.uniqid('', true)));
-
-        // We override the standard helper with our mock
-        $command->getHelperSet()->set($question, 'question');
-
         $tester = new CommandTester($command);
+        $tester->setInputs([
+            'y', // dropping database
+            'y', // create super admin
+            'username_'.uniqid('', true), // username
+            'password_'.uniqid('', true), // password
+            'email_'.uniqid('', true).'@wallabag.it', // email
+        ]);
         $tester->execute([
             'command' => $command->getName(),
         ]);
@@ -97,18 +93,13 @@ class InstallCommandTest extends WallabagCoreTestCase
 
         $command = $application->find('wallabag:install');
 
-        // We mock the QuestionHelper
-        $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
-            ->disableOriginalConstructor()
-            ->getMock();
-        $question->expects($this->any())
-            ->method('ask')
-            ->will($this->returnValue('yes_'.uniqid('', true)));
-
-        // We override the standard helper with our mock
-        $command->getHelperSet()->set($question, 'question');
-
         $tester = new CommandTester($command);
+        $tester->setInputs([
+            'y', // create super admin
+            'username_'.uniqid('', true), // username
+            'password_'.uniqid('', true), // password
+            'email_'.uniqid('', true).'@wallabag.it', // email
+        ]);
         $tester->execute([
             'command' => $command->getName(),
             '--reset' => true,
@@ -150,18 +141,13 @@ class InstallCommandTest extends WallabagCoreTestCase
 
         $command = $application->find('wallabag:install');
 
-        // We mock the QuestionHelper
-        $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
-            ->disableOriginalConstructor()
-            ->getMock();
-        $question->expects($this->any())
-            ->method('ask')
-            ->will($this->returnValue('yes_'.uniqid('', true)));
-
-        // We override the standard helper with our mock
-        $command->getHelperSet()->set($question, 'question');
-
         $tester = new CommandTester($command);
+        $tester->setInputs([
+            'y', // create super admin
+            'username_'.uniqid('', true), // username
+            'password_'.uniqid('', true), // password
+            'email_'.uniqid('', true).'@wallabag.it', // email
+        ]);
         $tester->execute([
             'command' => $command->getName(),
         ]);
@@ -183,23 +169,12 @@ class InstallCommandTest extends WallabagCoreTestCase
 
         $command = $application->find('wallabag:install');
 
-        // We mock the QuestionHelper
-        $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
-            ->disableOriginalConstructor()
-            ->getMock();
-
-        $question->expects($this->exactly(3))
-            ->method('ask')
-            ->will($this->onConsecutiveCalls(
-                false, // don't want to reset the entire database
-                true, // do want to reset the schema
-                false // don't want to create a new user
-            ));
-
-        // We override the standard helper with our mock
-        $command->getHelperSet()->set($question, 'question');
-
         $tester = new CommandTester($command);
+        $tester->setInputs([
+            'n', // don't want to reset the entire database
+            'y', // do want to reset the schema
+            'n', // don't want to create a new user
+        ]);
         $tester->execute([
             'command' => $command->getName(),
         ]);
@@ -239,22 +214,11 @@ class InstallCommandTest extends WallabagCoreTestCase
 
         $command = $application->find('wallabag:install');
 
-        // We mock the QuestionHelper
-        $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
-            ->disableOriginalConstructor()
-            ->getMock();
-
-        $question->expects($this->exactly(2))
-            ->method('ask')
-            ->will($this->onConsecutiveCalls(
-                false, // don't want to reset the entire database
-                false // don't want to create a new user
-            ));
-
-        // We override the standard helper with our mock
-        $command->getHelperSet()->set($question, 'question');
-
         $tester = new CommandTester($command);
+        $tester->setInputs([
+            'n', // don't want to reset the entire database
+            'n', // don't want to create a new user
+        ]);
         $tester->execute([
             'command' => $command->getName(),
         ]);
@@ -275,21 +239,11 @@ class InstallCommandTest extends WallabagCoreTestCase
 
         $command = $application->find('wallabag:install');
 
-        // We mock the QuestionHelper
-        $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
-            ->disableOriginalConstructor()
-            ->getMock();
-        $question->expects($this->any())
-            ->method('ask')
-            ->will($this->returnValue('yes_'.uniqid('', true)));
-
-        // We override the standard helper with our mock
-        $command->getHelperSet()->set($question, 'question');
-
         $tester = new CommandTester($command);
         $tester->execute([
             'command' => $command->getName(),
-            '--no-interaction' => true,
+        ], [
+            'interactive' => false,
         ]);
 
         $this->assertContains('Checking system requirements.', $tester->getDisplay());
index c3b22dcd2c41fb2aa148ed09ca6e43ffe77bd804..80611a87c2010549a31d6672fce7aaf7b654df1c 100644 (file)
@@ -126,9 +126,19 @@ class TagControllerTest extends WallabagCoreTestCase
             ->getRepository('WallabagCoreBundle:Tag')
             ->findOneByEntryAndTagLabel($entry, $this->tagName);
 
+        // We make a first request to set an history and test redirection after tag deletion
+        $client->request('GET', '/view/'.$entry->getId());
+        $entryUri = $client->getRequest()->getUri();
         $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
 
         $this->assertEquals(302, $client->getResponse()->getStatusCode());
+        $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl());
+
+        // re-retrieve the entry to be sure to get fresh data from database (mostly for tags)
+        $entry = $client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
 
         $this->assertNotContains($this->tagName, $entry->getTags());
 
index 0539f20a90ddcffd5c24d12e1e25dd9df9eb54f6..f420d06aefd6293b73807d3952208c0b5c0dbc4e 100644 (file)
@@ -89,4 +89,22 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
 
         $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl);
     }
+
+    public function testUserForRedirectWithIgnoreActionMarkAsRead()
+    {
+        $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
+
+        $redirectUrl = $this->redirect->to('/unread/list', '', true);
+
+        $this->assertEquals('/unread/list', $redirectUrl);
+    }
+
+    public function testUserForRedirectNullWithFallbackWithIgnoreActionMarkAsRead()
+    {
+        $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
+
+        $redirectUrl = $this->redirect->to(null, 'fallback', true);
+
+        $this->assertEquals('fallback', $redirectUrl);
+    }
 }