1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the LoopBackApiBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Théo FIDRY <[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 Fidry\LoopBackApiBundle\Tests\Http\Request; |
13
|
|
|
|
14
|
|
|
use Fidry\LoopBackApiBundle\Http\Request\FilterQueryExtractor; |
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @coversDefaultClass Fidry\LoopBackApiBundle\Http\RequestFilterQueryExtractor |
19
|
|
|
* |
20
|
|
|
* @author Théo FIDRY <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class FilterQueryExtractorTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @cover ::__construct |
26
|
|
|
*/ |
27
|
|
|
public function testConstructor() |
28
|
|
|
{ |
29
|
|
|
new FilterQueryExtractor('order'); |
30
|
|
|
new FilterQueryExtractor('order', null); |
31
|
|
|
new FilterQueryExtractor('order', 'filter'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @cover ::extractProperties |
36
|
|
|
*/ |
37
|
|
|
public function testExtractPropertiesWithoutFilterEntryParameter() |
38
|
|
|
{ |
39
|
|
|
$filterQueryExtractors = new FilterQueryExtractor('order'); |
40
|
|
|
|
41
|
|
|
$request = new Request([ |
42
|
|
|
'order' => [ |
43
|
|
|
'name' => 'fidry' |
44
|
|
|
], |
45
|
|
|
'where' => [ |
46
|
|
|
'id' => 1 |
47
|
|
|
] |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
$properties = $filterQueryExtractors->extractProperties($request); |
51
|
|
|
$this->assertEquals( |
52
|
|
|
[ |
53
|
|
|
'name' => 'fidry' |
54
|
|
|
], |
55
|
|
|
$properties |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$request = new Request([ |
59
|
|
|
'where' => [ |
60
|
|
|
'id' => 1 |
61
|
|
|
] |
62
|
|
|
]); |
63
|
|
|
|
64
|
|
|
$properties = $filterQueryExtractors->extractProperties($request); |
65
|
|
|
$this->assertCount(0, $properties); |
66
|
|
|
|
67
|
|
|
$request = new Request(); |
68
|
|
|
|
69
|
|
|
$properties = $filterQueryExtractors->extractProperties($request); |
70
|
|
|
$this->assertCount(0, $properties); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @cover ::extractProperties |
75
|
|
|
*/ |
76
|
|
|
public function testExtractPropertiesWithFilterEntryParameter() |
77
|
|
|
{ |
78
|
|
|
$filterQueryExtractors = new FilterQueryExtractor('order', 'filter'); |
79
|
|
|
|
80
|
|
|
$request = new Request([ |
81
|
|
|
'filter' => [ |
82
|
|
|
'order' => [ |
83
|
|
|
'name' => 'fidry' |
84
|
|
|
], |
85
|
|
|
'where' => [ |
86
|
|
|
'id' => 1 |
87
|
|
|
] |
88
|
|
|
], |
89
|
|
|
'where' => [ |
90
|
|
|
'id' => 2 |
91
|
|
|
] |
92
|
|
|
]); |
93
|
|
|
|
94
|
|
|
$properties = $filterQueryExtractors->extractProperties($request); |
95
|
|
|
$this->assertEquals( |
96
|
|
|
[ |
97
|
|
|
'name' => 'fidry' |
98
|
|
|
], |
99
|
|
|
$properties |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$request = new Request([ |
103
|
|
|
'where' => [ |
104
|
|
|
'id' => 1 |
105
|
|
|
] |
106
|
|
|
]); |
107
|
|
|
|
108
|
|
|
$properties = $filterQueryExtractors->extractProperties($request); |
109
|
|
|
$this->assertCount(0, $properties); |
110
|
|
|
|
111
|
|
|
$request = new Request(); |
112
|
|
|
|
113
|
|
|
$properties = $filterQueryExtractors->extractProperties($request); |
114
|
|
|
$this->assertCount(0, $properties); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|