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