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\AdminBundle\Form\Type\Filter\NumberType; |
15
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Filter\NumberFilter; |
16
|
|
|
|
17
|
|
|
class NumberFilterTest extends BaseTestCase |
18
|
|
|
{ |
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
parent::setUp(); |
22
|
|
|
$this->filter = new NumberFilter(); |
|
|
|
|
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' => NumberType::TYPE_EQUAL)); |
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('getQueryBuilder'); |
50
|
|
|
|
51
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => NumberType::TYPE_EQUAL, 'value' => ' ')); |
52
|
|
|
$this->assertFalse($this->filter->isActive()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getFilters() |
56
|
|
|
{ |
57
|
|
|
return array( |
58
|
|
|
array('gte', NumberType::TYPE_GREATER_EQUAL, 2), |
59
|
|
|
array('gt', NumberType::TYPE_GREATER_THAN, 3), |
60
|
|
|
array('lte', NumberType::TYPE_LESS_EQUAL, 4), |
61
|
|
|
array('lt', NumberType::TYPE_LESS_THAN, 5), |
62
|
|
|
array('eq', NumberType::TYPE_EQUAL, 6), |
63
|
|
|
array('eq', 'default', 7), |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @dataProvider getFilters |
69
|
|
|
*/ |
70
|
|
|
public function testFilterSwitch($operatorMethod, $choiceType, $expectedValue = 'somevalue') |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$this->filter->filter( |
73
|
|
|
$this->proxyQuery, |
74
|
|
|
null, |
75
|
|
|
'somefield', |
76
|
|
|
array('type' => $choiceType, 'value' => $expectedValue) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic'); |
80
|
|
|
$opStatic = $this->qbTester->getNode('where.constraint.operand_static'); |
81
|
|
|
|
82
|
|
|
$this->assertEquals('a', $opDynamic->getAlias()); |
83
|
|
|
$this->assertEquals('somefield', $opDynamic->getField()); |
84
|
|
|
$this->assertEquals($expectedValue, $opStatic->getValue()); |
85
|
|
|
|
86
|
|
|
$this->assertTrue($this->filter->isActive()); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: