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\DoctrineMongoDBAdminBundle\Tests\Filter; |
15
|
|
|
|
16
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Datagrid\ProxyQuery; |
17
|
|
|
use Sonata\DoctrineMongoDBAdminBundle\Filter\BooleanFilter; |
18
|
|
|
use Sonata\Form\Type\BooleanType; |
19
|
|
|
|
20
|
|
|
class BooleanFilterTest extends FilterWithQueryBuilderTest |
21
|
|
|
{ |
22
|
|
|
public function testFilterEmpty(): void |
23
|
|
|
{ |
24
|
|
|
$filter = new BooleanFilter(); |
25
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
26
|
|
|
|
27
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
28
|
|
|
|
29
|
|
|
$builder->getQueryBuilder() |
|
|
|
|
30
|
|
|
->expects($this->never()) |
31
|
|
|
->method('field') |
32
|
|
|
; |
33
|
|
|
|
34
|
|
|
$filter->filter($builder, 'alias', 'field', null); |
35
|
|
|
$filter->filter($builder, 'alias', 'field', ''); |
36
|
|
|
$filter->filter($builder, 'alias', 'field', 'test'); |
37
|
|
|
$filter->filter($builder, 'alias', 'field', false); |
38
|
|
|
|
39
|
|
|
$filter->filter($builder, 'alias', 'field', []); |
40
|
|
|
$filter->filter($builder, 'alias', 'field', [null, 'test']); |
41
|
|
|
|
42
|
|
|
$this->assertFalse($filter->isActive()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testFilterNo(): void |
46
|
|
|
{ |
47
|
|
|
$filter = new BooleanFilter(); |
48
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
49
|
|
|
|
50
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
51
|
|
|
|
52
|
|
|
$builder->getQueryBuilder() |
|
|
|
|
53
|
|
|
->expects($this->once()) |
54
|
|
|
->method('equals') |
55
|
|
|
->with(false) |
56
|
|
|
; |
57
|
|
|
|
58
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => null, 'value' => BooleanType::TYPE_NO]); |
59
|
|
|
|
60
|
|
|
$this->assertTrue($filter->isActive()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testFilterYes(): void |
64
|
|
|
{ |
65
|
|
|
$filter = new BooleanFilter(); |
66
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
67
|
|
|
|
68
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
69
|
|
|
|
70
|
|
|
$builder->getQueryBuilder() |
|
|
|
|
71
|
|
|
->expects($this->once()) |
72
|
|
|
->method('equals') |
73
|
|
|
->with(true) |
74
|
|
|
; |
75
|
|
|
|
76
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => null, 'value' => BooleanType::TYPE_YES]); |
77
|
|
|
|
78
|
|
|
$this->assertTrue($filter->isActive()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testFilterArray(): void |
82
|
|
|
{ |
83
|
|
|
$filter = new BooleanFilter(); |
84
|
|
|
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); |
85
|
|
|
|
86
|
|
|
$builder = new ProxyQuery($this->getQueryBuilder()); |
87
|
|
|
|
88
|
|
|
$builder->getQueryBuilder() |
|
|
|
|
89
|
|
|
->expects($this->once()) |
90
|
|
|
->method('in') |
91
|
|
|
->with([false]) |
92
|
|
|
; |
93
|
|
|
|
94
|
|
|
$filter->filter($builder, 'alias', 'field', ['type' => null, 'value' => [BooleanType::TYPE_NO]]); |
95
|
|
|
|
96
|
|
|
$this->assertTrue($filter->isActive()); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.