Issues (404)

tests/HansardTest.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * Provides test methods for Hansard functionality.
5
 */
6
class HansardTest extends TWFY_Database_TestCase {
7
    /**
8
     * Loads the Hansard testing fixture.
9
     */
10
    public function getDataSet() {
11
        return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/hansard.xml');
0 ignored issues
show
Are you sure the usage of $this->createMySQLXMLDat..._fixtures/hansard.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
    /**
15
     * Ensures the database is prepared and the alert class is included for every test.
16
     */
17
    public function setUp(): void {
18
        parent::setUp();
19
20
        include_once('www/includes/easyparliament/hansardlist.php');
21
    }
22
23
    /**
24
     * Test getting the most recent day
25
     */
26
    public function testMostRecentDay() {
27
        $HANSARD = new HANSARDLIST();
28
        $HANSARD->major = 1;
29
        $HANSARD->listpage = 'test';
30
31
        $response = $HANSARD->most_recent_day();
32
33
        // Make sure the date is as expected
34
        $this->assertEquals('2014-01-02', $response['hdate']);
35
    }
36
37
    /**
38
     * Test that getting data by person works
39
     */
40
    public function testGetDataByPerson() {
41
        $HANSARD = new HANSARDLIST();
42
43
        $args = [
44
            'person_id' => '2',
45
        ];
46
47
        $response = $HANSARD->_get_data_by_person($args);
48
49
        // Ensure we have four rows
50
        $this->assertEquals(4, count($response['rows']));
51
52
        // Make sure all four rows are the expected ones, in the expected order
53
        $this->assertEquals(7, $response['rows'][0]['gid']);
54
        $this->assertEquals(6, $response['rows'][1]['gid']);
55
        $this->assertEquals(5, $response['rows'][2]['gid']);
56
        $this->assertEquals(3, $response['rows'][3]['gid']);
57
    }
58
59
    /**
60
     * Test that getting data by date works
61
     */
62
    public function testGetDataByDate() {
63
        $HANSARD = new HANSARDLIST();
64
65
        $HANSARD->major = 1;
66
        $HANSARD->listpage = 'test';
67
68
        $args = [
69
            'date' => '2014-01-01',
70
        ];
71
72
        $response = $HANSARD->_get_data_by_date($args);
73
74
        // Ensure we have four rows
75
        $this->assertEquals(4, count($response['rows']));
76
77
        // Make sure all five rows are the expected ones, in the expected order
78
        $this->assertEquals(3, $response['rows'][0]['gid']);
79
        $this->assertEquals(5, $response['rows'][1]['gid']);
80
        $this->assertEquals(6, $response['rows'][2]['gid']);
81
        $this->assertEquals(7, $response['rows'][3]['gid']);
82
    }
83
84
    /**
85
     * Test that getting data by GID works as expected.
86
     *
87
     * This test inadvertently runs about a billion other bits of code.
88
     */
89
    public function testGetDataByGid() {
90
        $HANSARD = new HANSARDLIST();
91
92
        $HANSARD->major = 1;
93
        $HANSARD->gidprefix = 'com.theyworkforyou/test/hansard/';
94
        $HANSARD->listpage = 'test';
95
96
        $args = [
97
            'gid' => '3',
98
        ];
99
100
        $response = $HANSARD->_get_data_by_gid($args);
101
102
        // Ensure we have one row
103
        $this->assertEquals(1, count($response['rows']));
104
105
        // Make sure the row is the expected one
106
        $this->assertEquals(3, $response['rows'][0]['gid']);
107
    }
108
109
    /**
110
     * Test that getting an item works as expected.
111
     */
112
    public function testGetItem() {
113
        $HANSARD = new HANSARDLIST();
114
115
        $HANSARD->major = 1;
116
        $HANSARD->gidprefix = 'com.theyworkforyou/test/hansard/';
117
118
        $args = [
119
            'gid' => '3',
120
        ];
121
122
        $response = $HANSARD->_get_item($args);
123
124
        // Ensure the response is the expected object
125
        $this->assertEquals(3, $response['gid']);
126
    }
127
128
    /**
129
     * Test that getting a speaker works.
130
     */
131
    public function testGetSpeaker() {
132
        $HANSARD = new HANSARDLIST();
133
134
        $response = $HANSARD->_get_speaker(3, '2014-01-01', '00:00:00', 1);
135
136
        // Ensure the response is the expected object
137
        $this->assertEquals(3, $response['person_id']);
138
    }
139
140
}
141