From ca9b31f2e35f7ba962569e8b705a89b6dd139de3 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Tue, 12 Apr 2011 10:56:41 +0100 Subject: Start to move index.cgi into catalyst --- t/app/controller/index.t | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 t/app/controller/index.t (limited to 't/app/controller/index.t') diff --git a/t/app/controller/index.t b/t/app/controller/index.t new file mode 100644 index 000000000..1d0bff33c --- /dev/null +++ b/t/app/controller/index.t @@ -0,0 +1,39 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +# check that the homepage loads +$mech->get_ok('/'); + +subtest "check that the form goes to /around" => sub { + $mech->get_ok('/'); + + # submit form + $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); + + # check that we are at /around + is $mech->res->uri->path, '/around', "Got to /around"; + is $mech->res->uri->query_form, { pc => 'SW1A 1AA' }, "query passed along"; +}; + +subtest "check that requests with pc, x,y or lat,lon go to /around" => sub { + foreach my $test ( + { pc => 'SW1A 1AA', }, + { x => 3281, y => 1113, }, + { lat => 51.50100, lon => -0.14158, }, + ) + { + my $uri = URI->new('http://localhost/'); + $uri->query_form($test); + $mech->get_ok($uri); + + # check that we are at /around + is $mech->res->uri->path, '/around', "Got to /around"; + is $mech->res->uri->query_form, $test, "query passed along"; + } +}; + +done_testing(); -- cgit v1.2.3 From a38d76783ee9a44b9e237a87d086549677d3282e Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Tue, 12 Apr 2011 12:32:58 +0100 Subject: Redirect locations queries from '/' to '/around' --- t/app/controller/index.t | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 't/app/controller/index.t') diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 1d0bff33c..91f01c943 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -15,8 +15,9 @@ subtest "check that the form goes to /around" => sub { $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); # check that we are at /around - is $mech->res->uri->path, '/around', "Got to /around"; - is $mech->res->uri->query_form, { pc => 'SW1A 1AA' }, "query passed along"; + is $mech->uri->path, '/around', "Got to /around"; + is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' }, + "query passed along"; }; subtest "check that requests with pc, x,y or lat,lon go to /around" => sub { @@ -31,8 +32,8 @@ subtest "check that requests with pc, x,y or lat,lon go to /around" => sub { $mech->get_ok($uri); # check that we are at /around - is $mech->res->uri->path, '/around', "Got to /around"; - is $mech->res->uri->query_form, $test, "query passed along"; + is $mech->uri->path, '/around', "Got to /around"; + is_deeply { $mech->uri->query_form }, $test, "query passed along"; } }; -- cgit v1.2.3 From 7f6e0a5fef9d072135cb08b710e9dc6d06d6cac7 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Tue, 12 Apr 2011 15:13:59 +0100 Subject: Create Around controller and implement the easy bits --- t/app/controller/index.t | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 't/app/controller/index.t') diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 91f01c943..11c59d289 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -21,10 +21,9 @@ subtest "check that the form goes to /around" => sub { }; subtest "check that requests with pc, x,y or lat,lon go to /around" => sub { - foreach my $test ( - { pc => 'SW1A 1AA', }, - { x => 3281, y => 1113, }, - { lat => 51.50100, lon => -0.14158, }, + foreach my $test ( # + { pc => 'SW1A 1AA' }, # + { lat => 51.50100, lon => -0.14158 }, ) { my $uri = URI->new('http://localhost/'); -- cgit v1.2.3 From 5bb7634143bd320b20601c3d92efc0b6987a0d8d Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 15 Apr 2011 11:25:42 +0100 Subject: Handle (e,n) requests to '/' --- t/app/controller/index.t | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 't/app/controller/index.t') diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 11c59d289..cebeaf676 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -10,6 +10,7 @@ $mech->get_ok('/'); subtest "check that the form goes to /around" => sub { $mech->get_ok('/'); + is $mech->uri->path, '/', "still on '/'"; # submit form $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); @@ -20,19 +21,37 @@ subtest "check that the form goes to /around" => sub { "query passed along"; }; -subtest "check that requests with pc, x,y or lat,lon go to /around" => sub { +subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub { + foreach my $test ( # - { pc => 'SW1A 1AA' }, # - { lat => 51.50100, lon => -0.14158 }, + { + in => { pc => 'SW1A 1AA' }, + out => { pc => 'SW1A 1AA' }, + }, + { + in => { lat => 51.50100, lon => -0.14158 }, + out => { lat => 51.50100, lon => -0.14158 }, + }, + { + in => { x => 3281, y => 1113, }, + out => { lat => 51.4998246332569, lon => -0.140137309739907 }, + }, + { + in => { e => 1234, n => 4567 }, + out => { lat => 49.808509, lon => -7.544784 }, + }, ) { + my $uri = URI->new('http://localhost/'); - $uri->query_form($test); + $uri->query_form( $test->{in} ); + + # get the uri and check for 302 $mech->get_ok($uri); # check that we are at /around is $mech->uri->path, '/around', "Got to /around"; - is_deeply { $mech->uri->query_form }, $test, "query passed along"; + is_deeply { $mech->uri->query_form }, $test->{out}, "query correct"; } }; -- cgit v1.2.3