From 1267905d283afc8a0140da007d8428d533964839 Mon Sep 17 00:00:00 2001 From: Maxime Marinel Date: Wed, 3 May 2017 11:08:56 +0200 Subject: [PATCH 1/2] Disable negative numbers in filters --- src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index ee66c728a..ab27ec8e3 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Form\Type; use Doctrine\ORM\EntityRepository; +use Lexik\Bundle\FormFilterBundle\Filter\FilterOperands; use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface; use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\NumberRangeFilterType; use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\DateRangeFilterType; @@ -41,6 +42,8 @@ class EntryFilterType extends AbstractType { $builder ->add('readingTime', NumberRangeFilterType::class, [ + 'left_number_options' => ['condition_operator' => FilterOperands::OPERATOR_GREATER_THAN_EQUAL, 'attr' => ['min' => 0]], + 'right_number_options' => ['condition_operator' => FilterOperands::OPERATOR_LOWER_THAN_EQUAL, 'attr' => ['min' => 0]], 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { $lower = $values['value']['left_number'][0]; $upper = $values['value']['right_number'][0]; From 1b1647175d7eaa2800a2eff9f984ef37e9976fba Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 9 May 2017 12:12:23 +0200 Subject: [PATCH 2/2] Add some tests --- .../CoreBundle/Form/Type/EntryFilterType.php | 12 ++++++++--- .../Controller/EntryControllerTest.php | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index ab27ec8e3..556578d1a 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -34,7 +34,7 @@ class EntryFilterType extends AbstractType $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null; if (null === $this->user || !is_object($this->user)) { - return null; + return; } } @@ -42,8 +42,14 @@ class EntryFilterType extends AbstractType { $builder ->add('readingTime', NumberRangeFilterType::class, [ - 'left_number_options' => ['condition_operator' => FilterOperands::OPERATOR_GREATER_THAN_EQUAL, 'attr' => ['min' => 0]], - 'right_number_options' => ['condition_operator' => FilterOperands::OPERATOR_LOWER_THAN_EQUAL, 'attr' => ['min' => 0]], + 'left_number_options' => [ + 'condition_operator' => FilterOperands::OPERATOR_GREATER_THAN_EQUAL, + 'attr' => ['min' => 0], + ], + 'right_number_options' => [ + 'condition_operator' => FilterOperands::OPERATOR_LOWER_THAN_EQUAL, + 'attr' => ['min' => 0], + ], 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { $lower = $values['value']['left_number'][0]; $upper = $values['value']['right_number'][0]; diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 3eb6d47fb..7db4cf1ff 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -591,6 +591,26 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('div[class=entry]')); } + public function testFilterOnReadingTimeWithNegativeValue() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = [ + 'entry_filter[readingTime][right_number]' => -22, + 'entry_filter[readingTime][left_number]' => -22, + ]; + + $crawler = $client->submit($form, $data); + + // forcing negative value results in no entry displayed + $this->assertCount(0, $crawler->filter('div[class=entry]')); + } + public function testFilterOnReadingTimeOnlyUpper() { $this->logInAs('admin');