]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add some tests 3076/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 9 May 2017 10:12:23 +0000 (12:12 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 9 May 2017 10:12:23 +0000 (12:12 +0200)
src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php

index ab27ec8e3407486671a151b8bf69110d34d0cffd..556578d1a7bf6cc896d2888a07dd70c503a85c26 100644 (file)
@@ -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];
index 3eb6d47fb9feb875dd45053801f100515beabf7a..7db4cf1ff46aef5e7efa84bba45f32211a3c387e 100644 (file)
@@ -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');