Skip to content

Commit

Permalink
Fix UidFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 10, 2024
1 parent 2d90916 commit 7b8f14a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Filter/UidFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function getDefaultOptions(): array
'field_type' => TextType::class,
'operator_type' => EqualOperatorType::class,
'operator_options' => [],
'global_search' => false,
];
}

Expand Down
46 changes: 46 additions & 0 deletions tests/Filter/UidFilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* 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());
}
}

0 comments on commit 7b8f14a

Please sign in to comment.