1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Provides test methods to ensure pages contain what we want them to in various ways. |
5
|
|
|
*/ |
6
|
|
|
class AlertsPageTest extends FetchPageTestCase { |
7
|
|
|
/** |
8
|
|
|
* Loads the member testing fixture. |
9
|
|
|
*/ |
10
|
|
|
public function getDataSet() { |
11
|
|
|
return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/alertspage.xml'); |
|
|
|
|
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
private function fetch_page($vars) { |
15
|
|
|
return $this->base_fetch_page($vars, 'alert'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
private function get_page($vars = []) { |
19
|
|
|
return $this->base_fetch_page_user($vars, '1.fbb689a0c092f5534b929d302db2c8a9', 'alert'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testFetchPage() { |
23
|
|
|
$page = $this->fetch_page([]); |
24
|
|
|
$this->assertStringContainsString('TheyWorkForYou Email Alerts', $page); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testKeywordOnly() { |
28
|
|
|
$page = $this->fetch_page([ 'alertsearch' => 'elephant']); |
29
|
|
|
$this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page); |
30
|
|
|
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value="elephant"', $page); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testSpeakerId() { |
34
|
|
|
$page = $this->fetch_page([ 'alertsearch' => 'speaker:2']); |
35
|
|
|
$this->assertStringContainsString('Mrs Test Current-MP', $page); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testPostCodeOnly() { |
39
|
|
|
$page = $this->fetch_page([ 'alertsearch' => 'SE17 3HE']); |
40
|
|
|
$this->assertStringContainsString('Mrs Test Current-MP', $page); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testPostCodeWithKeyWord() { |
44
|
|
|
$page = $this->fetch_page([ 'alertsearch' => 'SE17 3HE elephant']); |
45
|
|
|
$this->assertStringContainsString('You have used a postcode and something else', $page); |
46
|
|
|
$this->assertStringContainsString('Mentions of [elephant] by your MP, Mrs Test Current-MP', $page); |
47
|
|
|
$this->assertStringNotContainsString('by your MSP', $page); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testScottishPostcodeWithKeyword() { |
51
|
|
|
$page = $this->fetch_page([ 'alertsearch' => 'PH6 2DB elephant']); |
52
|
|
|
$this->assertStringContainsString('You have used a postcode and something else', $page); |
53
|
|
|
$this->assertStringContainsString('Mentions of [elephant] by your MP, Mr Test2 Current-MP', $page); |
54
|
|
|
$this->assertStringContainsString('Mentions of [elephant] by your MSP, Mrs Test Current-MSP', $page); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testPostcodeAndKeywordWithNoSittingMP() { |
58
|
|
|
$page = $this->fetch_page([ 'alertsearch' => 'OX1 4LF elephant']); |
59
|
|
|
$this->assertStringContainsString('You have used a postcode and something else', $page); |
60
|
|
|
$this->assertStringNotContainsString('Did you mean to get alerts for when your MP', $page); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The tests below this are in the xapian group as they use the search engine and we need to be able to skip |
65
|
|
|
* these when running the tests as part of github actions as it has no access to the xapian |
66
|
|
|
* |
67
|
|
|
* @group xapian |
68
|
|
|
*/ |
69
|
|
|
public function testBasicKeyWordAlertsCreation() { |
70
|
|
|
$page = $this->fetch_page([ 'step' => 'define']); |
71
|
|
|
$this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page); |
72
|
|
|
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page); |
73
|
|
|
|
74
|
|
|
$page = $this->fetch_page([ 'step' => 'review', 'email' => '[email protected]', 'words[]' => 'fish']); |
75
|
|
|
$this->assertStringContainsString('Review Your Alert', $page); |
76
|
|
|
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page); |
77
|
|
|
|
78
|
|
|
$page = $this->fetch_page([ 'step' => 'confirm', 'email' => '[email protected]', 'words[]' => 'fish']); |
79
|
|
|
$this->assertStringContainsString('We’re nearly done', $page); |
80
|
|
|
$this->assertStringContainsString('You should receive an email shortly', $page); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @group xapian |
85
|
|
|
*/ |
86
|
|
|
public function testMultipleKeyWordAlertsCreation() { |
87
|
|
|
$page = $this->fetch_page([ 'step' => 'define']); |
88
|
|
|
$this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page); |
89
|
|
|
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page); |
90
|
|
|
|
91
|
|
|
$page = $this->fetch_page([ 'step' => 'review', 'email' => '[email protected]', 'words[]' => ['fish', 'salmon']]); |
92
|
|
|
$this->assertStringContainsString('Review Your Alert', $page); |
93
|
|
|
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page); |
94
|
|
|
$this->assertStringContainsString('<input type="hidden" name="words[]" value="salmon"', $page); |
95
|
|
|
|
96
|
|
|
$page = $this->fetch_page([ 'step' => 'confirm', 'email' => '[email protected]', 'words[]' => ['fish', 'salmon']]); |
97
|
|
|
$this->assertStringContainsString('You should receive an email shortly', $page); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @group xapian |
102
|
|
|
*/ |
103
|
|
|
public function testMultipleKeyWordAlertsCreationLoggedIn() { |
104
|
|
|
$page = $this->get_page(['step' => 'define']); |
105
|
|
|
$this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page); |
106
|
|
|
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page); |
107
|
|
|
|
108
|
|
|
$page = $this->get_page([ 'step' => 'review', 'words[]' => ['fish', 'salmon']]); |
109
|
|
|
$this->assertStringContainsString('Review Your Alert', $page); |
110
|
|
|
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page); |
111
|
|
|
$this->assertStringContainsString('<input type="hidden" name="words[]" value="salmon"', $page); |
112
|
|
|
|
113
|
|
|
$page = $this->get_page([ 'step' => 'confirm', 'words[]' => ['fish', 'salmon']]); |
114
|
|
|
$this->assertStringContainsString('You will now receive email alerts on any day when [fish salmon] is mentioned in parliament', $page); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @group xapian |
119
|
|
|
*/ |
120
|
|
|
public function testKeyWordAndSectionAlertsCreationLoggedIn() { |
121
|
|
|
$page = $this->get_page(['step' => 'define']); |
122
|
|
|
$this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page); |
123
|
|
|
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page); |
124
|
|
|
|
125
|
|
|
$page = $this->get_page(['step' => 'review', 'words[]' => 'fish', 'search_section' => 'debates']); |
126
|
|
|
$this->assertStringContainsString('Review Your Alert', $page); |
127
|
|
|
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page); |
128
|
|
|
|
129
|
|
|
$page = $this->get_page(['step' => 'confirm', 'words[]' => 'fish', 'search_section' => 'debates']); |
130
|
|
|
$this->assertStringContainsString('You will now receive email alerts on any day when [fish] is mentioned in House of Commons debates', $page); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @group xapian |
135
|
|
|
*/ |
136
|
|
|
public function testKeyWordAndSpeakerAlertsCreationLoggedIn() { |
137
|
|
|
$page = $this->get_page(['step' => 'define']); |
138
|
|
|
$this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page); |
139
|
|
|
$this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page); |
140
|
|
|
|
141
|
|
|
$page = $this->get_page(['step' => 'review', 'words[]' => 'fish', 'representative' => 'Mrs Test Current-MP']); |
142
|
|
|
$this->assertStringContainsString('Review Your Alert', $page); |
143
|
|
|
$this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page); |
144
|
|
|
$this->assertStringContainsString('<input type="hidden" name="representative" value="Mrs Test Current-MP"', $page); |
145
|
|
|
|
146
|
|
|
$page = $this->get_page([ 'step' => 'confirm', 'words[]' => 'fish', 'representative' => 'Mrs Test Current-MP']); |
147
|
|
|
$this->assertStringContainsString('You will now receive email alerts on any day when Mrs Test Current-MP mentions [fish] in parliament', $page); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.