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
|
|
|
// Page without links |
39
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
40
|
|
|
$response = $this->get($page->Link()); |
41
|
|
|
$parser = new CSSContentParser($response->getBody()); |
42
|
|
|
|
43
|
|
|
$cells = $parser->getBySelector('table.results tbody tr td'); |
44
|
|
|
|
45
|
|
|
$this->assertEquals('Alexander', $cells[0][0]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testFilteredSearchResults() |
49
|
|
|
{ |
50
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
51
|
|
|
$uri = Controller::join_links( |
52
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
53
|
|
|
'?' . |
54
|
|
|
http_build_query(array( |
55
|
|
|
'FirstName' => 'Alexander', |
56
|
|
|
'action_doRegistryFilter' => 'Filter' |
57
|
|
|
)) |
58
|
|
|
); |
59
|
|
|
$response = $this->get($uri); |
60
|
|
|
|
61
|
|
|
$parser = new CSSContentParser($response->getBody()); |
62
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
63
|
|
|
|
64
|
|
|
$cells = $rows[0]->td; |
65
|
|
|
|
66
|
|
|
$this->assertCount(1, $rows); |
67
|
|
|
$this->assertEquals('Alexander', (string) $cells[0]); |
68
|
|
|
$this->assertEquals('Bernie', (string) $cells[1]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testFilteredByRelationSearchResults() |
72
|
|
|
{ |
73
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-extra'); |
74
|
|
|
$uri = Controller::join_links( |
75
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
76
|
|
|
'?' . http_build_query(array( |
77
|
|
|
'RegistryPage.Title' => $page->Title, |
78
|
|
|
'action_doRegistryFilter' => 'Filter' |
79
|
|
|
)) |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$response = $this->get($uri); |
83
|
|
|
|
84
|
|
|
$parser = new CSSContentParser($response->getBody()); |
85
|
|
|
|
86
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
87
|
|
|
$cells = $rows[0]->td; |
88
|
|
|
|
89
|
|
|
$this->assertCount(1, $rows); |
90
|
|
|
$this->assertEquals('Jimmy', (string) $cells[0]->a[0]); |
91
|
|
|
$this->assertEquals('Sherson', (string) $cells[1]->a[0]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testUserCustomSummaryField() |
95
|
|
|
{ |
96
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-extra'); |
97
|
|
|
$response = $this->get($page->Link()); |
98
|
|
|
$parser = new CSSContentParser($response->getBody()); |
99
|
|
|
|
100
|
|
|
$cells = $parser->getBySelector('table.results tbody tr td'); |
101
|
|
|
|
102
|
|
|
$this->assertContains($page->getDataSingleton()->getStaticReference(), (string) $cells[3]->a[0]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testSearchResultsLimitAndStart() |
106
|
|
|
{ |
107
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-limit'); |
108
|
|
|
$uri = Controller::join_links( |
109
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
110
|
|
|
'?' . http_build_query(array( |
111
|
|
|
'Sort' => 'FirstName', |
112
|
|
|
'Dir' => 'DESC', |
113
|
|
|
'action_doRegistryFilter' => 'Filter' |
114
|
|
|
)) |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
$response = $this->get($uri); |
119
|
|
|
|
120
|
|
|
$parser = new CSSContentParser($response->getBody()); |
121
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
122
|
|
|
$anchors = $parser->getBySelector('ul.pageNumbers li a'); |
123
|
|
|
|
124
|
|
|
$this->assertCount(3, $rows, 'Limited to 3 search results'); |
125
|
|
|
$this->assertCount(4, $anchors, '4 paging anchors, including next'); |
126
|
|
|
|
127
|
|
|
$this->assertContains('Sort=FirstName', (string) $anchors[0]['href']); |
128
|
|
|
$this->assertContains('Dir=DESC', (string) $anchors[0]['href']); |
129
|
|
|
|
130
|
|
|
$this->assertContains('start=0', (string) $anchors[0]['href']); |
131
|
|
|
$this->assertContains('start=3', (string) $anchors[1]['href']); |
132
|
|
|
$this->assertContains('start=6', (string) $anchors[2]['href']); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testGetParamsPopulatesSearchForm() |
136
|
|
|
{ |
137
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
138
|
|
|
$uri = Controller::join_links( |
139
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
140
|
|
|
'?' . http_build_query(array( |
141
|
|
|
'FirstName' => 'Alexander', |
142
|
|
|
'Sort' => 'FirstName', |
143
|
|
|
'Dir' => 'DESC', |
144
|
|
|
'action_doRegistryFilter' => 'Filter' |
145
|
|
|
)) |
146
|
|
|
); |
147
|
|
|
$response = $this->get($uri); |
148
|
|
|
|
149
|
|
|
$parser = new CSSContentParser($response->getBody()); |
150
|
|
|
$firstNameField = $parser->getBySelector('#Form_RegistryFilterForm_FirstName'); |
151
|
|
|
$sortField = $parser->getBySelector('#Form_RegistryFilterForm_Sort'); |
152
|
|
|
$dirField = $parser->getBySelector('#Form_RegistryFilterForm_Dir'); |
153
|
|
|
|
154
|
|
|
$this->assertEquals('Alexander', (string) $firstNameField[0]['value']); |
155
|
|
|
$this->assertEquals('FirstName', (string) $sortField[0]['value']); |
156
|
|
|
$this->assertEquals('DESC', (string) $dirField[0]['value']); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testQueryLinks() |
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
|
|
|
'action_doRegistryFilter' => 'Filter' |
167
|
|
|
)) |
168
|
|
|
); |
169
|
|
|
$response = $this->get($uri); |
170
|
|
|
|
171
|
|
|
$parser = new CSSContentParser($response->getBody()); |
172
|
|
|
$rows = $parser->getBySelector('table.results thead tr'); |
173
|
|
|
$anchors = $rows[0]->th->a; |
174
|
|
|
|
175
|
|
|
$this->assertContains('FirstName=Alexander', (string) $anchors[0]['href']); |
176
|
|
|
$this->assertContains('Surname=', (string) $anchors[0]['href']); |
177
|
|
|
$this->assertContains('Sort=FirstName', (string) $anchors[0]['href']); |
178
|
|
|
$this->assertContains('Dir=ASC', (string) $anchors[0]['href']); |
179
|
|
|
$this->assertContains('action_doRegistryFilter=Filter', (string) $anchors[0]['href']); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function testShowExistingRecord() |
183
|
|
|
{ |
184
|
|
|
$record = $this->objFromFixture(RegistryPageTestContact::class, 'alexander'); |
185
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
186
|
|
|
$response = $this->get(Controller::join_links($page->RelativeLink(), 'show', $record->ID)); |
187
|
|
|
|
188
|
|
|
$this->assertContains('Alexander Bernie', $response->getBody()); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function testPageNotFoundNonExistantRecord() |
192
|
|
|
{ |
193
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
194
|
|
|
$response = $this->get(Controller::join_links($page->RelativeLink(), 'show', '123456')); |
195
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function testColumnName() |
199
|
|
|
{ |
200
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
201
|
|
|
$uri = Controller::join_links( |
202
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
203
|
|
|
'?' . http_build_query(array( |
204
|
|
|
'action_doRegistryFilter' => 'Filter' |
205
|
|
|
)) |
206
|
|
|
); |
207
|
|
|
$response = $this->get($uri); |
208
|
|
|
|
209
|
|
|
$parser = new CSSContentParser($response->getBody()); |
210
|
|
|
$rows = $parser->getBySelector('table.results thead tr'); |
211
|
|
|
$anchors = $rows[0]->th->a; |
212
|
|
|
|
213
|
|
|
$this->assertEquals('First name', (string) $anchors[0]); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function testSortableColumns() |
217
|
|
|
{ |
218
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage-extra'); |
219
|
|
|
$response = $this->get($page->Link()); |
220
|
|
|
$parser = new CSSContentParser($response->getBody()); |
221
|
|
|
$columns = $parser->getBySelector('table.results thead tr th'); |
222
|
|
|
|
223
|
|
|
$this->assertNotEmpty($columns[0]->a); |
224
|
|
|
$this->assertNotEmpty($columns[1]->a); |
225
|
|
|
$this->assertNotEmpty($columns[2]->a); |
226
|
|
|
$this->assertEquals('Other', $columns[3]); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function testExportLink() |
230
|
|
|
{ |
231
|
|
|
$page = $this->objFromFixture(RegistryPageTestPage::class, 'contact-registrypage'); |
232
|
|
|
$uri = Controller::join_links( |
233
|
|
|
$page->RelativeLink('RegistryFilterForm'), |
234
|
|
|
'?' . http_build_query(array( |
235
|
|
|
'FirstName' => 'Alexander', |
236
|
|
|
'Sort' => 'FirstName', |
237
|
|
|
'Dir' => 'DESC', |
238
|
|
|
'action_doRegistryFilter' => 'Filter' |
239
|
|
|
)) |
240
|
|
|
); |
241
|
|
|
$response = $this->get($uri); |
242
|
|
|
|
243
|
|
|
$parser = new CSSContentParser($response->getBody()); |
244
|
|
|
$anchor = $parser->getBySelector('a.export'); |
245
|
|
|
|
246
|
|
|
$this->assertContains('export?', (string) $anchor[0]['href']); |
247
|
|
|
$this->assertContains('FirstName=Alexander', (string) $anchor[0]['href']); |
248
|
|
|
$this->assertContains('Surname=', (string) $anchor[0]['href']); |
249
|
|
|
$this->assertContains('Sort=FirstName', (string) $anchor[0]['href']); |
250
|
|
|
$this->assertContains('Dir=DESC', (string) $anchor[0]['href']); |
251
|
|
|
$this->assertContains('action_doRegistryFilter=Filter', (string) $anchor[0]['href']); |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|