1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Tests\Filter; |
13
|
|
|
|
14
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\BooleanFilter; |
15
|
|
|
use Sonata\CoreBundle\Form\Type\BooleanType; |
16
|
|
|
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; |
17
|
|
|
|
18
|
|
|
class BooleanFilterTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
public function testFilterEmpty() |
21
|
|
|
{ |
22
|
|
|
$filter = new BooleanFilter; |
23
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
24
|
|
|
|
25
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
26
|
|
|
|
27
|
|
|
$filter->filter($builder, 'alias', 'field', null); |
28
|
|
|
$filter->filter($builder, 'alias', 'field', ''); |
29
|
|
|
$filter->filter($builder, 'alias', 'field', 'test'); |
30
|
|
|
$filter->filter($builder, 'alias', 'field', false); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$filter->filter($builder, 'alias', 'field', array()); |
|
|
|
|
33
|
|
|
$filter->filter($builder, 'alias', 'field', array(null, 'test')); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->assertEquals(array(), $builder->query); |
|
|
|
|
36
|
|
|
$this->assertEquals(false, $filter->isActive()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testFilterNo() |
40
|
|
|
{ |
41
|
|
|
$filter = new BooleanFilter; |
42
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
43
|
|
|
|
44
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
45
|
|
|
|
46
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => null, 'value' => BooleanType::TYPE_NO)); |
|
|
|
|
47
|
|
|
|
48
|
|
|
$this->assertEquals(array('alias.field = :field_name_0'), $builder->query); |
|
|
|
|
49
|
|
|
$this->assertEquals(array('field_name_0' => 0), $builder->parameters); |
|
|
|
|
50
|
|
|
$this->assertEquals(true, $filter->isActive()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testFilterYes() |
54
|
|
|
{ |
55
|
|
|
$filter = new BooleanFilter; |
56
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
57
|
|
|
|
58
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
59
|
|
|
|
60
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => null, 'value' => BooleanType::TYPE_YES)); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->assertEquals(array('alias.field = :field_name_0'), $builder->query); |
|
|
|
|
63
|
|
|
$this->assertEquals(array('field_name_0' => 1), $builder->parameters); |
|
|
|
|
64
|
|
|
$this->assertEquals(true, $filter->isActive()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testFilterArray() |
68
|
|
|
{ |
69
|
|
|
$filter = new BooleanFilter; |
70
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
71
|
|
|
|
72
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
73
|
|
|
|
74
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => null, 'value' => array(BooleanType::TYPE_NO))); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$this->assertEquals(array('in_alias.field', 'alias.field IN ("0")'), $builder->query); |
|
|
|
|
77
|
|
|
$this->assertEquals(true, $filter->isActive()); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
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: