|
1
|
|
|
<?php |
|
2
|
|
|
class RegistryPageFunctionalTest extends FunctionalTest { |
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
public static $fixture_file = array( |
|
5
|
|
|
'fixtures/RegistryPageTestContact.yml', |
|
6
|
|
|
'fixtures/RegistryPageFunctionalTest.yml' |
|
7
|
|
|
); |
|
8
|
|
|
|
|
9
|
|
|
protected $extraDataObjects = array( |
|
10
|
|
|
'RegistryPageTestPage', |
|
11
|
|
|
'RegistryPageTestContact' |
|
12
|
|
|
); |
|
13
|
|
|
|
|
14
|
|
|
public static $use_draft_site = true; |
|
15
|
|
|
|
|
16
|
|
|
public function testFilteredSearchResults() { |
|
17
|
|
|
$page = $this->objFromFixture('RegistryPageTestPage', 'contact-registrypage'); |
|
18
|
|
|
$response = $this->get($page->RelativeLink('RegistryFilterForm') . '?' . http_build_query(array( |
|
19
|
|
|
'FirstName' => 'Alexander', |
|
20
|
|
|
'action_doRegistryFilter' => 'Filter' |
|
21
|
|
|
))); |
|
22
|
|
|
|
|
23
|
|
|
$parser = new CSSContentParser($response->getBody()); |
|
24
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
|
25
|
|
|
$cells = $rows[0]->td; |
|
26
|
|
|
|
|
27
|
|
|
$this->assertEquals(1, count($rows)); |
|
|
|
|
|
|
28
|
|
|
$this->assertEquals('Alexander', (string) $cells[0]); |
|
|
|
|
|
|
29
|
|
|
$this->assertEquals('Bernie', (string) $cells[1]); |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testSearchResultsLimitAndStart() { |
|
33
|
|
|
$page = $this->objFromFixture('RegistryPageTestPage', 'contact-registrypage-limit'); |
|
34
|
|
|
$response = $this->get($page->RelativeLink('RegistryFilterForm') . '?' . http_build_query(array( |
|
35
|
|
|
'Sort' => 'FirstName', |
|
36
|
|
|
'Dir' => 'DESC', |
|
37
|
|
|
'action_doRegistryFilter' => 'Filter' |
|
38
|
|
|
))); |
|
39
|
|
|
|
|
40
|
|
|
$parser = new CSSContentParser($response->getBody()); |
|
41
|
|
|
$rows = $parser->getBySelector('table.results tbody tr'); |
|
42
|
|
|
$anchors = $parser->getBySelector('ul.pageNumbers li a'); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals(3, count($rows), 'Limited to 3 search results'); |
|
|
|
|
|
|
45
|
|
|
$this->assertEquals(4, count($anchors), '4 paging anchors, including next'); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$this->assertContains('Sort=FirstName', (string) $anchors[0]['href']); |
|
48
|
|
|
$this->assertContains('Dir=DESC', (string) $anchors[0]['href']); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertContains('start=0', (string) $anchors[0]['href']); |
|
51
|
|
|
$this->assertContains('start=3', (string) $anchors[1]['href']); |
|
52
|
|
|
$this->assertContains('start=6', (string) $anchors[2]['href']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testGetParamsPopulatesSearchForm() { |
|
56
|
|
|
$page = $this->objFromFixture('RegistryPageTestPage', 'contact-registrypage'); |
|
57
|
|
|
$response = $this->get($page->RelativeLink('RegistryFilterForm') . '?' . http_build_query(array( |
|
58
|
|
|
'FirstName' => 'Alexander', |
|
59
|
|
|
'Sort' => 'FirstName', |
|
60
|
|
|
'Dir' => 'DESC', |
|
61
|
|
|
'action_doRegistryFilter' => 'Filter' |
|
62
|
|
|
))); |
|
63
|
|
|
|
|
64
|
|
|
$parser = new CSSContentParser($response->getBody()); |
|
65
|
|
|
$firstNameField = $parser->getBySelector('#Form_RegistryFilterForm_FirstName'); |
|
66
|
|
|
$sortField = $parser->getBySelector('#Form_RegistryFilterForm_Sort'); |
|
67
|
|
|
$dirField = $parser->getBySelector('#Form_RegistryFilterForm_Dir'); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertEquals('Alexander', (string) $firstNameField[0]['value']); |
|
|
|
|
|
|
70
|
|
|
$this->assertEquals('FirstName', (string) $sortField[0]['value']); |
|
|
|
|
|
|
71
|
|
|
$this->assertEquals('DESC', (string) $dirField[0]['value']); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testQueryLinks() { |
|
75
|
|
|
$page = $this->objFromFixture('RegistryPageTestPage', 'contact-registrypage'); |
|
76
|
|
|
$response = $this->get($page->RelativeLink('RegistryFilterForm') . '?' . http_build_query(array( |
|
77
|
|
|
'FirstName' => 'Alexander', |
|
78
|
|
|
'action_doRegistryFilter' => 'Filter' |
|
79
|
|
|
))); |
|
80
|
|
|
|
|
81
|
|
|
$parser = new CSSContentParser($response->getBody()); |
|
82
|
|
|
$rows = $parser->getBySelector('table.results thead tr'); |
|
83
|
|
|
$anchors = $rows[0]->th->a; |
|
84
|
|
|
|
|
85
|
|
|
$this->assertContains('FirstName=Alexander', (string) $anchors[0]['href']); |
|
86
|
|
|
$this->assertContains('Surname=', (string) $anchors[0]['href']); |
|
87
|
|
|
$this->assertContains('Sort=FirstName', (string) $anchors[0]['href']); |
|
88
|
|
|
$this->assertContains('Dir=ASC', (string) $anchors[0]['href']); |
|
89
|
|
|
$this->assertContains('action_doRegistryFilter=Filter', (string) $anchors[0]['href']); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testShowExistingRecord() { |
|
93
|
|
|
$record = $this->objFromFixture('RegistryPageTestContact', 'alexander'); |
|
94
|
|
|
$page = $this->objFromFixture('RegistryPageTestPage', 'contact-registrypage'); |
|
95
|
|
|
$response = $this->get(Controller::join_links($page->RelativeLink(), 'show', $record->ID)); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertContains('Alexander Bernie', $response->getBody()); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testPageNotFoundNonExistantRecord() { |
|
101
|
|
|
$page = $this->objFromFixture('RegistryPageTestPage', 'contact-registrypage'); |
|
102
|
|
|
$response = $this->get(Controller::join_links($page->RelativeLink(), 'show', '123456')); |
|
103
|
|
|
$this->assertEquals(404, $response->getStatusCode()); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testColumnName() { |
|
107
|
|
|
$page = $this->objFromFixture('RegistryPageTestPage', 'contact-registrypage'); |
|
108
|
|
|
$response = $this->get($page->RelativeLink('RegistryFilterForm') . '?' . http_build_query(array( |
|
109
|
|
|
'action_doRegistryFilter' => 'Filter' |
|
110
|
|
|
))); |
|
111
|
|
|
|
|
112
|
|
|
$parser = new CSSContentParser($response->getBody()); |
|
113
|
|
|
$rows = $parser->getBySelector('table.results thead tr'); |
|
114
|
|
|
$anchors = $rows[0]->th->a; |
|
115
|
|
|
|
|
116
|
|
|
$this->assertEquals('First name', (string) $anchors[0]); |
|
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testExportLink() { |
|
120
|
|
|
$page = $this->objFromFixture('RegistryPageTestPage', 'contact-registrypage'); |
|
121
|
|
|
$response = $this->get($page->RelativeLink('RegistryFilterForm') . '?' . http_build_query(array( |
|
122
|
|
|
'FirstName' => 'Alexander', |
|
123
|
|
|
'Sort' => 'FirstName', |
|
124
|
|
|
'Dir' => 'DESC', |
|
125
|
|
|
'action_doRegistryFilter' => 'Filter' |
|
126
|
|
|
))); |
|
127
|
|
|
|
|
128
|
|
|
$parser = new CSSContentParser($response->getBody()); |
|
129
|
|
|
$anchor = $parser->getBySelector('a.export'); |
|
130
|
|
|
|
|
131
|
|
|
$this->assertContains('export?', (string) $anchor[0]['href']); |
|
132
|
|
|
$this->assertContains('FirstName=Alexander', (string) $anchor[0]['href']); |
|
133
|
|
|
$this->assertContains('Surname=', (string) $anchor[0]['href']); |
|
134
|
|
|
$this->assertContains('Sort=FirstName', (string) $anchor[0]['href']); |
|
135
|
|
|
$this->assertContains('Dir=DESC', (string) $anchor[0]['href']); |
|
136
|
|
|
$this->assertContains('action_doRegistryFilter=Filter', (string) $anchor[0]['href']); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
} |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
|
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.