Completed
Push — master ( e3c734...8f98ed )
by Daniel
03:08 queued 16s
created

testSearchResultsLimitAndStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 22
rs 9.2
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
class RegistryPageFunctionalTest extends FunctionalTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
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));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
		$this->assertEquals('Alexander', (string) $cells[0]);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
		$this->assertEquals('Bernie', (string) $cells[1]);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
		$this->assertEquals(4, count($anchors), '4 paging anchors, including next');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
		$this->assertEquals('FirstName', (string) $sortField[0]['value']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
		$this->assertEquals('DESC', (string) $dirField[0]['value']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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]);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RegistryPageFunctionalTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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
}
0 ignored issues
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...
140
141