diff --git a/tests/PostcodePageTest.php b/tests/PostcodePageTest.php new file mode 100644 index 0000000000..f1a4a3e6cf --- /dev/null +++ b/tests/PostcodePageTest.php @@ -0,0 +1,76 @@ +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); + } +} diff --git a/tests/_fixtures/postcodepage.xml b/tests/_fixtures/postcodepage.xml new file mode 100644 index 0000000000..f7c582eba0 --- /dev/null +++ b/tests/_fixtures/postcodepage.xml @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + 1 + Test Bill + http://example.com + unknown + 0 + 2013-14 + test_ + + + + + + + + + + + + + Test Westminster Constituency + test_constituency_key + Test Constituency Value + + + + + Test Scottish Westminster Constituency + 1 + 1983-00-00 + 9999-12-31 + 11 + + + Test NI Westminster Constituency + 1 + 1983-00-00 + 9999-12-31 + 12 + + + + + + + + + + + + + + + + + + + + + 1 + 1 + Test Westminster Constituency + + 2007-05-06 + 9999-12-31 + general_election + still_in_office + 2 + 2013-08-07 11:02:49 + + + 2 + 1 + Test Scottish Westminster Constituency + + 2007-05-06 + 9999-12-31 + general_election + still_in_office + 3 + 2013-08-07 11:02:49 + + + 3 + 4 + Test Holyrood Constituency + + 2007-05-06 + 9999-12-31 + general_election + still_in_office + 4 + 2013-08-07 11:02:49 + + + 4 + 4 + Test Scottish Region + + 2007-05-06 + 9999-12-31 + general_election + still_in_office + 5 + 2013-08-07 11:02:49 + + + 1 + 5 + Test NI Westminster Constituency + + 2007-05-06 + 9999-12-31 + general_election + still_in_office + 6 + 2013-08-07 11:02:49 + + + 6 + 3 + Test Stormont Constituency + + 2007-05-06 + 9999-12-31 + general_election + still_in_office + 7 + 2013-08-07 11:02:49 + + + + + Test + Current-MP + 2000-01-01 + 9999-12-31 + 2 + Mrs + + + Test2 + Current-MP + 2000-01-01 + 9999-12-31 + 3 + Mr + + + Test + Current-MSP + 2000-01-01 + 9999-12-31 + 4 + Mrs + + + Test + Current-Regional-MSP + 2000-01-01 + 9999-12-31 + 5 + Dr + + + Test3 + Current-MP + 2000-01-01 + 9999-12-31 + 6 + Miss + + + Test + Current-MLA + 2000-01-01 + 9999-12-31 + 7 + Mr + + + + + + + + + + + + + + + PH6 2DB + Test Scottish Westminster Constituency|Test Holyrood Constituency|Test Scottish Region + + + BT1 1AA + Test NI Westminster Constituency|Test Stormont Constituency + + + SW1A 1AA + Test Westminster Constituency + + + OX1 4LF + Another Westminster Constituency + + + + + + + + + + + + + + + + + + + + + +