From a42f38d9fb7906b785285fab2a09f8c2b9efe996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 6 Nov 2016 12:02:39 +0100 Subject: [PATCH 01/10] Added a configuration to define the redirection after archiving an entry Fix #496 --- .../Version20161106113822.php | 42 +++++++++++++++++++ docs/de/user/configuration.rst | 9 ++++ docs/en/user/configuration.rst | 9 ++++ docs/fr/user/configuration.rst | 9 ++++ .../DataFixtures/ORM/LoadConfigData.php | 3 ++ src/Wallabag/CoreBundle/Entity/Config.php | 27 ++++++++++++ .../CoreBundle/Form/Type/ConfigType.php | 7 ++++ src/Wallabag/CoreBundle/Helper/Redirect.php | 9 +++- .../CoreBundle/Resources/config/services.yml | 1 + .../Resources/translations/messages.da.yml | 4 ++ .../Resources/translations/messages.de.yml | 4 ++ .../Resources/translations/messages.en.yml | 4 ++ .../Resources/translations/messages.es.yml | 4 ++ .../Resources/translations/messages.fa.yml | 4 ++ .../Resources/translations/messages.fr.yml | 4 ++ .../Resources/translations/messages.it.yml | 4 ++ .../Resources/translations/messages.oc.yml | 4 ++ .../Resources/translations/messages.pl.yml | 4 ++ .../Resources/translations/messages.pt.yml | 4 ++ .../Resources/translations/messages.ro.yml | 4 ++ .../Resources/translations/messages.tr.yml | 4 ++ .../views/themes/baggy/Config/index.html.twig | 8 ++++ .../themes/material/Config/index.html.twig | 8 ++++ .../Controller/ConfigControllerTest.php | 1 + .../CoreBundle/Helper/DownloadImagesTest.php | 1 - .../CoreBundle/Helper/RedirectTest.php | 5 ++- 26 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 app/DoctrineMigrations/Version20161106113822.php diff --git a/app/DoctrineMigrations/Version20161106113822.php b/app/DoctrineMigrations/Version20161106113822.php new file mode 100644 index 000000000..41e64a4a1 --- /dev/null +++ b/app/DoctrineMigrations/Version20161106113822.php @@ -0,0 +1,42 @@ +container = $container; + } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix') . $tableName; + } + + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + $this->addSql('ALTER TABLE "'.$this->getTable('config').'" ADD action_mark_as_read INT DEFAULT 0'); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); + + $this->addSql('ALTER TABLE "'.$this->getTable('config').'" DROP action_mark_as_read'); + } +} diff --git a/docs/de/user/configuration.rst b/docs/de/user/configuration.rst index 0b0793b11..7596a1d3c 100644 --- a/docs/de/user/configuration.rst +++ b/docs/de/user/configuration.rst @@ -28,6 +28,15 @@ Lesegeschwindigkeit wallabag berechnet die Lesezeit für jeden Artikel. Du kannst hier definieren, dank dieser Liste, ob du ein schneller oder langsamer Leser bist. wallabag wird die Lesezeit für jeden Artikel neu berechnen. +Where do you want to be redirected after mark an article as read? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Each time you'll do some actions (after marking an article as read/favorite, +after deleting an article, after removing a tag from an entry), you can be redirected: + +- To the homepage +- To the current page + Sprache ~~~~~~~ diff --git a/docs/en/user/configuration.rst b/docs/en/user/configuration.rst index e7055a145..e16af12c3 100644 --- a/docs/en/user/configuration.rst +++ b/docs/en/user/configuration.rst @@ -27,6 +27,15 @@ Reading speed wallabag calculates a reading time for each article. You can define here, thanks to this list, if you are a fast or a slow reader. wallabag will recalculate the reading time for each article. +Where do you want to be redirected after mark an article as read? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Each time you'll do some actions (after marking an article as read/favorite, +after deleting an article, after removing a tag from an entry), you can be redirected: + +- To the homepage +- To the current page + Language ~~~~~~~~ diff --git a/docs/fr/user/configuration.rst b/docs/fr/user/configuration.rst index 90eece112..c533b5c5d 100644 --- a/docs/fr/user/configuration.rst +++ b/docs/fr/user/configuration.rst @@ -27,6 +27,15 @@ Vitesse de lecture wallabag calcule une durée de lecture pour chaque article. Vous pouvez définir ici, grâce à cette liste déroulante, si vous lisez plus ou moins vite. wallabag recalculera la durée de lecture de chaque article. +Où souhaitez-vous être redirigé après avoir marqué un article comme lu ? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Chaque fois que vous ferez certaines actions (après avoir marqué un article comme lu / comme favori, +après avoir supprimé un article, après avoir retiré un tag d'un article), vous pouvez être redirigé : + +- sur la page d'accueil +- sur la page courante + Langue ~~~~~~ diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php index 921c739ff..453580227 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadConfigData.php @@ -21,6 +21,7 @@ class LoadConfigData extends AbstractFixture implements OrderedFixtureInterface $adminConfig->setReadingSpeed(1); $adminConfig->setLanguage('en'); $adminConfig->setPocketConsumerKey('xxxxx'); + $adminConfig->setActionMarkAsRead(0); $manager->persist($adminConfig); @@ -32,6 +33,7 @@ class LoadConfigData extends AbstractFixture implements OrderedFixtureInterface $bobConfig->setReadingSpeed(1); $bobConfig->setLanguage('fr'); $bobConfig->setPocketConsumerKey(null); + $bobConfig->setActionMarkAsRead(1); $manager->persist($bobConfig); @@ -43,6 +45,7 @@ class LoadConfigData extends AbstractFixture implements OrderedFixtureInterface $emptyConfig->setReadingSpeed(1); $emptyConfig->setLanguage('en'); $emptyConfig->setPocketConsumerKey(null); + $emptyConfig->setActionMarkAsRead(0); $manager->persist($emptyConfig); diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index d0f0e3f38..c40d1535f 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -87,6 +87,13 @@ class Config */ private $pocketConsumerKey; + /** + * @var int + * + * @ORM\Column(name="action_mark_as_read", type="integer", nullable=true) + */ + private $actionMarkAsRead; + /** * @ORM\OneToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="config") */ @@ -309,6 +316,26 @@ class Config return $this->pocketConsumerKey; } + /** + * @return int + */ + public function getActionMarkAsRead() + { + return $this->actionMarkAsRead; + } + + /** + * @param int $actionMarkAsRead + * + * @return Config + */ + public function setActionMarkAsRead($actionMarkAsRead) + { + $this->actionMarkAsRead = $actionMarkAsRead; + + return $this; + } + /** * @param TaggingRule $rule * diff --git a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php index 0bac28740..3b1a80269 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php +++ b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php @@ -48,6 +48,13 @@ class ConfigType extends AbstractType 'config.form_settings.reading_speed.400_word' => '2', ], ]) + ->add('action_mark_as_read', ChoiceType::class, [ + 'label' => 'config.form_settings.action_mark_as_read.label', + 'choices' => [ + 'config.form_settings.action_mark_as_read.redirect_homepage' => '0', + 'config.form_settings.action_mark_as_read.redirect_current_page' => '1', + ], + ]) ->add('language', ChoiceType::class, [ 'choices' => array_flip($this->languages), 'label' => 'config.form_settings.language_label', diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index c14c79d11..918d92661 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Helper; use Symfony\Component\Routing\Router; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; /** * Manage redirections to avoid redirecting to empty routes. @@ -10,10 +11,12 @@ use Symfony\Component\Routing\Router; class Redirect { private $router; + private $actionMarkAsRead; - public function __construct(Router $router) + public function __construct(Router $router, TokenStorage $token) { $this->router = $router; + $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead(); } /** @@ -24,6 +27,10 @@ class Redirect */ public function to($url, $fallback = '') { + if ($this->actionMarkAsRead == 0) { + return $this->router->generate('homepage'); + } + if (null !== $url) { return $url; } diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 9786ac279..dad9bd421 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -109,6 +109,7 @@ services: class: Wallabag\CoreBundle\Helper\Redirect arguments: - "@router" + - "@security.token_storage" wallabag_core.helper.prepare_pager_for_entries: class: Wallabag\CoreBundle\Helper\PreparePagerForEntries diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index b66aa3ea5..c24c59653 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -70,6 +70,10 @@ config: # 200_word: 'I read ~200 words per minute' # 300_word: 'I read ~300 words per minute' # 400_word: 'I read ~400 words per minute' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' pocket_consumer_key_label: Brugers nøgle til Pocket for at importere materialer # android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 9e19dcc4a..1b0bc026b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -70,6 +70,10 @@ config: 200_word: 'Ich lese ~200 Wörter pro Minute' 300_word: 'Ich lese ~300 Wörter pro Minute' 400_word: 'Ich lese ~400 Wörter pro Minute' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' pocket_consumer_key_label: Consumer-Key für Pocket, um Inhalte zu importieren # android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 7516bbd5c..b11dc778a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -70,6 +70,10 @@ config: 200_word: 'I read ~200 words per minute' 300_word: 'I read ~300 words per minute' 400_word: 'I read ~400 words per minute' + action_mark_as_read: + label: 'Where do you want to be redirected after mark an article as read?' + redirect_homepage: 'To the homepage' + redirect_current_page: 'To the current page' pocket_consumer_key_label: Consumer key for Pocket to import contents android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 208982d9b..15d0c3cf0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -70,6 +70,10 @@ config: 200_word: 'Leo ~200 palabras por minuto' 300_word: 'Leo ~300 palabras por minuto' 400_word: 'Leo ~400 palabras por minuto' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' # pocket_consumer_key_label: Consumer key for Pocket to import contents # android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index c443b21c5..e7fa4f866 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -70,6 +70,10 @@ config: 200_word: 'من تقریباً ۲۰۰ واژه را در دقیقه می‌خوانم' 300_word: 'من تقریباً ۳۰۰ واژه را در دقیقه می‌خوانم' 400_word: 'من تقریباً ۴۰۰ واژه را در دقیقه می‌خوانم' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' pocket_consumer_key_label: کلید کاربری Pocket برای درون‌ریزی مطالب # android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index ea759dd30..f85a797d1 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -70,6 +70,10 @@ config: 200_word: "Je lis environ 200 mots par minute" 300_word: "Je lis environ 300 mots par minute" 400_word: "Je lis environ 400 mots par minute" + action_mark_as_read: + label: 'Où souhaitez-vous être redirigé après avoir marqué un article comme lu ?' + redirect_homepage: "À la page d'accueil" + redirect_current_page: 'À la page courante' pocket_consumer_key_label: Clé d’authentification Pocket pour importer les données android_configuration: Configurez votre application Android form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index b3bc573bd..8a8469d2c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -70,6 +70,10 @@ config: 200_word: 'Leggo ~200 parole al minuto' 300_word: 'Leggo ~300 parole al minuto' 400_word: 'Leggo ~400 parole al minuto' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' pocket_consumer_key_label: Consumer key per Pocket per importare i contenuti # android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 97b5f4a9f..d37dc724e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -70,6 +70,10 @@ config: 200_word: "Legissi a l'entorn de 200 mots per minuta" 300_word: "Legissi a l'entorn de 300 mots per minuta" 400_word: "Legissi a l'entorn de 400 mots per minuta" + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' pocket_consumer_key_label: Clau d'autentificacion Pocket per importar las donadas android_configuration: Configuratz vòstra aplicacion Android form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index b4212b830..117a1e127 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -70,6 +70,10 @@ config: 200_word: 'Czytam ~200 słów na minutę' 300_word: 'Czytam ~300 słów na minutę' 400_word: 'Czytam ~400 słów na minutę' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' pocket_consumer_key_label: 'Klucz klienta Pocket do importu zawartości' android_configuration: Skonfiguruj swoją androidową aplikację form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index d8fc9d5c6..5d2607af5 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -70,6 +70,10 @@ config: 200_word: 'Posso ler ~200 palavras por minuto' 300_word: 'Posso ler ~300 palavras por minuto' 400_word: 'Posso ler ~400 palavras por minuto' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' pocket_consumer_key_label: 'Chave do consumidor do Pocket para importar conteúdo' # android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index d130e431f..6b51d9ceb 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -70,6 +70,10 @@ config: # 200_word: 'I read ~200 words per minute' # 300_word: 'I read ~300 words per minute' # 400_word: 'I read ~400 words per minute' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' pocket_consumer_key_label: Cheie consumator pentru importarea contentului din Pocket # android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index f67d8beec..9c3924336 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -70,6 +70,10 @@ config: # 200_word: 'I read ~200 words per minute' # 300_word: 'I read ~300 words per minute' # 400_word: 'I read ~400 words per minute' + action_mark_as_read: + # label: 'Where do you to be redirected after mark an article as read?' + # redirect_homepage: 'To the homepage' + # redirect_current_page: 'To the current page' # pocket_consumer_key_label: Consumer key for Pocket to import contents # android_configuration: Configure your Android application form_rss: diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig index ec3b23c83..4c01b128d 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig @@ -36,6 +36,14 @@ +
+
+ {{ form_label(form.config.action_mark_as_read) }} + {{ form_errors(form.config.action_mark_as_read) }} + {{ form_widget(form.config.action_mark_as_read) }} +
+
+
{{ form_label(form.config.language) }} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index f69d158f4..e774795b9 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -51,6 +51,14 @@
+
+
+ {{ form_label(form.config.action_mark_as_read) }} + {{ form_errors(form.config.action_mark_as_read) }} + {{ form_widget(form.config.action_mark_as_read) }} +
+
+
{{ form_label(form.config.language) }} diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 568576a33..a2863014f 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -51,6 +51,7 @@ class ConfigControllerTest extends WallabagCoreTestCase 'config[theme]' => 'baggy', 'config[items_per_page]' => '30', 'config[reading_speed]' => '0.5', + 'config[action_mark_as_read]' => '0', 'config[language]' => 'en', ]; diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 920c21d99..85f12d87b 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -3,7 +3,6 @@ namespace Tests\Wallabag\CoreBundle\Helper; use Wallabag\CoreBundle\Helper\DownloadImages; -use Psr\Log\NullLogger; use Monolog\Logger; use Monolog\Handler\TestHandler; use GuzzleHttp\Client; diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index f339f75e8..825e8d53f 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -15,7 +15,10 @@ class RedirectTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->routerMock = $this->getRouterMock(); - $this->redirect = new Redirect($this->routerMock); + $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->redirect = new Redirect($this->routerMock, $tokenStorage); } public function testRedirectToNullWithFallback() From 5d52cc411bdccab59b3b53d96ccf8ece8afbdb2b Mon Sep 17 00:00:00 2001 From: Strubbl Date: Sun, 6 Nov 2016 20:40:19 +0100 Subject: [PATCH 02/10] update German configuration.rst --- docs/de/user/configuration.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/de/user/configuration.rst b/docs/de/user/configuration.rst index 7596a1d3c..075a52909 100644 --- a/docs/de/user/configuration.rst +++ b/docs/de/user/configuration.rst @@ -28,14 +28,13 @@ Lesegeschwindigkeit wallabag berechnet die Lesezeit für jeden Artikel. Du kannst hier definieren, dank dieser Liste, ob du ein schneller oder langsamer Leser bist. wallabag wird die Lesezeit für jeden Artikel neu berechnen. -Where do you want to be redirected after mark an article as read? +Wohin möchtest du weitergeleitet werden, nach dem ein Artikel als gelesen markiert wurde? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Each time you'll do some actions (after marking an article as read/favorite, -after deleting an article, after removing a tag from an entry), you can be redirected: +Jedes Mal, wenn du eine Aktion ausführst (nach dem Markieren eines Artikels als gelesen oder Favorit, nach dem Löschen eines Artikels oder dem Entfernen eines Tag von einem Eintrag), kannst du weitergeleitet werden: -- To the homepage -- To the current page +- zur Homepage +- zur aktuellen Seite Sprache ~~~~~~~ From f0ba37fbd59d3a1cb294b61e7514b059751cc2c0 Mon Sep 17 00:00:00 2001 From: Strubbl Date: Sun, 6 Nov 2016 21:10:20 +0100 Subject: [PATCH 03/10] Update messages.de.yml --- .../Resources/translations/messages.de.yml | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 1b0bc026b..561d276e5 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -71,11 +71,11 @@ config: 300_word: 'Ich lese ~300 Wörter pro Minute' 400_word: 'Ich lese ~400 Wörter pro Minute' action_mark_as_read: - # label: 'Where do you to be redirected after mark an article as read?' - # redirect_homepage: 'To the homepage' - # redirect_current_page: 'To the current page' + label: 'Wohin soll nach dem Gelesenmarkieren eines Artikels weitergeleitet werden?' + redirect_homepage: 'Zur Homepage' + redirect_current_page: 'Zur aktuellen Seite' pocket_consumer_key_label: Consumer-Key für Pocket, um Inhalte zu importieren - # android_configuration: Configure your Android application + android_configuration: Konfiguriere deine Android Application form_rss: description: 'Die RSS-Feeds von wallabag erlauben es dir, deine gespeicherten Artikel mit deinem bevorzugten RSS-Reader zu lesen. Vorher musst du jedoch einen Token erstellen.' token_label: 'RSS-Token' @@ -94,17 +94,17 @@ config: email_label: 'E-Mail-Adresse' twoFactorAuthentication_label: 'Zwei-Faktor-Authentifizierung' delete: - # title: Delete my account (a.k.a danger zone) - # description: If you remove your account, ALL your articles, ALL your tags, ALL your annotations and your account will be PERMANENTLY removed (it can't be UNDONE). You'll then be logged out. - # confirm: Are you really sure? (THIS CAN'T BE UNDONE) - # button: Delete my account + title: Lösche mein Konto (a.k.a Gefahrenzone) + description: Wenn du dein Konto löschst, werden ALL deine Artikel, ALL deine Tags, ALL deine Anmerkungen und dein Konto dauerhaft gelöscht (kann NICHT RÜCKGÄNGIG gemacht werden). Du wirst anschließend ausgeloggt. + confirm: Bist du wirklich sicher? (DIES KANN NICHT RÜCKGÄNGIG GEMACHT WERDEN) + button: Lösche mein Konto reset: - # title: Reset area (a.k.a danger zone) - # description: By hiting buttons below you'll have ability to remove some informations from your account. Be aware that these actions are IRREVERSIBLE. - # annotations: Remove ALL annotations - # tags: Remove ALL tags - # entries: Remove ALL entries - # confirm: Are you really really sure? (THIS CAN'T BE UNDONE) + title: Zurücksetzen (a.k.a Gefahrenzone) + description: Beim Nutzen der folgenden Schaltflächenhast du die Möglichkeit, einige Informationen von deinem Konto zu entfernen. Sei dir bewusst, dass dies NICHT RÜCKGÄNGIG zu machen ist. + annotations: Entferne ALLE Annotationen + tags: Entferne ALLE Tags + entries: Entferne ALLE Einträge + confirm: Bist du wirklich sicher? (DIES KANN NICHT RÜCKGÄNGIG GEMACHT WERDEN) form_password: old_password_label: 'Altes Kennwort' new_password_label: 'Neues Kennwort' @@ -375,7 +375,7 @@ import: how_to: 'Bitte wähle deinen Readability Export aus und klicke den unteren Button für das Hochladen und Importieren dessen.' worker: enabled: "Der Import erfolgt asynchron. Sobald der Import gestartet ist, wird diese Aufgabe extern abgearbeitet. Der aktuelle Service dafür ist:" - # download_images_warning: "You enabled downloading images for your articles. Combined with classic import it can take ages to proceed (or maybe failed). We strongly recommend to enable asynchronous import to avoid errors." + download_images_warning: "Du hast das Herunterladen von Bildern für deine Artikel aktiviert. Verbunden mit dem klassischen Import kann es ewig dauern fortzufahren (oder sogar fehlschlagen). Wir empfehlen den asynchronen Import zu aktivieren, um Fehler zu vermeiden." firefox: page_title: 'Aus Firefox importieren' description: "Dieser Import wird all deine Lesezeichen aus Firefox importieren. Gehe zu deinen Lesezeichen (Strg+Shift+O), dann auf \"Importen und Sichern\", wähle \"Sichern…\". Du erhälst eine .json Datei." @@ -471,7 +471,7 @@ user: back_to_list: Zurück zur Liste error: - # page_title: An error occurred + page_title: Ein Fehler ist aufgetreten flashes: config: @@ -484,9 +484,9 @@ flashes: tagging_rules_updated: 'Tagging-Regeln aktualisiert' tagging_rules_deleted: 'Tagging-Regel gelöscht' rss_token_updated: 'RSS-Token aktualisiert' - # annotations_reset: Annotations reset - # tags_reset: Tags reset - # entries_reset: Entries reset + annotations_reset: Anmerkungen zurücksetzen + tags_reset: Tags zurücksetzen + entries_reset: Einträge zurücksetzen entry: notice: entry_already_saved: 'Eintrag bereits am %date% gespeichert' @@ -518,6 +518,6 @@ flashes: client_deleted: 'Client gelöscht' user: notice: - # added: 'User "%username%" added' - # updated: 'User "%username%" updated' - # deleted: 'User "%username%" deleted' + added: 'Benutzer "%username%" hinzugefügt' + updated: 'Benutzer "%username%" aktualisiert' + deleted: 'Benutzer "%username%" gelöscht' From 287204cda72c73e171cd1bf801bc08f7e5d7d111 Mon Sep 17 00:00:00 2001 From: Strubbl Date: Sun, 6 Nov 2016 21:12:25 +0100 Subject: [PATCH 04/10] Update messages.en.yml --- .../CoreBundle/Resources/translations/messages.en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index b11dc778a..ec49368c1 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -100,11 +100,11 @@ config: button: Delete my account reset: title: Reset area (a.k.a danger zone) - description: By hiting buttons below you'll have ability to remove some informations from your account. Be aware that these actions are IRREVERSIBLE. + description: By hitting buttons below you'll have ability to remove some information from your account. Be aware that these actions are IRREVERSIBLE. annotations: Remove ALL annotations tags: Remove ALL tags entries: Remove ALL entries - confirm: Are you really really sure? (THIS CAN'T BE UNDONE) + confirm: Are you really sure? (THIS CAN'T BE UNDONE) form_password: old_password_label: 'Current password' new_password_label: 'New password' From f052f1fd57e51c8ae5ac17587636d608619a2057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 7 Nov 2016 09:30:37 +0100 Subject: [PATCH 05/10] Added constants for redirection values --- src/Wallabag/CoreBundle/Entity/Config.php | 3 +++ src/Wallabag/CoreBundle/Form/Type/ConfigType.php | 5 +++-- src/Wallabag/CoreBundle/Helper/Redirect.php | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index c40d1535f..bfc2fff87 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -16,6 +16,9 @@ use Wallabag\UserBundle\Entity\User; */ class Config { + const REDIRECT_TO_HOMEPAGE = 0; + const REDIRECT_TO_CURRENT_PAGE = 1; + /** * @var int * diff --git a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php index 3b1a80269..7e3b9dd4f 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php +++ b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php @@ -7,6 +7,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Wallabag\CoreBundle\Entity\Config; class ConfigType extends AbstractType { @@ -51,8 +52,8 @@ class ConfigType extends AbstractType ->add('action_mark_as_read', ChoiceType::class, [ 'label' => 'config.form_settings.action_mark_as_read.label', 'choices' => [ - 'config.form_settings.action_mark_as_read.redirect_homepage' => '0', - 'config.form_settings.action_mark_as_read.redirect_current_page' => '1', + 'config.form_settings.action_mark_as_read.redirect_homepage' => Config::REDIRECT_TO_HOMEPAGE, + 'config.form_settings.action_mark_as_read.redirect_current_page' => Config::REDIRECT_TO_CURRENT_PAGE, ], ]) ->add('language', ChoiceType::class, [ diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index 918d92661..59172db40 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Helper; use Symfony\Component\Routing\Router; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Wallabag\CoreBundle\Entity\Config; /** * Manage redirections to avoid redirecting to empty routes. @@ -27,7 +28,7 @@ class Redirect */ public function to($url, $fallback = '') { - if ($this->actionMarkAsRead == 0) { + if (Config::REDIRECT_TO_HOMEPAGE === $this->actionMarkAsRead) { return $this->router->generate('homepage'); } From 65cd8a4a9a1d15d962033f58276005a5f7716f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 7 Nov 2016 10:26:05 +0100 Subject: [PATCH 06/10] Added tests --- src/Wallabag/CoreBundle/Helper/Redirect.php | 15 +++-- .../Controller/EntryControllerTest.php | 65 +++++++++++++++++++ .../CoreBundle/Helper/RedirectTest.php | 4 +- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index 59172db40..82792aec3 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -3,7 +3,7 @@ namespace Wallabag\CoreBundle\Helper; use Symfony\Component\Routing\Router; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\CoreBundle\Entity\Config; /** @@ -12,12 +12,13 @@ use Wallabag\CoreBundle\Entity\Config; class Redirect { private $router; + private $tokenStorage; private $actionMarkAsRead; - public function __construct(Router $router, TokenStorage $token) + public function __construct(Router $router, TokenStorageInterface $tokenStorage) { $this->router = $router; - $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead(); + $this->tokenStorage = $tokenStorage; } /** @@ -28,7 +29,13 @@ class Redirect */ public function to($url, $fallback = '') { - if (Config::REDIRECT_TO_HOMEPAGE === $this->actionMarkAsRead) { + $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; + + if (null === $user || !is_object($user)) { + return $url; + } + + if (Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) { return $this->router->generate('homepage'); } diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 4ab06dbff..bf4e0543f 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -3,6 +3,7 @@ namespace Tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; class EntryControllerTest extends WallabagCoreTestCase @@ -896,4 +897,68 @@ class EntryControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } + + public function testRedirectToHomepage() + { + $this->logInAs('empty'); + $client = $this->getClient(); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->find($this->getLoggedInUserId()); + + if (!$user) { + $this->markTestSkipped('No user found in db.'); + } + + // Redirect to homepage + $config = $user->getConfig(); + $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); + $em->persist($config); + $em->flush(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + + $client->request('GET', '/view/'.$content->getId()); + $client->request('GET', '/archive/'.$content->getId()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertEquals('/', $client->getResponse()->headers->get('location')); + } + + public function testRedirectToCurrentPage() + { + $this->logInAs('empty'); + $client = $this->getClient(); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->find($this->getLoggedInUserId()); + + if (!$user) { + $this->markTestSkipped('No user found in db.'); + } + + // Redirect to current page + $config = $user->getConfig(); + $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); + $em->persist($config); + $em->flush(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + + $client->request('GET', '/view/'.$content->getId()); + $client->request('GET', '/archive/'.$content->getId()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); + } } diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 825e8d53f..a2d6a5245 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -25,14 +25,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase { $redirectUrl = $this->redirect->to(null, 'fallback'); - $this->assertEquals('fallback', $redirectUrl); + $this->assertEquals(null, $redirectUrl); } public function testRedirectToNullWithoutFallback() { $redirectUrl = $this->redirect->to(null); - $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); + $this->assertEquals(null, $redirectUrl); } public function testRedirectToValidUrl() From 54fd55fda1eca050ba10fd41c68251cd2dcd02a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 10 Nov 2016 15:50:10 +0100 Subject: [PATCH 07/10] Tried to fix tests --- src/Wallabag/CoreBundle/Helper/Redirect.php | 1 - .../CoreBundle/Helper/RedirectTest.php | 65 +++++++++++++++++-- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index 82792aec3..f78b7fe0d 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -13,7 +13,6 @@ class Redirect { private $router; private $tokenStorage; - private $actionMarkAsRead; public function __construct(Router $router, TokenStorageInterface $tokenStorage) { diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index a2d6a5245..3dcdf8de6 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -12,12 +12,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase /** @var Redirect */ private $redirect; + const PASSWORD = 's3Cr3t'; + const SALT = '^S4lt$'; + public function setUp() { $this->routerMock = $this->getRouterMock(); - $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') - ->disableOriginalConstructor() - ->getMock(); + $user = $this->createUser(); + $tokenStorage = $this->createTokenStorage($user); $this->redirect = new Redirect($this->routerMock, $tokenStorage); } @@ -25,14 +27,14 @@ class RedirectTest extends \PHPUnit_Framework_TestCase { $redirectUrl = $this->redirect->to(null, 'fallback'); - $this->assertEquals(null, $redirectUrl); + $this->assertEquals('fallback', $redirectUrl); } public function testRedirectToNullWithoutFallback() { $redirectUrl = $this->redirect->to(null); - $this->assertEquals(null, $redirectUrl); + $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); } public function testRedirectToValidUrl() @@ -55,4 +57,57 @@ class RedirectTest extends \PHPUnit_Framework_TestCase return $mock; } + + protected function createTokenStorage($user = null) + { + $token = $this->createAuthenticationToken($user); + + $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') + ->disableOriginalConstructor() + ->getMock(); + + $mock + ->expects($this->any()) + ->method('getToken') + ->will($this->returnValue($token)) + ; + + return $mock; + } + + protected function createUser() + { + $mock = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface') + ->disableOriginalConstructor() + ->getMock(); + + $mock + ->expects($this->any()) + ->method('getPassword') + ->will($this->returnValue(static::PASSWORD)) + ; + + $mock + ->expects($this->any()) + ->method('getSalt') + ->will($this->returnValue(static::SALT)) + ; + + return $mock; + } + + protected function createAuthenticationToken($user = null) + { + $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') + ->disableOriginalConstructor() + ->getMock(); + + $mock + ->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($user)) + ; + + return $mock; + } } From 00bf45b6f291b6d1ce5f6a106e8e15bb1cce411b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 16 Nov 2016 23:07:00 +0100 Subject: [PATCH 08/10] Update unit test for Redirect --- .../CoreBundle/Helper/RedirectTest.php | 104 ++++++++---------- 1 file changed, 43 insertions(+), 61 deletions(-) diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 3dcdf8de6..6aa596448 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -2,7 +2,11 @@ namespace Tests\Wallabag\CoreBundle\Helper; +use Wallabag\CoreBundle\Entity\Config; +use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\Redirect; +use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; class RedirectTest extends \PHPUnit_Framework_TestCase { @@ -17,9 +21,37 @@ class RedirectTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->routerMock = $this->getRouterMock(); - $user = $this->createUser(); - $tokenStorage = $this->createTokenStorage($user); + $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') + ->disableOriginalConstructor() + ->getMock(); + + $this->routerMock->expects($this->any()) + ->method('generate') + ->with('homepage') + ->willReturn('homepage'); + + $user = new User(); + $user->setName('youpi'); + $user->setEmail('youpi@youpi.org'); + $user->setUsername('youpi'); + $user->setPlainPassword('youpi'); + $user->setEnabled(true); + $user->addRole('ROLE_SUPER_ADMIN'); + + $config = new Config($user); + $config->setTheme('material'); + $config->setItemsPerPage(30); + $config->setReadingSpeed(1); + $config->setLanguage('en'); + $config->setPocketConsumerKey('xxxxx'); + $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); + + $user->setConfig($config); + + $this->token = new UsernamePasswordToken($user, 'password', 'key'); + $tokenStorage = new TokenStorage(); + $tokenStorage->setToken($this->token); + $this->redirect = new Redirect($this->routerMock, $tokenStorage); } @@ -44,70 +76,20 @@ class RedirectTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/unread/list', $redirectUrl); } - private function getRouterMock() + public function testWithNotLoggedUser() { - $mock = $this->getMockBuilder('Symfony\Component\Routing\Router') - ->disableOriginalConstructor() - ->getMock(); + $redirect = new Redirect($this->routerMock, new TokenStorage()); + $redirectUrl = $redirect->to('/unread/list'); - $mock->expects($this->any()) - ->method('generate') - ->with('homepage') - ->willReturn('homepage'); - - return $mock; + $this->assertEquals('/unread/list', $redirectUrl); } - protected function createTokenStorage($user = null) + public function testUserForRedirectToHomepage() { - $token = $this->createAuthenticationToken($user); + $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); - $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') - ->disableOriginalConstructor() - ->getMock(); + $redirectUrl = $this->redirect->to('/unread/list'); - $mock - ->expects($this->any()) - ->method('getToken') - ->will($this->returnValue($token)) - ; - - return $mock; - } - - protected function createUser() - { - $mock = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface') - ->disableOriginalConstructor() - ->getMock(); - - $mock - ->expects($this->any()) - ->method('getPassword') - ->will($this->returnValue(static::PASSWORD)) - ; - - $mock - ->expects($this->any()) - ->method('getSalt') - ->will($this->returnValue(static::SALT)) - ; - - return $mock; - } - - protected function createAuthenticationToken($user = null) - { - $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') - ->disableOriginalConstructor() - ->getMock(); - - $mock - ->expects($this->any()) - ->method('getUser') - ->will($this->returnValue($user)) - ; - - return $mock; + $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); } } From e6b133c60cc07e750ed38a1610ec30d3cd8d3189 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 16 Nov 2016 23:10:01 +0100 Subject: [PATCH 09/10] CS --- tests/Wallabag/CoreBundle/Helper/RedirectTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 6aa596448..0539f20a9 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -16,9 +16,6 @@ class RedirectTest extends \PHPUnit_Framework_TestCase /** @var Redirect */ private $redirect; - const PASSWORD = 's3Cr3t'; - const SALT = '^S4lt$'; - public function setUp() { $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') From 9e2440fe15633532c2bf62feac1535a85d6eb840 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 17 Nov 2016 08:05:15 +0100 Subject: [PATCH 10/10] Fix migration --- app/DoctrineMigrations/Version20161106113822.php | 8 +++++--- ...0161109150755.php => Version20161117071626.php} | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) rename app/DoctrineMigrations/{Version20161109150755.php => Version20161117071626.php} (57%) diff --git a/app/DoctrineMigrations/Version20161106113822.php b/app/DoctrineMigrations/Version20161106113822.php index 41e64a4a1..edca54f5d 100644 --- a/app/DoctrineMigrations/Version20161106113822.php +++ b/app/DoctrineMigrations/Version20161106113822.php @@ -4,8 +4,10 @@ namespace Application\Migrations; use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Schema\Schema; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; -class Version20161106113822 extends AbstractMigration +class Version20161106113822 extends AbstractMigration implements ContainerAwareInterface { /** * @var ContainerInterface @@ -27,7 +29,7 @@ class Version20161106113822 extends AbstractMigration */ public function up(Schema $schema) { - $this->addSql('ALTER TABLE "'.$this->getTable('config').'" ADD action_mark_as_read INT DEFAULT 0'); + $this->addSql('ALTER TABLE '.$this->getTable('config').' ADD action_mark_as_read INT DEFAULT 0'); } /** @@ -37,6 +39,6 @@ class Version20161106113822 extends AbstractMigration { $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.'); - $this->addSql('ALTER TABLE "'.$this->getTable('config').'" DROP action_mark_as_read'); + $this->addSql('ALTER TABLE '.$this->getTable('config').' DROP action_mark_as_read'); } } diff --git a/app/DoctrineMigrations/Version20161109150755.php b/app/DoctrineMigrations/Version20161117071626.php similarity index 57% rename from app/DoctrineMigrations/Version20161109150755.php rename to app/DoctrineMigrations/Version20161117071626.php index e4d269c49..9ae55b5f3 100644 --- a/app/DoctrineMigrations/Version20161109150755.php +++ b/app/DoctrineMigrations/Version20161117071626.php @@ -7,34 +7,38 @@ use Doctrine\DBAL\Schema\Schema; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -class Version20161031132655 extends AbstractMigration implements ContainerAwareInterface +class Version20161117071626 extends AbstractMigration implements ContainerAwareInterface { /** * @var ContainerInterface */ private $container; + public function setContainer(ContainerInterface $container = null) { $this->container = $container; } + private function getTable($tableName) { return $this->container->getParameter('database_table_prefix') . $tableName; } + /** * @param Schema $schema */ public function up(Schema $schema) { - $this->addSql("INSERT INTO \"".$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('share_unmark', 0, 'entry')"); - $this->addSql("INSERT INTO \"".$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('unmark_url', 'https://unmark.it', 'entry')"); + $this->addSql("INSERT INTO ".$this->getTable('craue_config_setting')." (name, value, section) VALUES ('share_unmark', 0, 'entry')"); + $this->addSql("INSERT INTO ".$this->getTable('craue_config_setting')." (name, value, section) VALUES ('unmark_url', 'https://unmark.it', 'entry')"); } + /** * @param Schema $schema */ public function down(Schema $schema) { - $this->addSql("DELETE FROM \"".$this->getTable('craue_config_setting')."\" WHERE name = 'share_unmark';"); - $this->addSql("DELETE FROM \"".$this->getTable('craue_config_setting')."\" WHERE name = 'unmark_url';"); + $this->addSql("DELETE FROM ".$this->getTable('craue_config_setting')." WHERE name = 'share_unmark';"); + $this->addSql("DELETE FROM ".$this->getTable('craue_config_setting')." WHERE name = 'unmark_url';"); } }