Skip to content

Commit

Permalink
tests for the postcode page
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Apr 13, 2017
1 parent d30a7a1 commit 63431d6
Show file tree
Hide file tree
Showing 2 changed files with 317 additions and 0 deletions.
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);
}
}
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>

0 comments on commit 63431d6

Please sign in to comment.