diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index db7d76a0a..510dca956 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -532,6 +532,8 @@ class EntryController extends Controller $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); + $formOptions = []; + switch ($type) { case 'search': $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute); @@ -541,12 +543,15 @@ class EntryController extends Controller break; case 'starred': $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId()); + $formOptions['filter_starred'] = true; break; case 'archive': $qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId()); + $formOptions['filter_archived'] = true; break; case 'unread': $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId()); + $formOptions['filter_unread'] = true; break; case 'all': $qb = $repository->getBuilderForAllByUser($this->getUser()->getId()); @@ -555,7 +560,7 @@ class EntryController extends Controller throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); } - $form = $this->createForm(EntryFilterType::class); + $form = $this->createForm(EntryFilterType::class, [], $formOptions); if ($request->query->has($form->getName())) { // manually bind values from the request diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index 61ad99a86..176b7ea07 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -118,12 +118,15 @@ class EntryFilterType extends AbstractType ]) ->add('isArchived', CheckboxFilterType::class, [ 'label' => 'entry.filters.archived_label', + 'data' => $options['filter_archived'], ]) ->add('isStarred', CheckboxFilterType::class, [ 'label' => 'entry.filters.starred_label', + 'data' => $options['filter_starred'], ]) ->add('isUnread', CheckboxFilterType::class, [ 'label' => 'entry.filters.unread_label', + 'data' => $options['filter_unread'], 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { if (false === $values['value']) { return; @@ -177,6 +180,9 @@ class EntryFilterType extends AbstractType $resolver->setDefaults([ 'csrf_protection' => false, 'validation_groups' => ['filtering'], + 'filter_archived' => false, + 'filter_starred' => false, + 'filter_unread' => false, ]); } } diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 96e3e9f13..8c65e7ed1 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -857,7 +857,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter('li.entry')); + $this->assertCount(4, $crawler->filter('li.entry')); $data = [ 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'), @@ -866,7 +866,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter('li.entry')); + $this->assertCount(4, $crawler->filter('li.entry')); $data = [ 'entry_filter[createdAt][left_date]' => '1970-01-01', @@ -919,7 +919,7 @@ class EntryControllerTest extends WallabagCoreTestCase ]; $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter('li.entry')); + $this->assertCount(4, $crawler->filter('li.entry')); $crawler = $client->request('GET', '/unread/list'); $form = $crawler->filter('button[id=submit-filter]')->form(); @@ -928,7 +928,7 @@ class EntryControllerTest extends WallabagCoreTestCase ]; $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter('li.entry')); + $this->assertCount(4, $crawler->filter('li.entry')); $form = $crawler->filter('button[id=submit-filter]')->form(); $data = [ @@ -948,6 +948,7 @@ class EntryControllerTest extends WallabagCoreTestCase $form = $crawler->filter('button[id=submit-filter]')->form(); $form['entry_filter[isArchived]']->tick(); $form['entry_filter[isStarred]']->untick(); + $form['entry_filter[isUnread]']->untick(); $crawler = $client->submit($form); $this->assertCount(1, $crawler->filter('li.entry')); @@ -960,6 +961,30 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('li.entry')); } + public function testFilterPreselectedStatus() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $this->assertTrue($form['entry_filter[isUnread]']->hasValue()); + $this->assertFalse($form['entry_filter[isArchived]']->hasValue()); + $this->assertFalse($form['entry_filter[isStarred]']->hasValue()); + + $crawler = $client->request('GET', '/starred/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $this->assertFalse($form['entry_filter[isUnread]']->hasValue()); + $this->assertFalse($form['entry_filter[isArchived]']->hasValue()); + $this->assertTrue($form['entry_filter[isStarred]']->hasValue()); + + $crawler = $client->request('GET', '/all/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $this->assertFalse($form['entry_filter[isUnread]']->hasValue()); + $this->assertFalse($form['entry_filter[isArchived]']->hasValue()); + $this->assertFalse($form['entry_filter[isStarred]']->hasValue()); + } + public function testFilterOnIsPublic() { $this->logInAs('admin');