1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Registry\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\Controller; |
6
|
|
|
use SilverStripe\Dev\CSSContentParser; |
7
|
|
|
use SilverStripe\Dev\FunctionalTest; |
8
|
|
|
use SilverStripe\Registry\Tests\Stub\RegistryPageTestContact; |
9
|
|
|
use SilverStripe\Registry\Tests\Stub\RegistryPageTestContactExtra; |
10
|
|
|
use SilverStripe\Registry\Tests\Stub\RegistryPageTestPage; |
11
|
|
|
|
12
|
|
|
class RegistryPageFunctionalTest extends FunctionalTest |
13
|
|
|
{ |
14
|
|
|
protected static $fixture_file = [ |
15
|
|
|
'fixtures/RegistryPageFunctionalTest.yml', |
16
|
|
|
'fixtures/RegistryPageTestContact.yml' |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
protected static $extra_dataobjects = [ |
20
|
|
|
RegistryPageTestContact::class, |
21
|
|
|
RegistryPageTestContactExtra::class, |
22
|
|
|
RegistryPageTestPage::class |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
protected static $use_draft_site = true; |
26
|
|
|
|
27
|
|
|
public function testUseLink() |
28
|
|
|
{ |
29
|
|
|
// Page with links |
30
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-extra'); |
31
|
|
|
$response = $this->get($page->Link()); |
32
|
|
|
$parser = new CSSContentParser($response->getBody()); |
33
|
|
|
|
34
|
|
|
$cells = $parser->getBySelector('table.results tbody tr td'); |
35
|
|
|
|
36
|
|
|
$this->assertContains('/contact-search-extra/', (string)$cells[0]->a->attributes()->href[0]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testFilteredSearchResults() |
40
|
|
|
{ |
41
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
42
|
|
|
$uri = Controller::join_links( |
43
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
44
|
|
|
'?' . |
45
|
|
|
http_build_query(array( |
46
|
|
|
'FirstName' => 'Alexander', |
47
|
|
|
'action_doRegistryFilter' => 'Filter' |
48
|
|
|
)) |
49
|
|
|
); |
50
|
|
|
$response = $this->get($uri); |
51
|
|
|
|
52
|
|
|
$parser = new CSSContentParser($response->getBody()); |
53
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
54
|
|
|
|
55
|
|
|
$cells = $rows[0]->td; |
56
|
|
|
|
57
|
|
|
$this->assertCount(1, $rows); |
58
|
|
|
$this->assertEquals('Alexander', trim((string)$cells[0])); |
59
|
|
|
$this->assertEquals('Bernie', trim((string)$cells[1])); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testFilteredByRelationSearchResults() |
63
|
|
|
{ |
64
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-extra'); |
65
|
|
|
$uri = Controller::join_links( |
66
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
67
|
|
|
'?' . http_build_query(array( |
68
|
|
|
'RegistryPage.Title' => $page->Title, |
69
|
|
|
'action_doRegistryFilter' => 'Filter' |
70
|
|
|
)) |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$response = $this->get($uri); |
74
|
|
|
|
75
|
|
|
$parser = new CSSContentParser($response->getBody()); |
76
|
|
|
|
77
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
78
|
|
|
$cells = $rows[0]->td; |
79
|
|
|
|
80
|
|
|
$this->assertCount(1, $rows); |
81
|
|
|
$this->assertEquals('Jimmy', trim((string)$cells[0]->a[0])); |
82
|
|
|
$this->assertEquals('Sherson', trim((string)$cells[1]->a[0])); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Check that RegistryPageController can filter for ExactMatches (ID) for relationships. |
87
|
|
|
* |
88
|
|
|
* @throws \Exception |
89
|
|
|
*/ |
90
|
|
|
public function testFilteredByRelationIDSearchResults() |
91
|
|
|
{ |
92
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-extra'); |
93
|
|
|
$uri = Controller::join_links( |
94
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
95
|
|
|
'?' . http_build_query(array( |
96
|
|
|
'RegistryPage.ID' => $page->ID, |
97
|
|
|
'action_doRegistryFilter' => 'Filter', |
98
|
|
|
)) |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
// If this is wrong then the configuration system is broken. |
102
|
|
|
$this->assertCount(4, $page->getDataSingleton()->config()->get('searchable_fields')); |
103
|
|
|
|
104
|
|
|
$response = $this->get($uri); |
105
|
|
|
|
106
|
|
|
$parser = new CSSContentParser($response->getBody()); |
107
|
|
|
|
108
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
109
|
|
|
|
110
|
|
|
// there should only be one user with that ID from our YML |
111
|
|
|
$this->assertCount(1, $rows); |
112
|
|
|
$cells = $rows[0]->td; |
113
|
|
|
|
114
|
|
|
$this->assertCount(1, $rows); |
115
|
|
|
$this->assertEquals('Jimmy', trim((string)$cells[0]->a)); |
116
|
|
|
$this->assertEquals('Sherson', trim((string)$cells[1]->a)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testUserCustomSummaryField() |
120
|
|
|
{ |
121
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-extra'); |
122
|
|
|
$response = $this->get($page->Link()); |
123
|
|
|
$parser = new CSSContentParser($response->getBody()); |
124
|
|
|
|
125
|
|
|
$cells = $parser->getBySelector('table.results tbody tr td'); |
126
|
|
|
|
127
|
|
|
$this->assertContains($page->getDataSingleton()->getStaticReference(), trim((string)$cells[4]->a[0])); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function testSearchResultsLimitAndStart() |
131
|
|
|
{ |
132
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-limit'); |
133
|
|
|
$uri = Controller::join_links( |
134
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
135
|
|
|
'?' . http_build_query(array( |
136
|
|
|
'Sort' => 'FirstName', |
137
|
|
|
'Dir' => 'DESC', |
138
|
|
|
'action_doRegistryFilter' => 'Filter' |
139
|
|
|
)) |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
$response = $this->get($uri); |
143
|
|
|
|
144
|
|
|
$parser = new CSSContentParser($response->getBody()); |
145
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
146
|
|
|
$anchors = $parser->getBySelector('ul.pageNumbers li a'); |
147
|
|
|
|
148
|
|
|
$this->assertCount(3, $rows, 'Limited to 3 search results'); |
149
|
|
|
$this->assertCount(4, $anchors, '4 paging anchors, including next'); |
150
|
|
|
|
151
|
|
|
$this->assertContains('Sort=FirstName', (string)$anchors[0]['href']); |
152
|
|
|
$this->assertContains('Dir=DESC', (string)$anchors[0]['href']); |
153
|
|
|
|
154
|
|
|
$this->assertContains('start=0', (string)$anchors[0]['href']); |
155
|
|
|
$this->assertContains('start=3', (string)$anchors[1]['href']); |
156
|
|
|
$this->assertContains('start=6', (string)$anchors[2]['href']); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testGetParamsPopulatesSearchForm() |
160
|
|
|
{ |
161
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
162
|
|
|
$uri = Controller::join_links( |
163
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
164
|
|
|
'?' . http_build_query(array( |
165
|
|
|
'FirstName' => 'Alexander', |
166
|
|
|
'Sort' => 'FirstName', |
167
|
|
|
'Dir' => 'DESC', |
168
|
|
|
'action_doRegistryFilter' => 'Filter' |
169
|
|
|
)) |
170
|
|
|
); |
171
|
|
|
$response = $this->get($uri); |
172
|
|
|
|
173
|
|
|
$parser = new CSSContentParser($response->getBody()); |
174
|
|
|
$firstNameField = $parser->getBySelector('#Form_RegistryFilterForm_FirstName'); |
175
|
|
|
$sortField = $parser->getBySelector('#Form_RegistryFilterForm_Sort'); |
176
|
|
|
$dirField = $parser->getBySelector('#Form_RegistryFilterForm_Dir'); |
177
|
|
|
|
178
|
|
|
$this->assertEquals('Alexander', (string)$firstNameField[0]['value']); |
179
|
|
|
$this->assertEquals('FirstName', (string)$sortField[0]['value']); |
180
|
|
|
$this->assertEquals('DESC', (string)$dirField[0]['value']); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function testQueryLinks() |
184
|
|
|
{ |
185
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
186
|
|
|
$uri = Controller::join_links( |
187
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
188
|
|
|
'?' . http_build_query(array( |
189
|
|
|
'FirstName' => 'Alexander', |
190
|
|
|
'action_doRegistryFilter' => 'Filter' |
191
|
|
|
)) |
192
|
|
|
); |
193
|
|
|
$response = $this->get($uri); |
194
|
|
|
|
195
|
|
|
$parser = new CSSContentParser($response->getBody()); |
196
|
|
|
$rows = $parser->getBySelector('table.results thead tr'); |
197
|
|
|
$anchors = $rows[0]->th->a; |
198
|
|
|
|
199
|
|
|
$this->assertContains('FirstName=Alexander', (string)$anchors[0]['href']); |
200
|
|
|
$this->assertContains('Surname=', (string)$anchors[0]['href']); |
201
|
|
|
$this->assertContains('Sort=FirstName', (string)$anchors[0]['href']); |
202
|
|
|
$this->assertContains('Dir=ASC', (string)$anchors[0]['href']); |
203
|
|
|
$this->assertContains('action_doRegistryFilter=Filter', (string)$anchors[0]['href']); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function testShowExistingRecord() |
207
|
|
|
{ |
208
|
|
|
$record = $this->objFromFixture(RegistryPageTestContact::class, 'alexander'); |
209
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
210
|
|
|
$response = $this->get(Controller::join_links($page->RelativeLink(), 'show', $record->ID)); |
211
|
|
|
|
212
|
|
|
$this->assertContains('Alexander Bernie', $response->getBody()); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function testPageNotFoundNonExistantRecord() |
216
|
|
|
{ |
217
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
218
|
|
|
$response = $this->get(Controller::join_links($page->RelativeLink(), 'show', '123456')); |
219
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function testColumnName() |
223
|
|
|
{ |
224
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
225
|
|
|
$uri = Controller::join_links( |
226
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
227
|
|
|
'?' . http_build_query(array( |
228
|
|
|
'action_doRegistryFilter' => 'Filter' |
229
|
|
|
)) |
230
|
|
|
); |
231
|
|
|
$response = $this->get($uri); |
232
|
|
|
|
233
|
|
|
$parser = new CSSContentParser($response->getBody()); |
234
|
|
|
$rows = $parser->getBySelector('table.results thead tr'); |
235
|
|
|
$anchors = $rows[0]->th->a; |
236
|
|
|
|
237
|
|
|
$this->assertEquals('First name', trim((string)$anchors[0])); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
public function testSortableColumns() |
241
|
|
|
{ |
242
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-extra'); |
243
|
|
|
$response = $this->get($page->Link()); |
244
|
|
|
$parser = new CSSContentParser($response->getBody()); |
245
|
|
|
$columns = $parser->getBySelector('table.results thead tr th'); |
246
|
|
|
|
247
|
|
|
$this->assertNotEmpty($columns[0]->a); |
248
|
|
|
$this->assertNotEmpty($columns[1]->a); |
249
|
|
|
$this->assertNotEmpty($columns[2]->a); |
250
|
|
|
$this->assertNotEmpty($columns[3]->a); |
251
|
|
|
$this->assertEquals('Other', trim((string)$columns[4])); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function testExportLink() |
255
|
|
|
{ |
256
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
257
|
|
|
$uri = Controller::join_links( |
258
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
259
|
|
|
'?' . http_build_query(array( |
260
|
|
|
'FirstName' => 'Alexander', |
261
|
|
|
'Sort' => 'FirstName', |
262
|
|
|
'Dir' => 'DESC', |
263
|
|
|
'action_doRegistryFilter' => 'Filter' |
264
|
|
|
)) |
265
|
|
|
); |
266
|
|
|
$response = $this->get($uri); |
267
|
|
|
|
268
|
|
|
$parser = new CSSContentParser($response->getBody()); |
269
|
|
|
$anchor = $parser->getBySelector('a.export'); |
270
|
|
|
|
271
|
|
|
$this->assertContains('export?', (string)$anchor[0]['href']); |
272
|
|
|
$this->assertContains('FirstName=Alexander', (string)$anchor[0]['href']); |
273
|
|
|
$this->assertContains('Surname=', (string)$anchor[0]['href']); |
274
|
|
|
$this->assertContains('Sort=FirstName', (string)$anchor[0]['href']); |
275
|
|
|
$this->assertContains('Dir=DESC', (string)$anchor[0]['href']); |
276
|
|
|
$this->assertContains('action_doRegistryFilter=Filter', (string)$anchor[0]['href']); |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
|