Failed Conditions
Pull Request — master (#1846)
by Struan
54:09 queued 22:02
created

AlertsPageTest::testSpeakerId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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');
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->createMySQLXMLDat...xtures/alertspage.xml') targeting TWFY_Database_TestCase::createMySQLXMLDataSet() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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 recieve 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
    public function testBasicKeyWordAlertsCreation() {
64
        $page = $this->fetch_page([ 'step' => 'define']);
65
        $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
66
        $this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page);
67
68
        $page = $this->fetch_page([ 'step' => 'review', 'email' => '[email protected]', 'words[]' => 'fish']);
69
        $this->assertStringContainsString('Review Your Alert', $page);
70
        $this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
71
72
        $page = $this->fetch_page([ 'step' => 'confirm', 'email' => '[email protected]', 'words[]' => 'fish']);
73
        $this->assertStringContainsString('We’re nearly done', $page);
74
        $this->assertStringContainsString('You should receive an email shortly', $page);
75
    }
76
77
    public function testMultipleKeyWordAlertsCreation() {
78
        $page = $this->fetch_page([ 'step' => 'define']);
79
        $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
80
        $this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page);
81
82
        $page = $this->fetch_page([ 'step' => 'review', 'email' => '[email protected]', 'words[]' => ['fish', 'salmon']]);
83
        $this->assertStringContainsString('Review Your Alert', $page);
84
        $this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
85
        $this->assertStringContainsString('<input type="hidden" name="words[]" value="salmon"', $page);
86
87
        $page = $this->fetch_page([ 'step' => 'confirm', 'email' => '[email protected]', 'words[]' => ['fish', 'salmon']]);
88
        $this->assertStringContainsString('You should receive an email shortly', $page);
89
    }
90
91
    public function testMultipleKeyWordAlertsCreationLoggedIn() {
92
        $page = $this->get_page(['step' => 'define']);
93
        $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
94
        $this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page);
95
96
        $page = $this->get_page([ 'step' => 'review', 'words[]' => ['fish', 'salmon']]);
97
        $this->assertStringContainsString('Review Your Alert', $page);
98
        $this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
99
        $this->assertStringContainsString('<input type="hidden" name="words[]" value="salmon"', $page);
100
101
        $page = $this->get_page([ 'step' => 'confirm', 'words[]' => ['fish', 'salmon']]);
102
        $this->assertStringContainsString('You will now receive email alerts on any day when [fish salmon] is mentioned in parliament', $page);
103
    }
104
105
    public function testKeyWordAndSectionAlertsCreationLoggedIn() {
106
        $page = $this->get_page(['step' => 'define']);
107
        $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
108
        $this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page);
109
110
        $page = $this->get_page(['step' => 'review', 'words[]' => 'fish', 'search_section' => 'debates']);
111
        $this->assertStringContainsString('Review Your Alert', $page);
112
        $this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
113
114
        $page = $this->get_page(['step' => 'confirm', 'words[]' => 'fish', 'search_section' => 'debates']);
115
        $this->assertStringContainsString('You will now receive email alerts on any day when [fish] is mentioned in House of Commons debates', $page);
116
    }
117
118
    public function testKeyWordAndSpeakerAlertsCreationLoggedIn() {
119
        $page = $this->get_page(['step' => 'define']);
120
        $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
121
        $this->assertStringContainsString('<input type="text" id="words0" name="words[]" aria-required="true" value=""', $page);
122
123
        $page = $this->get_page(['step' => 'review', 'words[]' => 'fish', 'representative' => 'Mrs Test Current-MP']);
124
        $this->assertStringContainsString('Review Your Alert', $page);
125
        $this->assertStringContainsString('<input type="hidden" name="words[]" value="fish"', $page);
126
        $this->assertStringContainsString('<input type="hidden" name="representative" value="Mrs Test Current-MP"', $page);
127
128
        $page = $this->get_page([ 'step' => 'confirm', 'words[]' => 'fish', 'representative' => 'Mrs Test Current-MP']);
129
        $this->assertStringContainsString('You will now receive email alerts on any day when Mrs Test Current-MP mentions [fish] in parliament', $page);
130
    }
131
}
132