1
|
|
|
<?php |
2
|
|
|
use GroupByInc\API\Model\Navigation; |
3
|
|
|
use GroupByInc\API\Request\SelectedRefinementRange; |
4
|
|
|
use GroupByInc\API\Request\SelectedRefinementValue; |
5
|
|
|
use GroupByInc\API\Url\UrlBeautifier; |
6
|
|
|
use GroupByInc\API\Url\UrlFunctions; |
7
|
|
|
|
8
|
|
|
class UrlFunctionsTest extends PHPUnit_Framework_TestCase |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
const DEFAULT_BEAUTIFIER = "default"; |
12
|
|
|
const DEFAULT_NAVIGATION = "default"; |
13
|
|
|
const HEIGHT_NAVIGATION = "height"; |
14
|
|
|
const CATEGORY_NAVIGATION = "category"; |
15
|
|
|
|
16
|
|
|
/** @var UrlBeautifier $beautifier */ |
17
|
|
|
private $beautifier; |
18
|
|
|
|
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
UrlBeautifier::createUrlBeautifier(self::DEFAULT_BEAUTIFIER); |
22
|
|
|
$this->beautifier = UrlBeautifier::getUrlBeautifiers()[self::DEFAULT_BEAUTIFIER]; |
23
|
|
|
$this->beautifier->addRefinementMapping('h', 'height') |
24
|
|
|
->setSearchMapping('q'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testAddToUrl() |
28
|
|
|
{ |
29
|
|
|
$navigations = []; |
30
|
|
|
$this->beautifier->addRefinementMapping('c', 'category'); |
31
|
|
|
$refinement = new SelectedRefinementValue(); |
32
|
|
|
$refinement->setValue('3.2m'); |
33
|
|
|
$url = UrlFunctions::toUrlAdd(self::DEFAULT_BEAUTIFIER, 'toast', $navigations, self::HEIGHT_NAVIGATION, $refinement); |
34
|
|
|
$this->assertEquals('/3.2m/toast/hq', $url); |
35
|
|
|
|
36
|
|
|
$nav1 = new Navigation(); |
37
|
|
|
$nav1->setName(self::HEIGHT_NAVIGATION)->setDisplayName("Height") |
38
|
|
|
->setType(Navigation\Type::String) |
39
|
|
|
->setRefinements([$refinement]); |
|
|
|
|
40
|
|
|
|
41
|
|
|
array_push($navigations, $nav1); |
42
|
|
|
|
43
|
|
|
$refinement = new SelectedRefinementValue(); |
44
|
|
|
$refinement->setValue('toys'); |
45
|
|
|
$url = UrlFunctions::toUrlAdd(self::DEFAULT_BEAUTIFIER, 'toast', $navigations, self::CATEGORY_NAVIGATION, $refinement); |
46
|
|
|
$this->assertEquals('/3.2m/toast/toys/hqc', $url); |
47
|
|
|
$this->assertEquals(1, count($navigations)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function testAddRangeToUrl() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$navigations = []; |
53
|
|
|
$this->beautifier->addRefinementMapping('c', 'category'); |
54
|
|
|
$refinement = new SelectedRefinementRange(); |
55
|
|
|
$refinement->setLow('12') |
56
|
|
|
->setHigh('34'); |
57
|
|
|
$url = UrlFunctions::toUrlAdd(self::DEFAULT_BEAUTIFIER, 'toast', $navigations, self::CATEGORY_NAVIGATION, $refinement); |
58
|
|
|
$this->assertEquals('/toast/q?refinements=%7Ecategory%3A12..34', $url); |
59
|
|
|
} |
60
|
|
|
public function testRemoveFromUrl() |
61
|
|
|
{ |
62
|
|
|
$navigations = []; |
63
|
|
|
$this->beautifier->addRefinementMapping('c', 'category'); |
64
|
|
|
$refinement1 = new SelectedRefinementValue(); |
65
|
|
|
$refinement1->setValue('3.2m'); |
66
|
|
|
|
67
|
|
|
$nav1 = new Navigation(); |
68
|
|
|
$nav1->setName(self::HEIGHT_NAVIGATION)->setDisplayName("Height") |
69
|
|
|
->setType(Navigation\Type::String) |
70
|
|
|
->setRefinements([$refinement1]); |
|
|
|
|
71
|
|
|
|
72
|
|
|
array_push($navigations, $nav1); |
73
|
|
|
|
74
|
|
|
$this->assertEquals(1, count($navigations)); |
75
|
|
|
$url = UrlFunctions::toUrlRemove(self::DEFAULT_BEAUTIFIER, 'toast', $navigations, self::HEIGHT_NAVIGATION, $refinement1); |
76
|
|
|
$this->assertEquals('/toast/q', $url); |
77
|
|
|
$this->assertEquals(0, count($navigations)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testRefinementAdditionWithMapping() { |
81
|
|
|
$navigations = []; |
82
|
|
|
|
83
|
|
|
$this->beautifier->addRefinementMapping('g', "gender"); |
84
|
|
|
$this->beautifier->addRefinementMapping('t', "product"); |
85
|
|
|
$this->beautifier->addRefinementMapping('s', "primarysport"); |
86
|
|
|
$this->beautifier->addRefinementMapping('c', "simpleColorDesc"); |
87
|
|
|
$this->beautifier->addRefinementMapping('l', "collections"); |
88
|
|
|
$this->beautifier->addRefinementMapping('f', "league"); |
89
|
|
|
$this->beautifier->setAppend("/index.html"); |
90
|
|
|
|
91
|
|
|
$refinement1 = new SelectedRefinementValue(); |
92
|
|
|
$refinement1->setValue("Women"); |
93
|
|
|
|
94
|
|
|
$nav1 = new Navigation(); |
95
|
|
|
$nav1->setName("gender")->setDisplayName("Gender") |
96
|
|
|
->setType(Navigation\Type::String) |
97
|
|
|
->setRefinements([$refinement1]); |
|
|
|
|
98
|
|
|
|
99
|
|
|
$refinement2 = new SelectedRefinementValue(); |
100
|
|
|
$refinement2->setValue("Pink"); |
101
|
|
|
|
102
|
|
|
$nav2 = new Navigation(); |
103
|
|
|
$nav2->setName("simpleColorDesc")->setDisplayName("Color") |
104
|
|
|
->setType(Navigation\Type::String) |
105
|
|
|
->setRefinements([$refinement2]); |
|
|
|
|
106
|
|
|
|
107
|
|
|
array_push($navigations, $nav1, $nav2); |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
$refinement3 = new SelectedRefinementValue(); |
111
|
|
|
$refinement3->setValue("Clothing"); |
112
|
|
|
|
113
|
|
|
$url = UrlFunctions::toUrlAdd(self::DEFAULT_BEAUTIFIER, '', $navigations, 'product', $refinement3); |
114
|
|
|
$this->assertEquals("/Women/Clothing/Pink/gtc/index.html", $url); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testRefinementAdditionWithoutMapping() { |
118
|
|
|
$navigations = []; |
119
|
|
|
|
120
|
|
|
$this->beautifier->setAppend("/index.html"); |
121
|
|
|
|
122
|
|
|
$refinement1 = new SelectedRefinementValue(); |
123
|
|
|
$refinement1->setValue("Women"); |
124
|
|
|
|
125
|
|
|
$nav1 = new Navigation(); |
126
|
|
|
$nav1->setName("gender")->setDisplayName("Gender") |
127
|
|
|
->setType(Navigation\Type::String) |
128
|
|
|
->setRefinements([$refinement1]); |
|
|
|
|
129
|
|
|
|
130
|
|
|
$refinement2 = new SelectedRefinementValue(); |
131
|
|
|
$refinement2->setValue("Pink"); |
132
|
|
|
|
133
|
|
|
$nav2 = new Navigation(); |
134
|
|
|
$nav2->setName("simpleColorDesc")->setDisplayName("Color") |
135
|
|
|
->setType(Navigation\Type::String) |
136
|
|
|
->setRefinements([$refinement2]); |
|
|
|
|
137
|
|
|
|
138
|
|
|
array_push($navigations, $nav1, $nav2); |
139
|
|
|
|
140
|
|
|
$refinement3 = new SelectedRefinementValue(); |
141
|
|
|
$refinement3->setValue("Clothing"); |
142
|
|
|
|
143
|
|
|
$url = UrlFunctions::toUrlAdd(self::DEFAULT_BEAUTIFIER, '', $navigations, 'product', $refinement3); |
144
|
|
|
$this->assertEquals("/index.html?refinements=%7Egender%3DWomen%7EsimpleColorDesc%3DPink%7Eproduct%3DClothing", $url); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testRefinementAdditionWithMappingMulti() { |
148
|
|
|
$navigations = []; |
149
|
|
|
|
150
|
|
|
$this->beautifier->addRefinementMapping('g', "gender"); |
151
|
|
|
$this->beautifier->addRefinementMapping('t', "product"); |
152
|
|
|
$this->beautifier->addRefinementMapping('s', "primarysport"); |
153
|
|
|
$this->beautifier->addRefinementMapping('c', "simpleColorDesc"); |
154
|
|
|
$this->beautifier->addRefinementMapping('l', "collections"); |
155
|
|
|
$this->beautifier->addRefinementMapping('f', "league"); |
156
|
|
|
$this->beautifier->setAppend("/index.html"); |
157
|
|
|
|
158
|
|
|
$refinement1 = new SelectedRefinementValue(); |
159
|
|
|
$refinement1->setValue("Women"); |
160
|
|
|
|
161
|
|
|
$nav1 = new Navigation(); |
162
|
|
|
$nav1->setName("gender")->setDisplayName("Gender") |
163
|
|
|
->setType(Navigation\Type::String) |
164
|
|
|
->setRefinements([$refinement1]); |
|
|
|
|
165
|
|
|
|
166
|
|
|
$refinement2 = new SelectedRefinementValue(); |
167
|
|
|
$refinement2->setValue("Pink"); |
168
|
|
|
|
169
|
|
|
$nav2 = new Navigation(); |
170
|
|
|
$nav2->setName("simpleColorDesc")->setDisplayName("Color") |
171
|
|
|
->setType(Navigation\Type::String) |
172
|
|
|
->setRefinements([$refinement2]); |
|
|
|
|
173
|
|
|
|
174
|
|
|
array_push($navigations, $nav1, $nav2); |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
$refinement3 = new SelectedRefinementValue(); |
178
|
|
|
$refinement3->setValue("Men"); |
179
|
|
|
|
180
|
|
|
$url = UrlFunctions::toUrlAdd(self::DEFAULT_BEAUTIFIER, '', $navigations, 'gender', $refinement3); |
181
|
|
|
$this->assertEquals("/Women/Men/Pink/ggc/index.html", $url); |
182
|
|
|
|
183
|
|
|
$refinement4 = new SelectedRefinementValue(); |
184
|
|
|
$refinement4->setValue("Kid"); |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
$url = UrlFunctions::toUrlAdd(self::DEFAULT_BEAUTIFIER, '', $navigations, 'gender', $refinement4); |
188
|
|
|
$this->assertEquals("/Women/Kid/Pink/ggc/index.html", $url); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
View Code Duplication |
public function testRefinementAdditionWithCategoryExpansion () { |
|
|
|
|
192
|
|
|
$navigations = []; |
193
|
|
|
|
194
|
|
|
$this->beautifier->addRefinementMapping('s', "size"); |
195
|
|
|
$this->beautifier->setAppend("/index.html"); |
196
|
|
|
|
197
|
|
|
$refinement = new SelectedRefinementValue(); |
198
|
|
|
$refinement->setValue("Category Root~Athletics~Men's~Sneakers"); |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
$url = UrlFunctions::toUrlAdd(self::DEFAULT_BEAUTIFIER, '', $navigations, 'category_leaf_expanded', $refinement); |
202
|
|
|
$this->assertEquals("/index.html?refinements=%7Ecategory_leaf_expanded%3DCategory+Root%7EAthletics%7EMen%27s%7ESneakers", $url); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.