From 7b8f14a957694110279c77d3f11b9f44200425b7 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 10 Apr 2024 15:41:28 +0200 Subject: [PATCH] Fix UidFilter --- src/Filter/UidFilter.php | 1 + tests/Filter/UidFilterTest.php | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/Filter/UidFilterTest.php diff --git a/src/Filter/UidFilter.php b/src/Filter/UidFilter.php index 4a032e9c8..256463c31 100644 --- a/src/Filter/UidFilter.php +++ b/src/Filter/UidFilter.php @@ -59,6 +59,7 @@ public function getDefaultOptions(): array 'field_type' => TextType::class, 'operator_type' => EqualOperatorType::class, 'operator_options' => [], + 'global_search' => false, ]; } diff --git a/tests/Filter/UidFilterTest.php b/tests/Filter/UidFilterTest.php new file mode 100644 index 000000000..8c92563bb --- /dev/null +++ b/tests/Filter/UidFilterTest.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DoctrineORMAdminBundle\Tests\Filter; + +use Sonata\AdminBundle\Filter\Model\FilterData; +use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; +use Sonata\DoctrineORMAdminBundle\Filter\UidFilter; + +final class UidFilterTest extends FilterTestCase +{ + public function testSearchEnabled(): void + { + $filter = new UidFilter(); + $filter->initialize('field_name'); + static::assertFalse($filter->isSearchEnabled()); + + $filter = new UidFilter(); + $filter->initialize('field_name', ['global_search' => true]); + static::assertTrue($filter->isSearchEnabled()); + } + + public function testEmpty(): void + { + $filter = new UidFilter(); + $filter->initialize('field_name'); + + $proxyQuery = new ProxyQuery($this->createQueryBuilderStub()); + + $filter->filter($proxyQuery, 'alias', 'field', FilterData::fromArray([])); + $filter->filter($proxyQuery, 'alias', 'field', FilterData::fromArray(['value' => ''])); + + self::assertSameQuery([], $proxyQuery); + static::assertFalse($filter->isActive()); + } +}