Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow redirect to policy page from postcode page #1254

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions classes/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ public function offices($include_only = NULL, $ignore_committees = FALSE) {

}


public function getPolicyURL($args = array()) {
$base_url = $this->url();
if (isset($args['policy_number'])) {
$url = $base_url . '/divisions?policy=' . $args['policy_number'];
} else if (isset($args['policy_set'])) {
$url = $base_url . '/votes?policy=' . $args['policy_set'];
} else {
$url = $base_url . '/votes';
}

return $url;
}

private function getOfficeObject($include_only, $ignore_committees, $row) {
if (!$this->includeOffice($include_only, $row['to_date'])) {
return null;
Expand Down
76 changes: 76 additions & 0 deletions tests/PostcodePageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Testing for postcode Utility functions
*/

class PostcodePageTest extends FetchPageTestCase
{

/**
* Loads the member testing fixture.
*/
public function getDataSet()
{
return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/postcodepage.xml');
}

private function fetch_postcode_page($postcode, $options = array()) {
$args = array('pc' => $postcode);
$args = array_merge($args, $options);

return $this->base_fetch_page(
$args,
'postcode',
'index.php',
'/postcode/'
);
}

public function testNoPostcodeGivesError()
{
$page = $this->fetch_postcode_page('');
$this->assertContains('Please supply a postcode!', $page);
}

public function testRedirectsForWestminsterOnly()
{
$page = $this->fetch_postcode_page('SW1A 1AA');
$this->assertContains('Location: /mp/2/test_current-mp/test_westminster_constituency', $page);
}

public function testShowsOptionsForScottishPostcode()
{
$page = $this->fetch_postcode_page('PH6 2DB');
$this->assertContains('That postcode has multiple results', $page);
$this->assertContains('Test2 Current-MP', $page);
$this->assertContains('Test Current-MSP', $page);
$this->assertContains('Test Current-Regional-MSP', $page);
}

public function testShowsOptionsForNIPostcode()
{
$page = $this->fetch_postcode_page('BT1 1AA');
$this->assertContains('That postcode has multiple results', $page);
$this->assertContains('Test3 Current-MP', $page);
$this->assertContains('Test Current-MLA', $page);
}

public function testRedirectsWithPolicySet()
{
$page = $this->fetch_postcode_page('SW1A 1AA', array('policy_set' => 'social'));
$this->assertContains('Location: /mp/2/test_current-mp/test_westminster_constituency/votes?policy=social', $page);
}

public function testRedirectsWithPolicySetForScottishPostcode()
{
$page = $this->fetch_postcode_page('PH6 2DB', array('policy_set' => 'social'));
$this->assertContains('Location: /mp/3/test2_current-mp/test_scottish_westminster_constituency/votes?policy=social', $page);
}

public function testRedirectsWithPolicySetForNIPostcode()
{
$page = $this->fetch_postcode_page('BT1 1AA', array('policy_set' => 'social'));
$this->assertContains('Location: /mp/6/test3_current-mp/test_ni_westminster_constituency/votes?policy=social', $page);
}
}
8 changes: 8 additions & 0 deletions tests/_fixtures/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@
<table_data name="personinfo">
</table_data>
<table_data name="postcode_lookup">
<row>
<field name="postcode">SW1A 1AA</field>
<field name="name">Cities of London and Westminster</field>
</row>
<row>
<field name="postcode">BT17 0XD</field>
<field name="name">Belfast West|Belfast West</field>
</row>
</table_data>
<table_data name="search_query_log">
</table_data>
Expand Down
4 changes: 4 additions & 0 deletions tests/_fixtures/postcode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<table_data name="personinfo">
</table_data>
<table_data name="postcode_lookup">
<row>
<field name="postcode">SW1A 1AA</field>
<field name="name">Cities of London and Westminster</field>
</row>
</table_data>
<table_data name="search_query_log">
</table_data>
Expand Down
241 changes: 241 additions & 0 deletions tests/_fixtures/postcodepage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="twfy_testing">
<table_data name="alerts">
</table_data>
<table_data name="anonvotes">
</table_data>
<table_data name="api_key">
</table_data>
<table_data name="api_stats">
</table_data>
<table_data name="bills">
<row>
<field name="id">1</field>
<field name="title">Test Bill</field>
<field name="url">http://example.com</field>
<field name="type">unknown</field>
<field name="lords">0</field>
<field name="session">2013-14</field>
<field name="standingprefix">test_</field>
</row>
</table_data>
<table_data name="campaigners">
</table_data>
<table_data name="campaigners_sent_email">
</table_data>
<table_data name="commentreports">
</table_data>
<table_data name="comments">
</table_data>
<table_data name="consinfo">
<row>
<field name="constituency">Test Westminster Constituency</field>
<field name="data_key">test_constituency_key</field>
<field name="data_value">Test Constituency Value</field>
</row>
</table_data>
<table_data name="constituency">
<row>
<field name="name">Test Scottish Westminster Constituency</field>
<field name="main_name">1</field>
<field name="from_date">1983-00-00</field>
<field name="to_date">9999-12-31</field>
<field name="cons_id">11</field>
</row>
<row>
<field name="name">Test NI Westminster Constituency</field>
<field name="main_name">1</field>
<field name="from_date">1983-00-00</field>
<field name="to_date">9999-12-31</field>
<field name="cons_id">12</field>
</row>
</table_data>
<table_data name="editqueue">
</table_data>
<table_data name="epobject">
</table_data>
<table_data name="future">
</table_data>
<table_data name="future_people">
</table_data>
<table_data name="gidredirect">
</table_data>
<table_data name="glossary">
</table_data>
<table_data name="hansard">
</table_data>
<table_data name="indexbatch">
</table_data>
<table_data name="member">
<row>
<field name="member_id">1</field>
<field name="house">1</field>
<field name="constituency">Test Westminster Constituency</field>
<field name="party"></field>
<field name="entered_house">2007-05-06</field>
<field name="left_house">9999-12-31</field>
<field name="entered_reason">general_election</field>
<field name="left_reason">still_in_office</field>
<field name="person_id">2</field>
<field name="lastupdate">2013-08-07 11:02:49</field>
</row>
<row>
<field name="member_id">2</field>
<field name="house">1</field>
<field name="constituency">Test Scottish Westminster Constituency</field>
<field name="party"></field>
<field name="entered_house">2007-05-06</field>
<field name="left_house">9999-12-31</field>
<field name="entered_reason">general_election</field>
<field name="left_reason">still_in_office</field>
<field name="person_id">3</field>
<field name="lastupdate">2013-08-07 11:02:49</field>
</row>
<row>
<field name="member_id">3</field>
<field name="house">4</field>
<field name="constituency">Test Holyrood Constituency</field>
<field name="party"></field>
<field name="entered_house">2007-05-06</field>
<field name="left_house">9999-12-31</field>
<field name="entered_reason">general_election</field>
<field name="left_reason">still_in_office</field>
<field name="person_id">4</field>
<field name="lastupdate">2013-08-07 11:02:49</field>
</row>
<row>
<field name="member_id">4</field>
<field name="house">4</field>
<field name="constituency">Test Scottish Region</field>
<field name="party"></field>
<field name="entered_house">2007-05-06</field>
<field name="left_house">9999-12-31</field>
<field name="entered_reason">general_election</field>
<field name="left_reason">still_in_office</field>
<field name="person_id">5</field>
<field name="lastupdate">2013-08-07 11:02:49</field>
</row>
<row>
<field name="house">1</field>
<field name="member_id">5</field>
<field name="constituency">Test NI Westminster Constituency</field>
<field name="party"></field>
<field name="entered_house">2007-05-06</field>
<field name="left_house">9999-12-31</field>
<field name="entered_reason">general_election</field>
<field name="left_reason">still_in_office</field>
<field name="person_id">6</field>
<field name="lastupdate">2013-08-07 11:02:49</field>
</row>
<row>
<field name="member_id">6</field>
<field name="house">3</field>
<field name="constituency">Test Stormont Constituency</field>
<field name="party"></field>
<field name="entered_house">2007-05-06</field>
<field name="left_house">9999-12-31</field>
<field name="entered_reason">general_election</field>
<field name="left_reason">still_in_office</field>
<field name="person_id">7</field>
<field name="lastupdate">2013-08-07 11:02:49</field>
</row>
</table_data>
<table_data name="person_names">
<row>
<field name="given_name">Test</field>
<field name="family_name">Current-MP</field>
<field name="start_date">2000-01-01</field>
<field name="end_date">9999-12-31</field>
<field name="person_id">2</field>
<field name="title">Mrs</field>
</row>
<row>
<field name="given_name">Test2</field>
<field name="family_name">Current-MP</field>
<field name="start_date">2000-01-01</field>
<field name="end_date">9999-12-31</field>
<field name="person_id">3</field>
<field name="title">Mr</field>
</row>
<row>
<field name="given_name">Test</field>
<field name="family_name">Current-MSP</field>
<field name="start_date">2000-01-01</field>
<field name="end_date">9999-12-31</field>
<field name="person_id">4</field>
<field name="title">Mrs</field>
</row>
<row>
<field name="given_name">Test</field>
<field name="family_name">Current-Regional-MSP</field>
<field name="start_date">2000-01-01</field>
<field name="end_date">9999-12-31</field>
<field name="person_id">5</field>
<field name="title">Dr</field>
</row>
<row>
<field name="given_name">Test3</field>
<field name="family_name">Current-MP</field>
<field name="start_date">2000-01-01</field>
<field name="end_date">9999-12-31</field>
<field name="person_id">6</field>
<field name="title">Miss</field>
</row>
<row>
<field name="given_name">Test</field>
<field name="family_name">Current-MLA</field>
<field name="start_date">2000-01-01</field>
<field name="end_date">9999-12-31</field>
<field name="person_id">7</field>
<field name="title">Mr</field>
</row>
</table_data>
<table_data name="memberinfo">
</table_data>
<table_data name="mentions">
</table_data>
<table_data name="moffice">
</table_data>
<table_data name="pbc_members">
</table_data>
<table_data name="personinfo">
</table_data>
<table_data name="postcode_lookup">
<row>
<field name="postcode">PH6 2DB</field>
<field name="name">Test Scottish Westminster Constituency|Test Holyrood Constituency|Test Scottish Region</field>
</row>
<row>
<field name="postcode">BT1 1AA</field>
<field name="name">Test NI Westminster Constituency|Test Stormont Constituency</field>
</row>
<row>
<field name="postcode">SW1A 1AA</field>
<field name="name">Test Westminster Constituency</field>
</row>
<row>
<field name="postcode">OX1 4LF</field>
<field name="name">Another Westminster Constituency</field>
</row>
</table_data>
<table_data name="search_query_log">
</table_data>
<table_data name="survey">
</table_data>
<table_data name="titles">
</table_data>
<table_data name="titles_ignored">
</table_data>
<table_data name="trackbacks">
</table_data>
<table_data name="users">
</table_data>
<table_data name="uservotes">
</table_data>
<table_data name="video_timestamps">
</table_data>
<table_data name="editorial">
</table_data>
</database>
</mysqldump>
1 change: 1 addition & 0 deletions www/docs/mp/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
$divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER, $positions, $policiesList);

if ( $policyID ) {
$data['policy'] = $policiesList->getPolicyDetails($policyID);
$data['policydivisions'] = $divisions->getMemberDivisionsForPolicy($policyID);
} else {
$data['policydivisions'] = $divisions->getAllMemberDivisionsByPolicy();
Expand Down
Loading