mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-29 02:50:29 +00:00
Merge pull request #1976 from wallabag/fix-filter-readingTime
Fix filter reading time
This commit is contained in:
commit
2142c714ef
3 changed files with 53 additions and 2 deletions
|
@ -35,6 +35,20 @@ class EntryFilterType extends AbstractType
|
|||
{
|
||||
$builder
|
||||
->add('readingTime', NumberRangeFilterType::class, [
|
||||
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
|
||||
$value = $values['value'];
|
||||
|
||||
if (null === $value['left_number'][0] || null === $value['right_number'][0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
$min = (int) ($value['left_number'][0] * $this->user->getConfig()->getReadingSpeed());
|
||||
$max = (int) ($value['right_number'][0] * $this->user->getConfig()->getReadingSpeed());
|
||||
|
||||
$expression = $filterQuery->getExpr()->between($field, $min, $max);
|
||||
|
||||
return $filterQuery->createCondition($expression);
|
||||
},
|
||||
'label' => 'entry.filters.reading_time.label',
|
||||
])
|
||||
->add('createdAt', DateRangeFilterType::class, [
|
||||
|
|
|
@ -60,6 +60,43 @@ class ConfigControllerTest extends WallabagCoreTestCase
|
|||
$this->assertContains('flashes.config.notice.config_saved', $alert[0]);
|
||||
}
|
||||
|
||||
public function testChangeReadingSpeed()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/unread/list');
|
||||
$form = $crawler->filter('button[id=submit-filter]')->form();
|
||||
$dataFilters = [
|
||||
'entry_filter[readingTime][right_number]' => 22,
|
||||
'entry_filter[readingTime][left_number]' => 22,
|
||||
];
|
||||
$crawler = $client->submit($form, $dataFilters);
|
||||
$this->assertCount(1, $crawler->filter('div[class=entry]'));
|
||||
|
||||
// Change reading speed
|
||||
$crawler = $client->request('GET', '/config');
|
||||
$form = $crawler->filter('button[id=config_save]')->form();
|
||||
$data = [
|
||||
'config[reading_speed]' => '2',
|
||||
];
|
||||
$client->submit($form, $data);
|
||||
|
||||
// Is the entry still available via filters?
|
||||
$crawler = $client->request('GET', '/unread/list');
|
||||
$form = $crawler->filter('button[id=submit-filter]')->form();
|
||||
$crawler = $client->submit($form, $dataFilters);
|
||||
$this->assertCount(0, $crawler->filter('div[class=entry]'));
|
||||
|
||||
// Restore old configuration
|
||||
$crawler = $client->request('GET', '/config');
|
||||
$form = $crawler->filter('button[id=config_save]')->form();
|
||||
$data = [
|
||||
'config[reading_speed]' => '0.5',
|
||||
];
|
||||
$client->submit($form, $data);
|
||||
}
|
||||
|
||||
public function dataForUpdateFailed()
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -462,8 +462,8 @@ class EntryControllerTest extends WallabagCoreTestCase
|
|||
$form = $crawler->filter('button[id=submit-filter]')->form();
|
||||
|
||||
$data = [
|
||||
'entry_filter[readingTime][right_number]' => 11,
|
||||
'entry_filter[readingTime][left_number]' => 11,
|
||||
'entry_filter[readingTime][right_number]' => 22,
|
||||
'entry_filter[readingTime][left_number]' => 22,
|
||||
];
|
||||
|
||||
$crawler = $client->submit($form, $data);
|
||||
|
|
Loading…
Reference in a new issue