Issues (404)

tests/PeopleTest.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * Provides test methods for people list functionality.
5
 */
6
class PeopleTest extends TWFY_Database_TestCase {
7
    /**
8
     * Loads the member testing fixture.
9
     */
10
    public function getDataSet() {
11
        return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/people.xml');
0 ignored issues
show
Are you sure the usage of $this->createMySQLXMLDat.../_fixtures/people.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
     * Test that a member is correctly retrieved by person ID alone.
16
     */
17
    public function testGetMPList() {
18
        $people = new MySociety\TheyWorkForYou\People\MPs();
19
20
        $expectedMP = [
21
            'person_id' => '2',
22
            'given_name' => 'Test',
23
            'family_name' => 'Current-MP',
24
            'lordofname' => '',
25
            'name' => 'Mrs Test Current-MP',
26
            'url' => '2/mrs_test_current-mp/test_westminster_constituency',
27
            'constituency' => 'Test Westminster Constituency',
28
            'party' => 'Lab',
29
            'left_reason' => 'still_in_office',
30
            'image' => '/images/unknownperson.png',
31
        ];
32
        $MPList = $people->getData();
33
34
        $this->assertEquals(9, count($MPList['data']));
35
        $this->assertEquals($expectedMP, $MPList['data'][2]);
36
    }
37
38
    public function testGetMSPList() {
39
        $people = new MySociety\TheyWorkForYou\People\MSPs();
40
41
        $expectedMSP = [
42
            'person_id' => '5',
43
            'given_name' => 'Test',
44
            'family_name' => 'Current-MSP',
45
            'lordofname' => '',
46
            'name' => 'Ms Test Current-MSP',
47
            'url' => '5/ms_test_current-msp',
48
            'constituency' => 'Test Scotland Constituency',
49
            'party' => 'Scottish National Party',
50
            'left_reason' => 'still_in_office',
51
            'image' => '/images/unknownperson.png',
52
        ];
53
        $MSPList = $people->getData();
54
55
        $this->assertEquals(4, count($MSPList['data']));
56
        $this->assertEquals($expectedMSP, $MSPList['data'][5]);
57
    }
58
59
    public function testGetMLAList() {
60
        $people = new MySociety\TheyWorkForYou\People\MLAs();
61
62
        $expectedMLA = [
63
            'person_id' => '4',
64
            'given_name' => 'Test',
65
            'family_name' => 'Current-MLA',
66
            'lordofname' => '',
67
            'name' => 'Miss Test Current-MLA',
68
            'url' => '4/miss_test_current-mla',
69
            'constituency' => 'Test Northern Ireland Constituency',
70
            'party' => 'Sinn Féin',
71
            'left_reason' => 'still_in_office',
72
            'image' => '/images/unknownperson.png',
73
        ];
74
        $MLAList = $people->getData();
75
76
        $this->assertEquals(4, count($MLAList['data']));
77
        $this->assertEquals($expectedMLA, $MLAList['data'][4]);
78
    }
79
80
    public function testGetPeerList() {
81
        $people = new MySociety\TheyWorkForYou\People\Peers();
82
83
        $expectedPeer = [
84
            'person_id' => '3',
85
            'given_name' => 'Test',
86
            'family_name' => 'Current-Lord',
87
            'lordofname' => '',
88
            'name' => 'Mr Current-Lord',
89
            'url' => '3/mr_current-lord',
90
            'constituency' => '',
91
            'party' => 'XB',
92
            'left_reason' => 'still_in_office',
93
            'image' => '/images/unknownlord.png',
94
        ];
95
        $PeerList = $people->getData();
96
97
        $this->assertEquals(2, count($PeerList['data']));
98
        $this->assertEquals($expectedPeer, $PeerList['data'][3]);
99
    }
100
101
    public function getOldMPList() {
102
        $people = new MySociety\TheyWorkForYou\People\MPs();
103
104
        $MPList = $people->getData(['date' => '1995-01-01']);
105
106
        $this->assertEquals(2, count($MPList['data']));
107
    }
108
109
    public function getAllMPList() {
110
        $people = new MySociety\TheyWorkForYou\People\MPs();
111
112
        $MPList = $people->getData(['all' => 1]);
113
114
        $this->assertEquals(11, count($MPList['data']));
115
    }
116
}
117