1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Unit\Filter; |
15
|
|
|
|
16
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Filter\NodeNameFilter; |
17
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Form\Type\Filter\ChoiceType; |
18
|
|
|
|
19
|
|
|
class NodeNameFilterTest extends BaseTestCase |
20
|
|
|
{ |
21
|
|
|
public function setUp(): void |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
$this->filter = new NodeNameFilter(); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getChoiceTypeForEmptyTests() |
28
|
|
|
{ |
29
|
|
|
return ChoiceType::TYPE_EQUAL; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testFilterNullData(): void |
33
|
|
|
{ |
34
|
|
|
$res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', null); |
35
|
|
|
$this->assertNull($res); |
36
|
|
|
$this->assertFalse($this->filter->isActive()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testFilterEmptyArrayData(): void |
40
|
|
|
{ |
41
|
|
|
$res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', []); |
42
|
|
|
$this->assertNull($res); |
43
|
|
|
$this->assertFalse($this->filter->isActive()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testFilterEmptyArrayDataSpecifiedType(): void |
47
|
|
|
{ |
48
|
|
|
$res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', ['type' => ChoiceType::TYPE_EQUAL]); |
49
|
|
|
$this->assertNull($res); |
50
|
|
|
$this->assertFalse($this->filter->isActive()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testFilterEmptyArrayDataWithMeaninglessValue(): void |
54
|
|
|
{ |
55
|
|
|
$this->filter->filter($this->proxyQuery, 'a', 'somefield', ['type' => ChoiceType::TYPE_EQUAL, 'value' => ' ']); |
56
|
|
|
$this->assertFalse($this->filter->isActive()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getFilters() |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
|
|
['eqNodeName', ChoiceType::TYPE_EQUAL], |
63
|
|
|
['likeNodeName', ChoiceType::TYPE_NOT_CONTAINS, '%somevalue%'], |
64
|
|
|
['likeNodeName', ChoiceType::TYPE_CONTAINS, '%somevalue%'], |
65
|
|
|
['likeNodeName', ChoiceType::TYPE_CONTAINS_WORDS, '%somevalue%'], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @dataProvider getFilters |
71
|
|
|
*/ |
72
|
|
|
public function testFilterSwitch($operatorMethod, $choiceType, $expectedValue = 'somevalue'): void |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$this->proxyQuery->expects($this->exactly(1)) |
|
|
|
|
75
|
|
|
->method('getQueryBuilder') |
76
|
|
|
->willReturn($this->qb); |
77
|
|
|
|
78
|
|
|
$this->filter->filter( |
79
|
|
|
$this->proxyQuery, |
80
|
|
|
'a', |
81
|
|
|
'somefield', |
82
|
|
|
['type' => $choiceType, 'value' => 'somevalue'] |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$localName = $this->qbTester->getNode('where.constraint.operand_dynamic'); |
86
|
|
|
$literal = $this->qbTester->getNode('where.constraint.operand_static'); |
87
|
|
|
|
88
|
|
|
$this->assertSame('a', $localName->getAlias()); |
89
|
|
|
$this->assertSame($expectedValue, $literal->getValue()); |
90
|
|
|
|
91
|
|
|
$this->assertTrue($this->filter->isActive()); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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: