From: Nicolas LÅ“uillet Date: Fri, 18 Nov 2016 22:05:02 +0000 (+0100) Subject: Check if status code is OK X-Git-Tag: 2.2.0~3^2~63^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=refs%2Fpull%2F2601%2Fhead;hp=e10e6ab34e62129d57fc69d7b9b69b08c20e6f5a;p=github%2Fwallabag%2Fwallabag.git Check if status code is OK --- diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index 38321d17..8e2883f7 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -11,6 +11,7 @@ use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType; use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; @@ -91,6 +92,18 @@ class EntryFilterType extends AbstractType 'label' => 'entry.filters.domain_label', ]) ->add('httpStatus', TextFilterType::class, [ + 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { + $value = $values['value']; + if (false === array_key_exists($value, Response::$statusTexts)) { + return; + } + + $paramName = sprintf('%s', str_replace('.', '_', $field)); + $expression = $filterQuery->getExpr()->eq($field, ':'.$paramName); + $parameters = array($paramName => $value); + + return $filterQuery->createCondition($expression, $parameters); + }, 'label' => 'entry.filters.http_status_label', ]) ->add('isArchived', CheckboxFilterType::class, [ diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 771903fe..09cf01b8 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1006,5 +1006,16 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); $this->assertCount(1, $crawler->filter('div[class=entry]')); + + $crawler = $client->request('GET', '/all/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = [ + 'entry_filter[httpStatus]' => 1024, + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(7, $crawler->filter('div[class=entry]')); } }