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