| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Test Party class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | class PartyTest extends FetchPageTestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |      * Loads the member testing fixture. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     public function getDataSet() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/cohorts.xml'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     private function fetch_page($vars) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         return $this->base_fetch_page($vars, 'mp'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     public function testLoad() { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         // Party class name function is working | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         $party = new MySociety\TheyWorkForYou\Party('A Party'); | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $this->assertNotNull($party); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         $this->assertEquals('A Party', $party->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public function testTwoLabourPartiesAreOneParty() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         //A labour and labour/coop mp end up in the same cohort. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         //Person ID 5 and 6 have the same cohort. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $member = $this->getMemberFromPersonId(5); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $cohortkeya = $member->cohortParty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $member = $this->getMemberFromPersonId(6); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $cohortkeyb = $member->cohortParty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->assertEquals($cohortkeya, $cohortkeyb); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public function testPartyChangerComparison() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         //An MP who changes party should have their first party as their comparison party. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         // Person id 7, has changed party but should have 'A Party' not 'C Party' as their comparison party. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $member = $this->getMemberFromPersonId(7); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $comparison_party = $member->cohortParty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->assertEquals($comparison_party, "a-party"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     public function testManualPartyChangerComparison() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         // Person 10172 has changed party but has a manual override so should use their last party | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $member = $this->getMemberFromPersonId(10172); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $comparison_party = $member->cohortParty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->assertEquals($comparison_party, "i-party"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function testSpeakerPartyChangerComparison() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         // Person 25 is the speaker, and so doesn't get their former party comparison. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $member = $this->getMemberFromPersonId(25); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $comparison_party = $member->cohortParty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->assertEquals($comparison_party, "speaker"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     public function testLabourCoOp() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         // Test Labour/Coop party name is correctly aliased to Labour | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $party = new MySociety\TheyWorkForYou\Party('Labour/Co-operative'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->assertEquals('Labour', $party->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     public function testCountMembers() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         // Test the test data contains the correct number of people in party A | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $party = new MySociety\TheyWorkForYou\Party('A Party'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->assertEquals($party->getCurrentMemberCount(HOUSE_TYPE_COMMONS), 4); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     public function testCalculatePositionsPolicyAgree() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         # The labour/coop party's position on policy 996 was that they | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         # were agree (0 distance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         # Person 6 is a coop MP - we want to test they correctly get compared to labour | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $person_id = 6; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $voting_comparison_period_slug = "all_time"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $member = $this->getMemberFromPersonId($person_id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $sets = ['reform']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $collections = MySociety\TheyWorkForYou\PolicyDistributionCollection::getPersonDistributions($sets, $member->person_id(), $member->cohortParty(), $voting_comparison_period_slug, HOUSE_TYPE_COMMONS); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $reform = $collections[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $pair = $reform->getPairfromPolicyID(996); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $comparison_score = $pair->comparison_distribution->distance_score; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $this->assertEquals(0, $comparison_score); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     public function testGetAllParties() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $parties = MySociety\TheyWorkForYou\Party::getParties(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $expected = ['A Party', 'B Party', 'C Party', 'D Party', 'E Party', 'F Party', 'G Party', 'Labour', 'Labour/Co-operative']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $this->assertCount(0, array_diff($expected, $parties)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     private function getMemberFromPersonId($person_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         return new MySociety\TheyWorkForYou\Member([ "person_id" => $person_id ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     public function testMPPartyPolicyTextWhenDiffersVotes() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         // Checks that an MP that differs from party gets the 'sometimes differs from their party' on the profile page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         // for this one we need some mock data on how person 15 sometimes differs from their party | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $page = $this->fetch_page(['pagetype' => 'votes', 'pid' => 15, 'url' => '/mp/15/test_mp_g_party_1/test_westminster_constituency/votes']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $this->assertStringContainsString('is a G Party MP', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $this->assertStringContainsString('Test MP G Party 1', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $this->assertStringContainsString('sometimes <b>differs</b> from their party', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     public function testSingleMemberPartyPolicyText() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         // this test checks it doesn't say they are an X party MP when they are the only MP of that party | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $page = $this->fetch_page(['pid' => 7, 'url' => '/mp/7/test_mp_g/test_westminster_constituency']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $this->assertStringContainsString('Test MP G', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $this->assertStringNotContainsString('is a B Party MP', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     public function testMPPartyPolicyWherePartyMissingPositions() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         // When an MP has votes, but there is no broader party policy to compare it to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         // this goes down a funnel that shows the votes, but does not make the comparison to party. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         // this is a single person party i think - so no party comparison? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         // need to check what votes would actually produce | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $page = $this->fetch_page(['pid' => 4, 'pagetype' => 'votes','url' => '/mp/4/test_mp_d/test_westminster_constituency/votes']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $this->assertStringContainsString('Test MP D', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $this->assertStringContainsString('<li class="vote-description"', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         $this->assertStringNotContainsString('comparable B Party MPs voted', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     public function testMPPartyPolicyTextWhenAgrees() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         // Test when an MP mostly agrees with their party, as MP G Party 2 does with party G | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         // this is just a boring, person aligned with party example | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $page = $this->fetch_page(['pagetype' => 'votes', 'pid' => 16,  'url' => '/mp/16/test_mp_g_party_2/test_westminster_constituency/votes']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $this->assertStringContainsString('Test MP G Party 2', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         $this->assertStringNotContainsString('sometimes <b>differs</b> from their party colleagues', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     public function testCrossPartyDisclaimer() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         // Test if the cross party disclaimer is there | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         // this should still work fine | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $page = $this->fetch_page(['pagetype' => 'votes', 'pid' => 7, 'url' => '/mp/7/test_mp_g/test_westminster_constituency/votes']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $this->assertStringContainsString('Test MP G', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         $this->assertStringContainsString('In the votes below they are compared to their original party', $page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 166 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 167 |  |  |  | 
            
                        
This check looks for function or method calls that always return null and whose return value is used.
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.