aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-06-23 11:38:10 +0200
committerGitHub <noreply@github.com>2016-06-23 11:38:10 +0200
commitfb5c17a9ab5e10b1de9caa50e73638fdae19cb78 (patch)
tree2ac9d53e2c5c88f60121f7b366322e256147eae1
parentbf27f99d546b74c3690e8b228c73e609b2d409de (diff)
parent95859e54c512ec4a3ee1c28404981f5c4b9481df (diff)
downloadwallabag-fb5c17a9ab5e10b1de9caa50e73638fdae19cb78.tar.gz
wallabag-fb5c17a9ab5e10b1de9caa50e73638fdae19cb78.tar.zst
wallabag-fb5c17a9ab5e10b1de9caa50e73638fdae19cb78.zip
Merge pull request #2157 from wallabag/lower-upper-readingtime
Handle only upper or only lower reading filter
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php23
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php36
2 files changed, 52 insertions, 7 deletions
diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
index bc59c9a1..3c597b5d 100644
--- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
+++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
@@ -36,17 +36,26 @@ class EntryFilterType extends AbstractType
36 $builder 36 $builder
37 ->add('readingTime', NumberRangeFilterType::class, [ 37 ->add('readingTime', NumberRangeFilterType::class, [
38 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { 38 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
39 $value = $values['value']; 39 $lower = $values['value']['left_number'][0];
40 $upper = $values['value']['right_number'][0];
41
42 $min = (int) ($lower * $this->user->getConfig()->getReadingSpeed());
43 $max = (int) ($upper * $this->user->getConfig()->getReadingSpeed());
40 44
41 if (null === $value['left_number'][0] || null === $value['right_number'][0]) { 45 if (null === $lower && null === $upper) {
46 // no value? no filter
42 return; 47 return;
48 } elseif (null === $lower && null !== $upper) {
49 // only lower value is defined: query all entries with reading LOWER THAN this value
50 $expression = $filterQuery->getExpr()->lte($field, $max);
51 } elseif (null !== $lower && null === $upper) {
52 // only upper value is defined: query all entries with reading GREATER THAN this value
53 $expression = $filterQuery->getExpr()->gte($field, $min);
54 } else {
55 // both value are defined, perform a between
56 $expression = $filterQuery->getExpr()->between($field, $min, $max);
43 } 57 }
44 58
45 $min = (int) ($value['left_number'][0] * $this->user->getConfig()->getReadingSpeed());
46 $max = (int) ($value['right_number'][0] * $this->user->getConfig()->getReadingSpeed());
47
48 $expression = $filterQuery->getExpr()->between($field, $min, $max);
49
50 return $filterQuery->createCondition($expression); 59 return $filterQuery->createCondition($expression);
51 }, 60 },
52 'label' => 'entry.filters.reading_time.label', 61 'label' => 'entry.filters.reading_time.label',
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index bea771bc..5c739c78 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -499,6 +499,42 @@ class EntryControllerTest extends WallabagCoreTestCase
499 $this->assertCount(1, $crawler->filter('div[class=entry]')); 499 $this->assertCount(1, $crawler->filter('div[class=entry]'));
500 } 500 }
501 501
502 public function testFilterOnReadingTimeOnlyUpper()
503 {
504 $this->logInAs('admin');
505 $client = $this->getClient();
506
507 $crawler = $client->request('GET', '/unread/list');
508
509 $form = $crawler->filter('button[id=submit-filter]')->form();
510
511 $data = [
512 'entry_filter[readingTime][right_number]' => 22,
513 ];
514
515 $crawler = $client->submit($form, $data);
516
517 $this->assertCount(2, $crawler->filter('div[class=entry]'));
518 }
519
520 public function testFilterOnReadingTimeOnlyLower()
521 {
522 $this->logInAs('admin');
523 $client = $this->getClient();
524
525 $crawler = $client->request('GET', '/unread/list');
526
527 $form = $crawler->filter('button[id=submit-filter]')->form();
528
529 $data = [
530 'entry_filter[readingTime][left_number]' => 22,
531 ];
532
533 $crawler = $client->submit($form, $data);
534
535 $this->assertCount(4, $crawler->filter('div[class=entry]'));
536 }
537
502 public function testFilterOnUnreadStatus() 538 public function testFilterOnUnreadStatus()
503 { 539 {
504 $this->logInAs('admin'); 540 $this->logInAs('admin');