Failed Conditions
Pull Request — master (#1851)
by Struan
30:43
created

testKeyWordAndSpeakerAlertsCreationLoggedIn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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