From: Nicolas LÅ“uillet Date: Wed, 31 May 2017 10:32:09 +0000 (+0200) Subject: Merge pull request #3168 from wallabag/instapaper-tags-import X-Git-Tag: 2.3.0~31^2~80 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=4423b88c5b2c2d530b0a83a822f521a61ca4d4b8;hp=bad7df8c0048285e7a6bd539e5e501ce6675d663;p=github%2Fwallabag%2Fwallabag.git Merge pull request #3168 from wallabag/instapaper-tags-import Add support for tag in Instapaper import --- diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index fb6a720b..736eb1dc 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -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); } diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 08a67c34..9a7dd4e7 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -550,7 +550,7 @@ class Entry } /** - * @return ArrayCollection + * @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 */ diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index c712bb26..1c56fa9f 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php @@ -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) { diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index f78b7fe0..abc84d08 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -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'); } diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php index add27db2..509d0dec 100644 --- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php @@ -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) { diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 122a87d4..71c2ffc6 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -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()); diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index c3b22dcd..80611a87 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -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()); diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 0539f20a..f420d06a 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -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); + } }