|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata Project 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\DoctrinePHPCRAdminBundle\Tests\Unit\Filter; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\CoreBundle\Form\Type\BooleanType; |
|
15
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Filter\BooleanFilter; |
|
16
|
|
|
|
|
17
|
|
|
class BooleanFilterTest extends BaseTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var BooleanFilter |
|
21
|
|
|
*/ |
|
22
|
|
|
private $filter; |
|
23
|
|
|
|
|
24
|
|
|
public function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
parent::setUp(); |
|
27
|
|
|
$this->filter = new BooleanFilter(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testFilterNullData() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', null); |
|
33
|
|
|
$this->assertFalse($this->filter->isActive()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testFilterEmptyArrayData() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', array()); |
|
|
|
|
|
|
39
|
|
|
$this->assertFalse($this->filter->isActive()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testFilterEmptyArrayDataSpecifiedType() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => BooleanType::TYPE_YES)); |
|
|
|
|
|
|
45
|
|
|
$this->assertFalse($this->filter->isActive()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testFilterEmptyArrayDataWithMeaninglessValue() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => BooleanType::TYPE_YES, 'value' => 'someValue')); |
|
|
|
|
|
|
51
|
|
|
$this->assertFalse($this->filter->isActive()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getFilters() |
|
55
|
|
|
{ |
|
56
|
|
|
return array( |
|
57
|
|
|
array('eq', BooleanType::TYPE_YES, 1), |
|
58
|
|
|
array('eq', BooleanType::TYPE_NO, 0), |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @dataProvider getFilters |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testFilterSwitch($operatorMethod, $value, $expectedValue) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->filter->filter( |
|
68
|
|
|
$this->proxyQuery, |
|
69
|
|
|
null, |
|
70
|
|
|
'somefield', |
|
71
|
|
|
array('type' => '', 'value' => $value) |
|
|
|
|
|
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic'); |
|
75
|
|
|
$opStatic = $this->qbTester->getNode('where.constraint.operand_static'); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertEquals('a', $opDynamic->getAlias()); |
|
78
|
|
|
$this->assertEquals('somefield', $opDynamic->getField()); |
|
79
|
|
|
$this->assertEquals($expectedValue, $opStatic->getValue()); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertTrue($this->filter->isActive()); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
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: