1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Tests\Filter; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; |
18
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\ClassFilter; |
19
|
|
|
use Sonata\Form\Type\EqualType; |
20
|
|
|
|
21
|
|
|
class ClassFilterTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testRenderSettings(): void |
24
|
|
|
{ |
25
|
|
|
$filter = new ClassFilter(); |
26
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
27
|
|
|
$options = $filter->getRenderSettings()[1]; |
28
|
|
|
|
29
|
|
|
$this->assertSame(EqualType::class, $options['operator_type']); |
30
|
|
|
$this->assertSame([], $options['operator_options']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testFilterEmpty(): void |
34
|
|
|
{ |
35
|
|
|
$filter = new ClassFilter(); |
36
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
37
|
|
|
|
38
|
|
|
$builder = new ProxyQuery(new QueryBuilder()); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$filter->filter($builder, 'alias', 'field', null); |
|
|
|
|
41
|
|
|
$filter->filter($builder, 'alias', 'field', 'asds'); |
|
|
|
|
42
|
|
|
$filter->filter($builder, 'alias', 'field', ['value' => '']); |
43
|
|
|
|
44
|
|
|
$this->assertSame([], $builder->query); |
|
|
|
|
45
|
|
|
$this->assertFalse($filter->isActive()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testFilterInvalidOperator(): void |
49
|
|
|
{ |
50
|
|
|
$filter = new ClassFilter(); |
51
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
52
|
|
|
|
53
|
|
|
$builder = new ProxyQuery(new QueryBuilder()); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => 'foo']); |
56
|
|
|
|
57
|
|
|
$this->assertSame([], $builder->query); |
|
|
|
|
58
|
|
|
$this->assertFalse($filter->isActive()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testFilter(): void |
62
|
|
|
{ |
63
|
|
|
$filter = new ClassFilter(); |
64
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
65
|
|
|
|
66
|
|
|
$builder = new ProxyQuery(new QueryBuilder()); |
|
|
|
|
67
|
|
|
|
68
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => EqualType::TYPE_IS_EQUAL, 'value' => 'type']); |
69
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => EqualType::TYPE_IS_NOT_EQUAL, 'value' => 'type']); |
70
|
|
|
$filter->filter($builder, 'alias', 'field', ['value' => 'type']); |
71
|
|
|
|
72
|
|
|
$expected = [ |
73
|
|
|
'alias INSTANCE OF type', |
74
|
|
|
'alias NOT INSTANCE OF type', |
75
|
|
|
'alias INSTANCE OF type', |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
$this->assertSame($expected, $builder->query); |
|
|
|
|
79
|
|
|
$this->assertTrue($filter->isActive()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: