|
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\ChoiceFilter; |
|
15
|
|
|
use Sonata\AdminBundle\Form\Type\Filter\ChoiceType; |
|
16
|
|
|
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; |
|
17
|
|
|
|
|
18
|
|
|
class ChoiceFilterTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testFilterEmpty() |
|
21
|
|
|
{ |
|
22
|
|
|
$filter = new ChoiceFilter; |
|
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', 'all'); |
|
29
|
|
|
$filter->filter($builder, 'alias', 'field', array()); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals(array(), $builder->query); |
|
|
|
|
|
|
32
|
|
|
$this->assertEquals(false, $filter->isActive()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testFilterArray() |
|
36
|
|
|
{ |
|
37
|
|
|
$filter = new ChoiceFilter; |
|
38
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
|
39
|
|
|
|
|
40
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
|
41
|
|
|
|
|
42
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => ChoiceType::TYPE_CONTAINS, 'value' => array('1', '2'))); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals(array('in_alias.field', 'alias.field IN ("1,2")'), $builder->query); |
|
|
|
|
|
|
45
|
|
|
$this->assertEquals(true, $filter->isActive()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testFilterScalar() |
|
49
|
|
|
{ |
|
50
|
|
|
$filter = new ChoiceFilter; |
|
51
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
|
52
|
|
|
|
|
53
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
|
54
|
|
|
|
|
55
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => ChoiceType::TYPE_CONTAINS, 'value' => '1')); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals(array('alias.field = :field_name_0'), $builder->query); |
|
|
|
|
|
|
58
|
|
|
$this->assertEquals(array('field_name_0' => '1'), $builder->parameters); |
|
|
|
|
|
|
59
|
|
|
$this->assertEquals(true, $filter->isActive()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testFilterZero() |
|
63
|
|
|
{ |
|
64
|
|
|
$filter = new ChoiceFilter; |
|
65
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
|
66
|
|
|
|
|
67
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
|
68
|
|
|
|
|
69
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => ChoiceType::TYPE_CONTAINS, 'value' => 0)); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$this->assertEquals(array('alias.field = :field_name_0'), $builder->query); |
|
|
|
|
|
|
72
|
|
|
$this->assertEquals(array('field_name_0' => 0), $builder->parameters); |
|
|
|
|
|
|
73
|
|
|
$this->assertEquals(true, $filter->isActive()); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
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: