|
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\Filter; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Filter\StringFilter; |
|
15
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Form\Type\Filter\ChoiceType; |
|
16
|
|
|
|
|
17
|
|
|
class StringFilterTest extends BaseTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var StringFilter |
|
21
|
|
|
*/ |
|
22
|
|
|
private $filter; |
|
23
|
|
|
|
|
24
|
|
|
public function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
parent::setUp(); |
|
27
|
|
|
$this->filter = new StringFilter(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testFilterNullData() |
|
31
|
|
|
{ |
|
32
|
|
|
$res = $this->filter->filter($this->proxyQuery, null, 'somefield', null); |
|
|
|
|
|
|
33
|
|
|
$this->assertNull($res); |
|
34
|
|
|
$this->assertFalse($this->filter->isActive()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testFilterEmptyArrayData() |
|
38
|
|
|
{ |
|
39
|
|
|
$res = $this->filter->filter($this->proxyQuery, null, 'somefield', array()); |
|
|
|
|
|
|
40
|
|
|
$this->assertNull($res); |
|
41
|
|
|
$this->assertFalse($this->filter->isActive()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testFilterEmptyArrayDataSpecifiedType() |
|
45
|
|
|
{ |
|
46
|
|
|
$res = $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => ChoiceType::TYPE_EQUAL)); |
|
|
|
|
|
|
47
|
|
|
$this->assertNull($res); |
|
48
|
|
|
$this->assertFalse($this->filter->isActive()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testFilterEmptyArrayDataWithMeaninglessValue() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->proxyQuery->expects($this->never()) |
|
|
|
|
|
|
54
|
|
|
->method('getQueryBuilder'); |
|
55
|
|
|
|
|
56
|
|
|
$this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => ChoiceType::TYPE_EQUAL, 'value' => ' ')); |
|
|
|
|
|
|
57
|
|
|
$this->assertFalse($this->filter->isActive()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getFilters() |
|
61
|
|
|
{ |
|
62
|
|
|
return array( |
|
63
|
|
|
array(ChoiceType::TYPE_EQUAL, array( |
|
64
|
|
|
'where.constraint.operand_dynamic' => array( |
|
65
|
|
|
'getAlias' => 'a', |
|
66
|
|
|
'getField' => 'somefield', |
|
67
|
|
|
), |
|
68
|
|
|
'where.constraint.operand_static' => array( |
|
69
|
|
|
'getValue' => 'somevalue', |
|
70
|
|
|
), |
|
71
|
|
|
)), |
|
72
|
|
|
array(ChoiceType::TYPE_NOT_CONTAINS, array( |
|
73
|
|
|
'where.constraint' => array( |
|
74
|
|
|
'getField' => 'somefield', |
|
75
|
|
|
'getFullTextSearchExpression' => '* -somevalue', ), |
|
76
|
|
|
)), |
|
77
|
|
|
array(ChoiceType::TYPE_CONTAINS, array( |
|
78
|
|
|
'where.constraint.operand_dynamic' => array( |
|
79
|
|
|
'getAlias' => 'a', |
|
80
|
|
|
'getField' => 'somefield', |
|
81
|
|
|
), |
|
82
|
|
|
'where.constraint.operand_static' => array( |
|
83
|
|
|
'getValue' => '%somevalue%', |
|
84
|
|
|
), |
|
85
|
|
|
)), |
|
86
|
|
|
array(ChoiceType::TYPE_CONTAINS_WORDS, array( |
|
87
|
|
|
'where.constraint' => array( |
|
88
|
|
|
'getField' => 'somefield', |
|
89
|
|
|
'getFullTextSearchExpression' => 'somevalue', ), |
|
90
|
|
|
)), |
|
91
|
|
|
'equalCaseInsensitiveComparision' => array(ChoiceType::TYPE_EQUAL, array( |
|
92
|
|
|
'where.constraint.operand_dynamic.operand_dynamic' => array( |
|
93
|
|
|
'getAlias' => 'a', |
|
94
|
|
|
'getField' => 'somefield', |
|
95
|
|
|
), |
|
96
|
|
|
'where.constraint.operand_static' => array( |
|
97
|
|
|
'getValue' => 'somevalue', |
|
98
|
|
|
), |
|
99
|
|
|
), true), |
|
100
|
|
|
'containsCaseInsensitiveComparision' => array(ChoiceType::TYPE_CONTAINS, array( |
|
101
|
|
|
'where.constraint.operand_dynamic.operand_dynamic' => array( |
|
102
|
|
|
'getAlias' => 'a', |
|
103
|
|
|
'getField' => 'somefield', |
|
104
|
|
|
), |
|
105
|
|
|
'where.constraint.operand_static' => array( |
|
106
|
|
|
'getValue' => '%somevalue%', |
|
107
|
|
|
), |
|
108
|
|
|
), true) |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @dataProvider getFilters |
|
114
|
|
|
*/ |
|
115
|
|
|
public function testFilterSwitch($choiceType, $assertPaths, $isLowerCase = false) |
|
116
|
|
|
{ |
|
117
|
|
|
if ($isLowerCase) { |
|
118
|
|
|
$this->filter->setOption('compare_case_insensitive', true); |
|
119
|
|
|
} |
|
120
|
|
|
$this->filter->filter( |
|
121
|
|
|
$this->proxyQuery, |
|
122
|
|
|
null, |
|
123
|
|
|
'somefield', |
|
124
|
|
|
array('type' => $choiceType, 'value' => 'somevalue') |
|
|
|
|
|
|
125
|
|
|
); |
|
126
|
|
|
$this->assertTrue($this->filter->isActive()); |
|
127
|
|
|
|
|
128
|
|
|
foreach ($assertPaths as $path => $assertions) { |
|
129
|
|
|
$node = $this->qbTester->getNode($path); |
|
130
|
|
|
foreach ($assertions as $methodName => $expectedValue) { |
|
131
|
|
|
$res = $node->$methodName(); |
|
132
|
|
|
$this->assertEquals($expectedValue, $res); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$this->assertTrue($this->filter->isActive()); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.