diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-05-03 09:05:31 +0200 |
---|---|---|
committer | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-05-03 09:05:31 +0200 |
commit | 2142c714ef997f4853b5649ab86d150e40e6f18a (patch) | |
tree | 59601deae1a0bf59ec7886be53f31dc422786a2c | |
parent | 045859a2b502a9e94943e262ee80698af08619e1 (diff) | |
parent | c4c062cce00d8358b9a9c836aadcd8997f2fb069 (diff) | |
download | wallabag-2142c714ef997f4853b5649ab86d150e40e6f18a.tar.gz wallabag-2142c714ef997f4853b5649ab86d150e40e6f18a.tar.zst wallabag-2142c714ef997f4853b5649ab86d150e40e6f18a.zip |
Merge pull request #1976 from wallabag/fix-filter-readingTime
Fix filter reading time
3 files changed, 53 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index dcdb3ab7..cd4d3490 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php | |||
@@ -35,6 +35,20 @@ class EntryFilterType extends AbstractType | |||
35 | { | 35 | { |
36 | $builder | 36 | $builder |
37 | ->add('readingTime', NumberRangeFilterType::class, [ | 37 | ->add('readingTime', NumberRangeFilterType::class, [ |
38 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { | ||
39 | $value = $values['value']; | ||
40 | |||
41 | if (null === $value['left_number'][0] || null === $value['right_number'][0]) { | ||
42 | return; | ||
43 | } | ||
44 | |||
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); | ||
51 | }, | ||
38 | 'label' => 'entry.filters.reading_time.label', | 52 | 'label' => 'entry.filters.reading_time.label', |
39 | ]) | 53 | ]) |
40 | ->add('createdAt', DateRangeFilterType::class, [ | 54 | ->add('createdAt', DateRangeFilterType::class, [ |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 1f9cfe53..8cdedfda 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php | |||
@@ -60,6 +60,43 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
60 | $this->assertContains('flashes.config.notice.config_saved', $alert[0]); | 60 | $this->assertContains('flashes.config.notice.config_saved', $alert[0]); |
61 | } | 61 | } |
62 | 62 | ||
63 | public function testChangeReadingSpeed() | ||
64 | { | ||
65 | $this->logInAs('admin'); | ||
66 | $client = $this->getClient(); | ||
67 | |||
68 | $crawler = $client->request('GET', '/unread/list'); | ||
69 | $form = $crawler->filter('button[id=submit-filter]')->form(); | ||
70 | $dataFilters = [ | ||
71 | 'entry_filter[readingTime][right_number]' => 22, | ||
72 | 'entry_filter[readingTime][left_number]' => 22, | ||
73 | ]; | ||
74 | $crawler = $client->submit($form, $dataFilters); | ||
75 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | ||
76 | |||
77 | // Change reading speed | ||
78 | $crawler = $client->request('GET', '/config'); | ||
79 | $form = $crawler->filter('button[id=config_save]')->form(); | ||
80 | $data = [ | ||
81 | 'config[reading_speed]' => '2', | ||
82 | ]; | ||
83 | $client->submit($form, $data); | ||
84 | |||
85 | // Is the entry still available via filters? | ||
86 | $crawler = $client->request('GET', '/unread/list'); | ||
87 | $form = $crawler->filter('button[id=submit-filter]')->form(); | ||
88 | $crawler = $client->submit($form, $dataFilters); | ||
89 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | ||
90 | |||
91 | // Restore old configuration | ||
92 | $crawler = $client->request('GET', '/config'); | ||
93 | $form = $crawler->filter('button[id=config_save]')->form(); | ||
94 | $data = [ | ||
95 | 'config[reading_speed]' => '0.5', | ||
96 | ]; | ||
97 | $client->submit($form, $data); | ||
98 | } | ||
99 | |||
63 | public function dataForUpdateFailed() | 100 | public function dataForUpdateFailed() |
64 | { | 101 | { |
65 | return [ | 102 | return [ |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 64ebd631..df4c34cd 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php | |||
@@ -462,8 +462,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
462 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 462 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
463 | 463 | ||
464 | $data = [ | 464 | $data = [ |
465 | 'entry_filter[readingTime][right_number]' => 11, | 465 | 'entry_filter[readingTime][right_number]' => 22, |
466 | 'entry_filter[readingTime][left_number]' => 11, | 466 | 'entry_filter[readingTime][left_number]' => 22, |
467 | ]; | 467 | ]; |
468 | 468 | ||
469 | $crawler = $client->submit($form, $data); | 469 | $crawler = $client->submit($form, $data); |