Issues (404)

tests/SectionTest.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * Provides test methods to ensure pages contain what we want them to in various ways.
5
 */
6
class SectionTest extends FetchPageTestCase {
7
    public function getDataSet() {
8
        return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/section.xml');
0 ignored issues
show
Are you sure the usage of $this->createMySQLXMLDat..._fixtures/section.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...
9
    }
10
11
    private function fetch_page($vars) {
12
        return $this->base_fetch_page($vars, '', 'section.php');
13
    }
14
15
    public $types = ['debates', 'whall', 'wrans', 'wms', 'ni', 'sp', 'spwrans', 'lords'];
16
17
    public function testDebatesFront() {
18
        foreach ($this->types as $type) {
19
            $page = $this->fetch_page([ 'type' => $type ]);
20
            $this->assertStringContainsString($type, $page);
21
        }
22
    }
23
24
    public function testDebatesYear() {
25
        foreach ($this->types as $type) {
26
            $page = $this->fetch_page([ 'type' => $type, 'y' => '2014' ]);
27
            $this->assertStringContainsString('<div class="calendar">', $page);
28
            $this->assertStringContainsString('January', $page);
29
            $this->assertMatchesRegularExpression('/<td colspan="2">&nbsp;<\/td><td[^>]*><a href="\/' . $type . '\/\?d=2014-01-01">1<\/a><\/td><td[^>]*><span>2<\/span><\/td>/', $page);
30
        }
31
    }
32
33
    public function testDebatesDay() {
34
        foreach ($this->types as $type) {
35
            $page = $this->fetch_page([ 'type' => $type, 'd' => '2014-01-01' ]);
36
            $this->assertStringContainsString('Wednesday,  1 January 2014', $page);
37
            $this->assertStringContainsString('HeadingA', $page);
38
            if ($type == 'wrans') {
39
                $this->assertStringContainsString('DepartmentA', $page);
40
                $this->assertStringContainsString('QuestionA', $page);
41
            } elseif ($type == 'spwrans') {
42
                $this->assertStringContainsString('QuestionA', $page);
43
            } elseif ($type == 'wms') {
44
                $this->assertStringContainsString('DepartmentA', $page);
45
                $this->assertStringContainsString('StatementA', $page);
46
            } else {
47
                $this->assertStringContainsString('SubheadingA', $page);
48
                $this->assertStringContainsString('SpeechA', $page);
49
            }
50
        }
51
    }
52
53
    public function testDebatesHeading() {
54
        foreach ($this->types as $type) {
55
            if ($type == 'spwrans') {
56
                # Only one level of headings on spwrans
57
                continue;
58
            }
59
60
            $page = $this->fetch_page([ 'type' => $type, 'id' => '2014-01-01b.1.1' ]);
61
            if ($type == 'wrans') {
62
                $this->assertMatchesRegularExpression("#All .*?written answers on  1 Jan 2014#i", $page);
63
                $this->assertStringContainsString("QuestionA", $page);
64
            } else {
65
                $this->assertMatchesRegularExpression("#Location: .*?/$type/\?id=2014-01-01b\.1\.2#", $page);
66
            }
67
        }
68
    }
69
70
    public function testDebatesSubheading() {
71
        foreach ($this->types as $type) {
72
            $page = $this->fetch_page([ 'type' => $type, 'id' => '2014-01-01b.1.2' ]);
73
            $this->assertStringContainsString("HeadingA", $page);
74
            if ($type == 'spwrans') {
75
                $this->assertStringContainsString("QuestionA", $page);
76
                $this->assertStringContainsString("AnswerA", $page);
77
            } elseif ($type == 'wrans') {
78
                $this->assertStringContainsString("DepartmentA", $page);
79
                $this->assertStringContainsString("QuestionA", $page);
80
                $this->assertStringContainsString("AnswerA", $page);
81
                $this->assertStringContainsString('Mp Mp', $page);
82
                $this->assertStringContainsString('Highlands and Islands', $page);
83
                $this->assertStringContainsString('Mp2 Mp2', $page);
84
                $this->assertStringContainsString('Birmingham', $page);
85
                $this->assertStringContainsString('Independent', $page);
86
            } elseif ($type == 'wms') {
87
                $this->assertStringContainsString('DepartmentA', $page);
88
                $this->assertStringContainsString('StatementA', $page);
89
            } else {
90
                $this->assertStringContainsString("SubheadingA", $page);
91
                $this->assertStringContainsString("SpeechA", $page);
92
            }
93
            $time = strftime('2:30 %p', mktime(14, 30));
94
            $this->assertStringContainsString($time, $page);
95
            $this->assertMatchesRegularExpression('#All.*?on  1 Jan 2014#', $page);
96
            $this->assertStringContainsString("Mp Mp", $page);
97
        }
98
    }
99
100
    public function testDebatesSpeech() {
101
        foreach ($this->types as $type) {
102
            $page = $this->fetch_page([ 'type' => $type, 'id' => '2014-01-01b.1.3' ]);
103
            if ($type == 'wrans' || $type == 'spwrans' || $type == 'wms') {
104
                $this->assertMatchesRegularExpression("#Location: .*?/$type/\?id=2014-01-01b\.1\.2#", $page);
105
            } else {
106
                $this->assertStringContainsString("HeadingA", $page);
107
                $this->assertStringContainsString("SubheadingA", $page);
108
                $time = strftime('2:30 %p', mktime(14, 30));
109
                $this->assertStringContainsString($time, $page);
110
                $this->assertStringContainsString('See the whole debate', $page);
111
                $this->assertStringContainsString('See this speech in context', $page);
112
                $this->assertStringContainsString("Mp Mp", $page);
113
                $this->assertStringContainsString("SpeechA", $page);
114
            }
115
        }
116
    }
117
118
    /**
119
     * Test that applying search highlighting and glossary linking to the same
120
     * term doesn't break the layout
121
     *
122
     * see issue 912 for details
123
     *
124
     * @group xapian
125
     */
126
    public function testGlossaryAndSearchHighlights() {
127
        $page = $this->fetch_page([ 'type' => 'lords', 's' => 'constituency', 'id' => '2014-02-02b.1.3' ]);
128
        $this->assertStringContainsString("constituency", $page);
129
        $this->assertStringContainsString("<span class=\"hi\"><a href=\"/glossary/?gl=1\" title=\"In a general election, each Constituency chooses an MP to represent them....\" class=\"glossary\">constituency</a></span>", $page);
130
    }
131
132
    public function testGidRedirect() {
133
        $page = $this->fetch_page([ 'type' => 'wrans', 'id' => '2014-01-01a.187335.h' ]);
134
        $this->assertMatchesRegularExpression("#Location: .*?/wrans/\?id=2014-01-01b\.1\.2#", $page);
135
    }
136
}
137