From 1498dfdec73becf769c3596bf41185f003c2a4cf Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Wed, 23 Feb 2011 13:58:27 +0000 Subject: Added About controller put 'loc' stub in place for i18n in templates server static files --- t/app/controller/about.t | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 t/app/controller/about.t (limited to 't/app/controller') diff --git a/t/app/controller/about.t b/t/app/controller/about.t new file mode 100644 index 000000000..2ac628367 --- /dev/null +++ b/t/app/controller/about.t @@ -0,0 +1,18 @@ +use strict; +use warnings; + +use Test::More; +use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; + +ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); + +# check that we can get the page +$mech->get_ok('/about'); +$mech->content_contains('FixMyStreet.com'); + +# check that geting the page as EHA produces a different page +ok $mech->host("www.reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; +$mech->get_ok('/about'); +$mech->content_lacks('FixMyStreet.com'); + +done_testing(); -- cgit v1.2.3 From 3ef36c3c9b5393c78c0af59b9f4e3f4528472357 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Wed, 23 Feb 2011 22:10:37 +0000 Subject: More work on the Cobrand and setting for request test to see welsh about us page --- t/app/controller/about.t | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/about.t b/t/app/controller/about.t index 2ac628367..adbce8f25 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -11,8 +11,14 @@ $mech->get_ok('/about'); $mech->content_contains('FixMyStreet.com'); # check that geting the page as EHA produces a different page -ok $mech->host("www.reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; +ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; $mech->get_ok('/about'); -$mech->content_lacks('FixMyStreet.com'); +$mech->content_contains('The Empty Homes Agency'); + +# check that geting the page as EHA in welsh produces a different page +ok $mech->host("cy.reportemptyhomes.co.uk"), + 'change host to cy.reportemptyhomes'; +$mech->get_ok('/about'); +$mech->content_contains('Yr Asiantaeth Tai Gwag'); done_testing(); -- cgit v1.2.3 From 9bd3b875d7a16f2a8842feb6913431ae789047bd Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Wed, 23 Feb 2011 22:27:57 +0000 Subject: Tidy t/app --- t/app/controller/page_not_found.t | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 t/app/controller/page_not_found.t (limited to 't/app/controller') diff --git a/t/app/controller/page_not_found.t b/t/app/controller/page_not_found.t new file mode 100644 index 000000000..9c8d7e5a6 --- /dev/null +++ b/t/app/controller/page_not_found.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 4; + +use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; + +my $mech = Test::WWW::Mechanize::Catalyst->new; + +# homepage ok +$mech->get_ok('/'); + +# get 404 page +my $path_to_404 = '/bad/path/page_not_found'; +my $res = $mech->get($path_to_404); +ok !$res->is_success(), "want a bad response"; +is $res->code, 404, "got 404"; +$mech->content_contains($path_to_404); -- cgit v1.2.3 From 7c9a89eedb17bdafbc171bba5de21cdd5725acd7 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 24 Feb 2011 15:27:23 +0000 Subject: Explicitly set gettext_dir so that it does not matter where calling script file is located --- t/app/controller/about.t | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/about.t b/t/app/controller/about.t index adbce8f25..aeca47d86 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -8,17 +8,19 @@ ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); # check that we can get the page $mech->get_ok('/about'); -$mech->content_contains('FixMyStreet.com'); +$mech->content_contains('About Us :: FixMyStreet.com'); +$mech->content_contains('html lang="en-gb"'); # check that geting the page as EHA produces a different page ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; $mech->get_ok('/about'); -$mech->content_contains('The Empty Homes Agency'); +$mech->content_contains('About us :: Report Empty Homes'); +$mech->content_contains('html lang="en-gb"'); # check that geting the page as EHA in welsh produces a different page -ok $mech->host("cy.reportemptyhomes.co.uk"), - 'change host to cy.reportemptyhomes'; +ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes'; $mech->get_ok('/about'); -$mech->content_contains('Yr Asiantaeth Tai Gwag'); +$mech->content_contains('Amdanom ni :: Adrodd am Eiddo Gwag'); +$mech->content_contains('html lang="cy"'); done_testing(); -- cgit v1.2.3 From 9c361f9b2bf1617fa97d3731a83a926db31e21c9 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 3 Mar 2011 15:29:56 +0000 Subject: Allow users to create an account, confirm it and logout --- t/app/controller/auth.t | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 t/app/controller/auth.t (limited to 't/app/controller') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t new file mode 100644 index 000000000..0a0280494 --- /dev/null +++ b/t/app/controller/auth.t @@ -0,0 +1,127 @@ +use strict; +use warnings; + +BEGIN { + use FixMyStreet; + FixMyStreet->test_mode(1); +} + +use Test::More tests => 44; +use Email::Send::Test; + +use FixMyStreet::App; + +use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; +my $mech = Test::WWW::Mechanize::Catalyst->new; + +my $test_email = 'test@example.com'; + +END { + ok( + FixMyStreet::App->model('DB::User')->find( { email => $test_email } ) + ->delete, + "delete test user" + ); +} + +$mech->get_ok('/auth'); + +# check that we can't reach a page that is only available to authenticated users +is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; + +# check that submitting form with no / bad email creates an error. +$mech->get_ok('/auth'); + +for my $test ( + [ '' => 'enter an email address' ], + [ 'not an email' => 'check your email address is correct' ], + [ 'bob@foo' => 'check your email address is correct' ], + [ 'bob@foonaoedudnueu.co.uk' => 'check your email address is correct' ], + ) +{ + my ( $email, $error_message ) = @$test; + pass "--- testing bad email '$email' gives error '$error_message'"; + $mech->get_ok('/auth'); + $mech->content_lacks($error_message); + $mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { email => $email, }, + button => 'create_account', + }, + "try to create an account with email '$email'" + ); + is $mech->uri->path, '/auth', "still on auth page"; + $mech->content_contains($error_message); +} + +# create a new account +Email::Send::Test->clear; +$mech->get_ok('/auth'); +$mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { email => $test_email, }, + button => 'create_account', + }, + "create an account for '$test_email'" +); +is $mech->uri->path, '/auth/welcome', "redirected to welcome page"; + +# check that we are now logged in +$mech->get_ok("/auth/check_auth"); + +# check that we got one email +{ + my @emails = Email::Send::Test->emails; + Email::Send::Test->clear; + + is scalar(@emails), 1, "got one email"; + is $emails[0]->header('Subject'), "Your new FixMyStreet.com account", + "subject is correct"; + is $emails[0]->header('To'), $test_email, "to is correct"; + + # extract the link + my ($link) = $emails[0]->body =~ m{(http://\S+)}; + ok $link, "Found a link in email '$link'"; + + # check that the user is currently not confirmed + my $user = + FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + ok $user, "got a user"; + ok !$user->is_confirmed, "user has not been confirmed"; + + # visit the confirm link (with bad token) and check user no confirmed + $mech->get_ok( $link . 'XXX' ); + $user->discard_changes; + ok !$user->is_confirmed, "user has not been confirmed"; + + # visit the confirm link and check user is confirmed + $mech->get_ok($link); + $user->discard_changes; + ok $user->is_confirmed, "user has been confirmed"; +} + +# logout +$mech->get_ok("/auth/logout"); +is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; + +# login using valid details + +# logout + +# try to login with bad details + +# try to create an account with bad details + +# get a password reset email (for bad email address) + +# get a password reminder (for good email address) + +# try using bad reset token + +# use the good reset token and change the password + +# try to use the good token again + +# delete the test user -- cgit v1.2.3 From e18bf78e0513d4f1ebf0413d60691525cdcc2f5d Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 4 Mar 2011 11:07:28 +0000 Subject: Added 'my' section to the site --- t/app/controller/my.t | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 t/app/controller/my.t (limited to 't/app/controller') diff --git a/t/app/controller/my.t b/t/app/controller/my.t new file mode 100644 index 000000000..e018a8941 --- /dev/null +++ b/t/app/controller/my.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More; + + +use Catalyst::Test 'FixMyStreet::App'; +use FixMyStreet::App::Controller::My; + +ok( request('/my')->is_success, 'Request should succeed' ); +done_testing(); -- cgit v1.2.3 From 770ffd1d8fb1f023e78df876a29dc36022246692 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 4 Mar 2011 11:08:07 +0000 Subject: Completed auth section (main parts at least) --- t/app/controller/auth.t | 169 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 134 insertions(+), 35 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 0a0280494..43f83db13 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -6,7 +6,7 @@ BEGIN { FixMyStreet->test_mode(1); } -use Test::More tests => 44; +use Test::More tests => 90; use Email::Send::Test; use FixMyStreet::App; @@ -14,14 +14,13 @@ use FixMyStreet::App; use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; my $mech = Test::WWW::Mechanize::Catalyst->new; -my $test_email = 'test@example.com'; +my $test_email = 'test@example.com'; +my $test_password = 'foobar'; END { - ok( - FixMyStreet::App->model('DB::User')->find( { email => $test_email } ) - ->delete, - "delete test user" - ); + ok( FixMyStreet::App->model('DB::User')->find( { email => $_ } )->delete, + "delete test user '$_'" ) + for ($test_email); } $mech->get_ok('/auth'); @@ -47,7 +46,7 @@ for my $test ( { form_name => 'general_auth', fields => { email => $email, }, - button => 'create_account', + button => 'email_login', }, "try to create an account with email '$email'" ); @@ -62,14 +61,14 @@ $mech->submit_form_ok( { form_name => 'general_auth', fields => { email => $test_email, }, - button => 'create_account', + button => 'email_login', }, "create an account for '$test_email'" ); -is $mech->uri->path, '/auth/welcome', "redirected to welcome page"; +is $mech->uri->path, '/auth/token', "redirected to welcome page"; -# check that we are now logged in -$mech->get_ok("/auth/check_auth"); +# check that we are not logged in yet +is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; # check that we got one email { @@ -77,7 +76,7 @@ $mech->get_ok("/auth/check_auth"); Email::Send::Test->clear; is scalar(@emails), 1, "got one email"; - is $emails[0]->header('Subject'), "Your new FixMyStreet.com account", + is $emails[0]->header('Subject'), "Your FixMyStreet.com account details", "subject is correct"; is $emails[0]->header('To'), $test_email, "to is correct"; @@ -85,43 +84,143 @@ $mech->get_ok("/auth/check_auth"); my ($link) = $emails[0]->body =~ m{(http://\S+)}; ok $link, "Found a link in email '$link'"; - # check that the user is currently not confirmed - my $user = - FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); - ok $user, "got a user"; - ok !$user->is_confirmed, "user has not been confirmed"; + # check that the user does not exist + sub get_user { + FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + } + ok !get_user(), "no user exists"; # visit the confirm link (with bad token) and check user no confirmed $mech->get_ok( $link . 'XXX' ); - $user->discard_changes; - ok !$user->is_confirmed, "user has not been confirmed"; + ok !get_user(), "no user exists"; + is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; # visit the confirm link and check user is confirmed $mech->get_ok($link); - $user->discard_changes; - ok $user->is_confirmed, "user has been confirmed"; + ok get_user(), "user created"; + is $mech->uri->path, '/my', "redirected to the 'my' section of site"; + $mech->get_ok('/auth/check_auth'); + + # logout and try to use the token again + $mech->get_ok("/auth/logout"); + is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; + $mech->get_ok($link); + is $mech->uri, $link, "not logged in"; + $mech->content_contains( 'Link too old or already used', + 'token now invalid' ); + is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; } -# logout -$mech->get_ok("/auth/logout"); -is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; +# get a login email and change password +{ + Email::Send::Test->clear; + $mech->get_ok('/auth'); + $mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { email => "$test_email", }, + button => 'email_login', + }, + "email_login with '$test_email'" + ); + is $mech->uri->path, '/auth/token', "redirected to token page"; -# login using valid details + # rest is as before so no need to test -# logout + # follow link and change password - check not prompted for old password + is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; -# try to login with bad details + my @emails = Email::Send::Test->emails; + my ($link) = $emails[0]->body =~ m{(http://\S+)}; + $mech->get_ok($link); + + $mech->follow_link_ok( { url => '/auth/change_password' } ); + + ok my $form = $mech->form_name('change_password'), + "found change password form"; + is_deeply [ sort grep { $_ } map { $_->name } $form->inputs ], # + [ 'confirm', 'new_password' ], + "check we got expected fields (ie not old_password)"; + + # check the various ways the form can be wrong + for my $test ( + { new => '', conf => '', err => 'enter a password', }, + { new => 'secret', conf => '', err => 'do not match', }, + { new => '', conf => 'secret', err => 'do not match', }, + { new => 'secret', conf => 'not_secret', err => 'do not match', }, + ) + { + $mech->get_ok('/auth/change_password'); + $mech->content_lacks( $test->{err}, "did not find expected error" ); + $mech->submit_form_ok( + { + form_name => 'change_password', + fields => + { new_password => $test->{new}, confirm => $test->{conf}, }, + }, + "change_password with '$test->{new}' and '$test->{conf}'" + ); + $mech->content_contains( $test->{err}, "found expected error" ); + } + + my $user = + FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + ok $user, "got a user"; + ok !$user->password, "user has no password"; -# try to create an account with bad details + $mech->get_ok('/auth/change_password'); + $mech->submit_form_ok( + { + form_name => 'change_password', + fields => + { new_password => $test_password, confirm => $test_password, }, + }, + "change_password with '$test_password' and '$test_password'" + ); + is $mech->uri->path, '/auth/change_password', + "still on change password page"; + $mech->content_contains( 'password has been changed', + "found password changed" ); -# get a password reset email (for bad email address) + $user->discard_changes(); + ok $user->password, "user now has a password"; +} -# get a password reminder (for good email address) +# login using valid details +$mech->get_ok('/auth'); +$mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { + email => $test_email, + password => $test_password, + }, + button => 'login', + }, + "login with '$test_email' & '$test_password" +); +is $mech->uri->path, '/my', "redirected to correct page"; -# try using bad reset token +# logout +$mech->get_ok("/auth/logout"); +is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; -# use the good reset token and change the password +# try to login with bad details +$mech->get_ok('/auth'); +$mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { + email => $test_email, + password => 'not the password', + }, + button => 'login', + }, + "login with '$test_email' & '$test_password" +); +is $mech->uri->path, '/auth', "redirected to correct page"; +$mech->content_contains( 'Email or password wrong', 'found error message' ); -# try to use the good token again +# more test: +# TODO: test that email are always lowercased -# delete the test user -- cgit v1.2.3 From df8c32881171b5ea73d4e77030c9f642f7f19aab Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 18 Mar 2011 15:50:35 +0000 Subject: Controller to handle new reports and outline of tests needed --- t/app/controller/reports_new.t | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 t/app/controller/reports_new.t (limited to 't/app/controller') diff --git a/t/app/controller/reports_new.t b/t/app/controller/reports_new.t new file mode 100644 index 000000000..e071eff9a --- /dev/null +++ b/t/app/controller/reports_new.t @@ -0,0 +1,48 @@ +use strict; +use warnings; +use Test::More; + +use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; + +my $mech = Test::WWW::Mechanize::Catalyst->new(); +$mech->get_ok('/reports/new'); + +TODO: { + local $TODO = "paths to '/reports/new' not handled by catalyst yet"; + fail "Test that clicking on map sends user here"; + fail "Test that clicking on 'skip map' link sends user here"; + fail "Test that partial token sends user here"; +} + +#### test report creation for a user who does not have an account +# come to site +# fill in report +# recieve token +# confirm token +# report is confirmed +# user is created and logged in + + +#### test report creation for a user who has account but is not logged in +# come to site +# fill in report +# recieve token +# confirm token +# report is confirmed + + +#### test report creation for user with account and logged in +# come to site +# fill in report +# report is confirmed + + +#### test uploading an image + +#### test completing a partial report (eq flickr upload) + +#### test error cases when filling in a report + + + +done_testing(); -- cgit v1.2.3 From 76253c9ff527ad14f932b9fec5dca795b1ba08d8 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Mon, 21 Mar 2011 11:56:47 +0000 Subject: WiP: determine location from pc --- t/app/controller/reports_new.t | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/reports_new.t b/t/app/controller/reports_new.t index e071eff9a..1cd4b1ab1 100644 --- a/t/app/controller/reports_new.t +++ b/t/app/controller/reports_new.t @@ -17,7 +17,7 @@ TODO: { #### test report creation for a user who does not have an account # come to site # fill in report -# recieve token +# receive token # confirm token # report is confirmed # user is created and logged in @@ -26,7 +26,7 @@ TODO: { #### test report creation for a user who has account but is not logged in # come to site # fill in report -# recieve token +# receive token # confirm token # report is confirmed @@ -43,6 +43,11 @@ TODO: { #### test error cases when filling in a report +#### possibly manual testing +# create report without using map +# create report by clicking on may with javascript off +# create report with images off + done_testing(); -- cgit v1.2.3 From 20ae747d9a49473e5664b27156d7fefd38eb6333 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 25 Mar 2011 11:10:18 +0000 Subject: Tests for pc searches (both hits and misses) --- t/app/controller/reports_new.t | 97 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 12 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/reports_new.t b/t/app/controller/reports_new.t index 1cd4b1ab1..506678459 100644 --- a/t/app/controller/reports_new.t +++ b/t/app/controller/reports_new.t @@ -2,16 +2,94 @@ use strict; use warnings; use Test::More; -use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; +use FixMyStreet::TestMech; +use Web::Scraper; -my $mech = Test::WWW::Mechanize::Catalyst->new(); +my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/reports/new'); -TODO: { - local $TODO = "paths to '/reports/new' not handled by catalyst yet"; - fail "Test that clicking on map sends user here"; - fail "Test that clicking on 'skip map' link sends user here"; - fail "Test that partial token sends user here"; +# TODO: { +# local $TODO = "paths to '/reports/new' not handled by catalyst yet"; +# fail "Test that clicking on map sends user here"; +# fail "Test that clicking on 'skip map' link sends user here"; +# fail +# "Test that clicking on 'Report a Problem' in header link sends user here"; +# fail "Test that partial token sends user here"; +# } + +# test various locations on inital search box +foreach my $test ( + { + pc => '', # + errors => [], + pc_alternatives => [], + }, + { + pc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', + errors => ['Sorry, we could not find that location.'], + pc_alternatives => [], + }, + { + pc => 'ZZ9 9ZZ', + errors => + ['We had a problem with the supplied co-ordinates - outside the UK?'], + pc_alternatives => [], + }, + { + pc => 'glenthorpe', + errors => [], + pc_alternatives => [ + 'Glenthorpe Crescent, Leeds LS9 7, UK', + 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', + 'Glenthorpe Ln, Katy, TX 77494, USA', + 'Glenthorpe Dr, Walnut, CA 91789, USA', + 'Glenthorpe Ave, Leeds LS9 7, UK', + 'Glenthorpe Ct, Katy, TX 77494, USA', + ], + }, + { + pc => 'Glenthorpe Ct, Katy, TX 77494, USA', + errors => + ['We had a problem with the supplied co-ordinates - outside the UK?'], + pc_alternatives => [], + }, + ) +{ + $mech->get_ok('/reports/new'); + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "bad location" ); + is_deeply $mech->form_errors, $test->{errors}, + "expected errors for pc '$test->{pc}'"; + is_deeply $mech->pc_alternatives, $test->{pc_alternatives}, + "expected alternatives for pc '$test->{pc}'"; +} + +# check that exact queries result in the correct lat,lng +foreach my $test ( + { + pc => 'SW1A 1AA', + latitude => '51.5010096115539', + longitude => '-0.141587067110009', + }, + { + pc => 'Manchester', + latitude => '53.4807125', + longitude => '-2.2343765', + }, + { + pc => 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', + latitude => '51.3937997', + longitude => '-0.2209596', + }, + ) +{ + $mech->get_ok('/reports/new'); + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "good location" ); + is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + is_deeply $mech->extract_location, $test, + "got expected location for pc '$test->{pc}'"; + } #### test report creation for a user who does not have an account @@ -22,7 +100,6 @@ TODO: { # report is confirmed # user is created and logged in - #### test report creation for a user who has account but is not logged in # come to site # fill in report @@ -30,13 +107,11 @@ TODO: { # confirm token # report is confirmed - #### test report creation for user with account and logged in # come to site # fill in report # report is confirmed - #### test uploading an image #### test completing a partial report (eq flickr upload) @@ -48,6 +123,4 @@ TODO: { # create report by clicking on may with javascript off # create report with images off - - done_testing(); -- cgit v1.2.3 From 47bf5d345fca67912d5f061813f22e599b2bb1d5 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 25 Mar 2011 15:09:53 +0000 Subject: More tests (and fixes to issues thrown up) --- t/app/controller/reports_new.t | 218 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 215 insertions(+), 3 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/reports_new.t b/t/app/controller/reports_new.t index 506678459..dd353a903 100644 --- a/t/app/controller/reports_new.t +++ b/t/app/controller/reports_new.t @@ -36,9 +36,9 @@ foreach my $test ( pc_alternatives => [], }, { - pc => 'glenthorpe', - errors => [], - pc_alternatives => [ + pc => 'glenthorpe', + errors => [], + pc_alternatives => [ # TODO - should filter out these non-UK addresses 'Glenthorpe Crescent, Leeds LS9 7, UK', 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', 'Glenthorpe Ln, Katy, TX 77494, USA', @@ -89,6 +89,218 @@ foreach my $test ( is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; is_deeply $mech->extract_location, $test, "got expected location for pc '$test->{pc}'"; +} + +# test that the various bit of form get filled in and errors correctly +# generated. +foreach my $test ( + { + msg => 'all fields empty', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => '', + may_show_name => '1', + email => '', + phone => '', + }, + changes => {}, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please enter your name', + 'Please enter your email', + ], + }, + { + msg => 'may_show_name defaults to true', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => '', + may_show_name => undef, + email => '', + phone => '', + }, + changes => { may_show_name => '1' }, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please enter your name', + 'Please enter your email', + ], + }, + { + msg => 'may_show_name unchanged if name is present (stays false)', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => 'Bob Jones', + may_show_name => undef, + email => '', + phone => '', + }, + changes => {}, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please enter your email', + ], + }, + { + msg => 'may_show_name unchanged if name is present (stays true)', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => 'Bob Jones', + may_show_name => '1', + email => '', + phone => '', + }, + changes => {}, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please enter your email', + ], + }, + { + msg => 'title and details tidied up', + pc => 'SW1A 1AA', + fields => { + title => 'DOG SHIT ON WALLS', + detail => 'on this portakabin - more of a portaloo HEH!!', + photo => '', + name => 'Bob Jones', + may_show_name => '1', + email => '', + phone => '', + }, + changes => { + title => 'Dog poo on walls', + detail => + 'On this [portable cabin] - more of a [portable loo] HEH!!', + }, + errors => [ 'Please enter your email', ], + }, + { + msg => 'name too short', + pc => 'SW1A 1AA', + fields => { + title => 'Test title', + detail => 'Test detail', + photo => '', + name => 'DUDE', + may_show_name => '1', + email => '', + phone => '', + }, + changes => {}, + errors => [ +'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', + 'Please enter your email', + ], + }, + { + msg => 'name is anonymous', + pc => 'SW1A 1AA', + fields => { + title => 'Test title', + detail => 'Test detail', + photo => '', + name => 'anonymous', + may_show_name => '1', + email => '', + phone => '', + }, + changes => {}, + errors => [ +'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', + 'Please enter your email', + ], + }, + { + msg => 'email invalid', + pc => 'SW1A 1AA', + fields => { + title => 'Test title', + detail => 'Test detail', + photo => '', + name => 'Joe Smith', + may_show_name => '1', + email => 'not an email', + phone => '', + }, + changes => { email => 'notanemail', }, + errors => [ 'Please enter a valid email', ], + }, + { + msg => 'cleanup title and detail', + pc => 'SW1A 1AA', + fields => { + title => " Test title ", + detail => " first line \n\n second\nline\n\n ", + photo => '', + name => '', + may_show_name => '1', + email => '', + phone => '', + }, + changes => { + title => 'Test title', + detail => "First line\n\nSecond line", + }, + errors => [ 'Please enter your name', 'Please enter your email', ], + }, + { + msg => 'clean up name and email', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => ' Bob Jones ', + may_show_name => '1', + email => ' BOB @ExAmplE.COM ', + phone => '', + }, + changes => { + name => 'Bob Jones', + email => 'bob@example.com', + }, + errors => [ 'Please enter a subject', 'Please enter some details', ], + }, + ) +{ + pass "--- $test->{msg} ---"; + $mech->get_ok('/reports/new'); + + # submit initial pc form + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "submit location" ); + is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + + # submit the main form + $mech->submit_form_ok( { with_fields => $test->{fields} }, "submit form" ); + + # check that we got the errors expected + is_deeply $mech->form_errors, $test->{errors}, "check errors"; + + # check that fields have changed as expected + my $new_values = { + %{ $test->{fields} }, # values added to form + %{ $test->{changes} }, # changes we expect + }; + is_deeply $mech->visible_form_values, $new_values, + "values correctly changed"; } -- cgit v1.2.3 From 3aa202368e73f8ea76eb85dd5cc6f529604f26ba Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 25 Mar 2011 16:48:02 +0000 Subject: Move login/out methods into TestMech --- t/app/controller/auth.t | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 43f83db13..651fd0285 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -1,18 +1,11 @@ use strict; use warnings; -BEGIN { - use FixMyStreet; - FixMyStreet->test_mode(1); -} - use Test::More tests => 90; use Email::Send::Test; -use FixMyStreet::App; - -use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; -my $mech = Test::WWW::Mechanize::Catalyst->new; +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; my $test_email = 'test@example.com'; my $test_password = 'foobar'; @@ -26,7 +19,7 @@ END { $mech->get_ok('/auth'); # check that we can't reach a page that is only available to authenticated users -is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; +$mech->not_logged_in_ok; # check that submitting form with no / bad email creates an error. $mech->get_ok('/auth'); @@ -68,7 +61,7 @@ $mech->submit_form_ok( is $mech->uri->path, '/auth/token', "redirected to welcome page"; # check that we are not logged in yet -is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; +$mech->not_logged_in_ok; # check that we got one email { @@ -93,22 +86,21 @@ is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; # visit the confirm link (with bad token) and check user no confirmed $mech->get_ok( $link . 'XXX' ); ok !get_user(), "no user exists"; - is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; + $mech->not_logged_in_ok; # visit the confirm link and check user is confirmed $mech->get_ok($link); ok get_user(), "user created"; is $mech->uri->path, '/my', "redirected to the 'my' section of site"; - $mech->get_ok('/auth/check_auth'); + $mech->logged_in_ok; # logout and try to use the token again - $mech->get_ok("/auth/logout"); - is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; + $mech->log_out_ok; $mech->get_ok($link); is $mech->uri, $link, "not logged in"; $mech->content_contains( 'Link too old or already used', 'token now invalid' ); - is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; + $mech->not_logged_in_ok; } # get a login email and change password @@ -128,7 +120,7 @@ is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; # rest is as before so no need to test # follow link and change password - check not prompted for old password - is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; + $mech->not_logged_in_ok; my @emails = Email::Send::Test->emails; my ($link) = $emails[0]->body =~ m{(http://\S+)}; @@ -202,8 +194,7 @@ $mech->submit_form_ok( is $mech->uri->path, '/my', "redirected to correct page"; # logout -$mech->get_ok("/auth/logout"); -is $mech->get('/auth/check_auth')->code, 401, "got 401 at check_auth"; +$mech->log_out_ok; # try to login with bad details $mech->get_ok('/auth'); -- cgit v1.2.3 From 8f87691e3bb328879a1ff8c1baa1aa6748368f68 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 25 Mar 2011 17:03:50 +0000 Subject: Abstracted out some email tests --- t/app/controller/auth.t | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 651fd0285..6e1e8d58d 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -1,8 +1,7 @@ use strict; use warnings; -use Test::More tests => 90; -use Email::Send::Test; +use Test::More tests => 97; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -48,7 +47,7 @@ for my $test ( } # create a new account -Email::Send::Test->clear; +$mech->clear_emails_ok; $mech->get_ok('/auth'); $mech->submit_form_ok( { @@ -65,16 +64,15 @@ $mech->not_logged_in_ok; # check that we got one email { - my @emails = Email::Send::Test->emails; - Email::Send::Test->clear; - - is scalar(@emails), 1, "got one email"; - is $emails[0]->header('Subject'), "Your FixMyStreet.com account details", + $mech->email_count_is(1); + my $email = $mech->get_email; + $mech->clear_emails_ok; + is $email->header('Subject'), "Your FixMyStreet.com account details", "subject is correct"; - is $emails[0]->header('To'), $test_email, "to is correct"; + is $email->header('To'), $test_email, "to is correct"; # extract the link - my ($link) = $emails[0]->body =~ m{(http://\S+)}; + my ($link) = $email->body =~ m{(http://\S+)}; ok $link, "Found a link in email '$link'"; # check that the user does not exist @@ -105,7 +103,7 @@ $mech->not_logged_in_ok; # get a login email and change password { - Email::Send::Test->clear; + $mech->clear_emails_ok; $mech->get_ok('/auth'); $mech->submit_form_ok( { @@ -122,8 +120,10 @@ $mech->not_logged_in_ok; # follow link and change password - check not prompted for old password $mech->not_logged_in_ok; - my @emails = Email::Send::Test->emails; - my ($link) = $emails[0]->body =~ m{(http://\S+)}; + $mech->email_count_is(1); + my $email = $mech->get_email; + $mech->clear_emails_ok; + my ($link) = $email->body =~ m{(http://\S+)}; $mech->get_ok($link); $mech->follow_link_ok( { url => '/auth/change_password' } ); -- cgit v1.2.3 From 9942c5c59ab28d0441ea5ba49a7bd426f17e45c3 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Mon, 28 Mar 2011 14:21:56 +0100 Subject: Handle problem confirmation tokens in catalyst and get all tests working --- t/app/controller/reports_new.t | 143 ++++++++++++++++++++++++++++++----------- t/app/controller/tokens.t | 10 +++ 2 files changed, 115 insertions(+), 38 deletions(-) create mode 100644 t/app/controller/tokens.t (limited to 't/app/controller') diff --git a/t/app/controller/reports_new.t b/t/app/controller/reports_new.t index dd353a903..aa4920cc5 100644 --- a/t/app/controller/reports_new.t +++ b/t/app/controller/reports_new.t @@ -55,13 +55,15 @@ foreach my $test ( }, ) { - $mech->get_ok('/reports/new'); - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "bad location" ); - is_deeply $mech->form_errors, $test->{errors}, - "expected errors for pc '$test->{pc}'"; - is_deeply $mech->pc_alternatives, $test->{pc_alternatives}, - "expected alternatives for pc '$test->{pc}'"; + subtest "test bad pc value '$test->{pc}'" => sub { + $mech->get_ok('/reports/new'); + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "bad location" ); + is_deeply $mech->form_errors, $test->{errors}, + "expected errors for pc '$test->{pc}'"; + is_deeply $mech->pc_alternatives, $test->{pc_alternatives}, + "expected alternatives for pc '$test->{pc}'"; + }; } # check that exact queries result in the correct lat,lng @@ -83,12 +85,14 @@ foreach my $test ( }, ) { - $mech->get_ok('/reports/new'); - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "good location" ); - is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; - is_deeply $mech->extract_location, $test, - "got expected location for pc '$test->{pc}'"; + subtest "check lat/lng for '$test->{pc}'" => sub { + $mech->get_ok('/reports/new'); + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "good location" ); + is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + is_deeply $mech->extract_location, $test, + "got expected location for pc '$test->{pc}'"; + }; } # test that the various bit of form get filled in and errors correctly @@ -280,37 +284,102 @@ foreach my $test ( }, ) { - pass "--- $test->{msg} ---"; - $mech->get_ok('/reports/new'); + subtest "check form errors where $test->{msg}" => sub { + $mech->get_ok('/reports/new'); + + # submit initial pc form + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "submit location" ); + is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + + # submit the main form + $mech->submit_form_ok( { with_fields => $test->{fields} }, + "submit form" ); + + # check that we got the errors expected + is_deeply $mech->form_errors, $test->{errors}, "check errors"; + + # check that fields have changed as expected + my $new_values = { + %{ $test->{fields} }, # values added to form + %{ $test->{changes} }, # changes we expect + }; + is_deeply $mech->visible_form_values, $new_values, + "values correctly changed"; + }; +} + +subtest "test report creation for a user who does not have an account" => sub { + $mech->log_out_ok; + $mech->clear_emails_ok; + + # check that the user does not exist + my $test_email = 'test-1@example.com'; + ok !FixMyStreet::App->model('DB::User')->find( { email => $test_email } ), + "test user does not exist"; # submit initial pc form - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + $mech->get_ok('/reports/new'); + $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, "submit location" ); - is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; - - # submit the main form - $mech->submit_form_ok( { with_fields => $test->{fields} }, "submit form" ); + $mech->submit_form_ok( + { + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + email => 'test-1@example.com', + phone => '07903 123 456', + } + }, + "submit good details" + ); # check that we got the errors expected - is_deeply $mech->form_errors, $test->{errors}, "check errors"; + is_deeply $mech->form_errors, [], "check there were no errors"; - # check that fields have changed as expected - my $new_values = { - %{ $test->{fields} }, # values added to form - %{ $test->{changes} }, # changes we expect - }; - is_deeply $mech->visible_form_values, $new_values, - "values correctly changed"; + # check that the user has been created + my $user = + FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + ok $user, "created new user"; -} + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; -#### test report creation for a user who does not have an account -# come to site -# fill in report -# receive token -# confirm token -# report is confirmed -# user is created and logged in + # check that the report is not available yet. + is $report->state, 'unconfirmed', "report not confirmed"; + is $mech->get( '/reports/' . $report->id )->code, 404, "report not found"; + + # receive token + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the problem/i, "confirm the problem"; + + my ($url) = $email->body =~ m{(http://\S+)}; + ok $url, "extracted confirm url '$url'"; + + # confirm token + $mech->get_ok($url); + $report->discard_changes; + is $report->state, 'confirmed', "Report is now confirmed"; + is $report->state, 'confirmed', "report is now confirmed"; + + TODO: { + local $TODO = "'/reports/<>' not handled by catalyst yet"; + $mech->get_ok( '/reports/' . $report->id ); + } + + # user is created and logged in + $mech->logged_in_ok; + + # cleanup + $mech->log_out_ok; + ok $_->delete, "delete problem" for $user->problems; + ok $user->delete, "delete test user"; +}; #### test report creation for a user who has account but is not logged in # come to site @@ -328,8 +397,6 @@ foreach my $test ( #### test completing a partial report (eq flickr upload) -#### test error cases when filling in a report - #### possibly manual testing # create report without using map # create report by clicking on may with javascript off diff --git a/t/app/controller/tokens.t b/t/app/controller/tokens.t new file mode 100644 index 000000000..eec1b0d35 --- /dev/null +++ b/t/app/controller/tokens.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More; + + +use Catalyst::Test 'FixMyStreet::App'; +use FixMyStreet::App::Controller::Tokens; + +ok( request('/tokens')->is_success, 'Request should succeed' ); +done_testing(); -- cgit v1.2.3 From f5b10293c317e5025f47e6cb332659723684d0f6 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Mon, 28 Mar 2011 14:23:34 +0100 Subject: code tested elsewhere --- t/app/controller/tokens.t | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 t/app/controller/tokens.t (limited to 't/app/controller') diff --git a/t/app/controller/tokens.t b/t/app/controller/tokens.t deleted file mode 100644 index eec1b0d35..000000000 --- a/t/app/controller/tokens.t +++ /dev/null @@ -1,10 +0,0 @@ -use strict; -use warnings; -use Test::More; - - -use Catalyst::Test 'FixMyStreet::App'; -use FixMyStreet::App::Controller::Tokens; - -ok( request('/tokens')->is_success, 'Request should succeed' ); -done_testing(); -- cgit v1.2.3 From 6a201b1ed1aa4b6efb9f1f3801afc05ebfa7ef84 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Mon, 28 Mar 2011 16:34:18 +0100 Subject: Test report creation for user who is logged in also added methods to testmech --- t/app/controller/reports_new.t | 64 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/reports_new.t b/t/app/controller/reports_new.t index aa4920cc5..7ee125592 100644 --- a/t/app/controller/reports_new.t +++ b/t/app/controller/reports_new.t @@ -376,9 +376,7 @@ subtest "test report creation for a user who does not have an account" => sub { $mech->logged_in_ok; # cleanup - $mech->log_out_ok; - ok $_->delete, "delete problem" for $user->problems; - ok $user->delete, "delete test user"; + $mech->delete_user($user); }; #### test report creation for a user who has account but is not logged in @@ -389,9 +387,63 @@ subtest "test report creation for a user who does not have an account" => sub { # report is confirmed #### test report creation for user with account and logged in -# come to site -# fill in report -# report is confirmed +subtest "test report creation for a user who is logged in" => sub { + + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + $mech->clear_emails_ok; + my $user = $mech->log_in_ok($test_email); + + # submit initial pc form + $mech->get_ok('/reports/new'); + $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, + "submit location" ); + + TODO: { + local $TODO = +"'/reports/<>' not handled by catalyst yet - form creation redirects to there on success if logged in"; + eval { + $mech->submit_form_ok( + { + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + email => $test_email, + phone => '07903 123 456', + } + }, + "submit good details" + ); + }; + } + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # check that we got redirected to /reports/ + is $mech->uri->path, "/reports/" . $report->id, "redirected to report page"; + + # check that no emails have been sent + $mech->email_count_is(0); + + # check report is confirmed and available + is $report->state, 'confirmed', "report is now confirmed"; + TODO: { + local $TODO = "'/reports/<>' not handled by catalyst yet"; + $mech->get_ok( '/reports/' . $report->id ); + } + + # user is still logged in + $mech->logged_in_ok; + + # cleanup + $mech->delete_user($user); +}; #### test uploading an image -- cgit v1.2.3 From 53fbccab8e7471fa9e06496a56f136b1edb43351 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 31 Mar 2011 17:54:14 +0100 Subject: Ported import.cgi to catalyst --- t/app/controller/reports_import.t | 158 ++++++++++++++++++++++++++++++++++++++ t/app/controller/reports_new.t | 6 -- t/app/controller/sample.jpg | Bin 0 -> 22588 bytes 3 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 t/app/controller/reports_import.t create mode 100644 t/app/controller/sample.jpg (limited to 't/app/controller') diff --git a/t/app/controller/reports_import.t b/t/app/controller/reports_import.t new file mode 100644 index 000000000..5c16324d3 --- /dev/null +++ b/t/app/controller/reports_import.t @@ -0,0 +1,158 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +use Web::Scraper; +use Path::Class; + +my $mech = FixMyStreet::TestMech->new; +$mech->get_ok('/import'); + +my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; +ok -e $sample_file, "sample file $sample_file exists"; + +# submit an empty report to import - check we get all errors +subtest "Test creating bad partial entries" => sub { + + foreach my $test ( + { + fields => { email => 'bob', }, + errors => [ + 'You must supply a service', + 'Please enter a subject', + 'Please enter your name', + 'Please enter a valid email', + 'Either a location or a photo must be provided.', + ], + }, + { + fields => { email => 'bob@example.com' }, + errors => [ + 'You must supply a service', + 'Please enter a subject', + 'Please enter your name', + 'Either a location or a photo must be provided.', + ], + }, + { + fields => { lat => 1, lon => 1, }, + errors => [ + 'You must supply a service', + 'Please enter a subject', + 'Please enter your name', + 'Please enter your email', +'We had a problem with the supplied co-ordinates - outside the UK?', + ], + }, + { + fields => { photo => $sample_file, }, + errors => [ + 'You must supply a service', + 'Please enter a subject', + 'Please enter your name', + 'Please enter your email', + ], + }, + ) + { + $mech->get_ok('/import'); + + $mech->submit_form_ok( # + { with_fields => $test->{fields} }, + "fill in form" + ); + + is_deeply( $mech->import_errors, $test->{errors}, "expected errors" ); + } + +}; + +# submit an empty report to import - check we get all errors +subtest "Submit a correct entry" => sub { + + $mech->get_ok('/import'); + + $mech->submit_form_ok( # + { + with_fields => { + service => 'test-script', + name => 'Test User', + email => 'test@example.com', + subject => 'Test report', + detail => 'This is a test report', + photo => $sample_file, + } + }, + "fill in form" + ); + + is_deeply( $mech->import_errors, [], "got no errors" ); + is $mech->content, 'SUCCESS', "Got success response"; + + # check that we have received the email + $mech->email_count_is(1); + my $email = $mech->get_email; + $mech->clear_emails_ok; + + my ($token_url) = $email->body =~ m{(http://\S+)}; + ok $token_url, "Found a token url $token_url"; + + # go to the token url + $mech->get_ok($token_url); + + # check that we are not shown anything as we don't have a location yet + is_deeply $mech->visible_form_values, { pc => '' }, + "check only pc field is shown"; + + $mech->submit_form_ok( # + { with_fields => { pc => 'SW1A 1AA' } }, + "fill in postcode" + ); + + # check that we are not shown anything as we don't have a location yet + is_deeply $mech->visible_form_values, + { + name => 'Test User', + email => 'test@example.com', + title => 'Test report', + detail => 'This is a test report', + photo => '', + phone => '', + may_show_name => '1', + }, + "check imported fields are shown"; + + TODO: { + local $TODO = "'/report/123' urls not srved by catalyst yet"; + + # change the details + $mech->submit_form_ok( # + { + with_fields => { + name => 'New Test User', + email => 'test@example.com', + title => 'New Test report', + detail => 'This is a test report', + phone => '01234 567 890', + may_show_name => '1', + } + }, + "Update details and save" + ); + } + + # check that report has been created + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test@example.com' } ); + ok $user, "Found a user"; + + my $report = $user->problems->first; + is $report->state, 'confirmed', 'is confirmed'; + is $report->title, 'New Test report', 'title is correct'; + + $mech->delete_user($user); +}; + +done_testing(); diff --git a/t/app/controller/reports_new.t b/t/app/controller/reports_new.t index 7ee125592..c87571a9d 100644 --- a/t/app/controller/reports_new.t +++ b/t/app/controller/reports_new.t @@ -29,12 +29,6 @@ foreach my $test ( errors => ['Sorry, we could not find that location.'], pc_alternatives => [], }, - { - pc => 'ZZ9 9ZZ', - errors => - ['We had a problem with the supplied co-ordinates - outside the UK?'], - pc_alternatives => [], - }, { pc => 'glenthorpe', errors => [], diff --git a/t/app/controller/sample.jpg b/t/app/controller/sample.jpg new file mode 100644 index 000000000..23198cb83 Binary files /dev/null and b/t/app/controller/sample.jpg differ -- cgit v1.2.3 From 4249138c5f1ba30708fe50971c8adf9f93adc1de Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 1 Apr 2011 11:13:32 +0100 Subject: Change '/reports/new' to '/report/new' Fix broken links to '/reports/<>' Get correct base under CGI and FastCGI --- t/app/controller/report_import.t | 158 +++++++++++++ t/app/controller/report_new.t | 451 ++++++++++++++++++++++++++++++++++++++ t/app/controller/reports_import.t | 158 ------------- t/app/controller/reports_new.t | 451 -------------------------------------- 4 files changed, 609 insertions(+), 609 deletions(-) create mode 100644 t/app/controller/report_import.t create mode 100644 t/app/controller/report_new.t delete mode 100644 t/app/controller/reports_import.t delete mode 100644 t/app/controller/reports_new.t (limited to 't/app/controller') diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t new file mode 100644 index 000000000..5c16324d3 --- /dev/null +++ b/t/app/controller/report_import.t @@ -0,0 +1,158 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +use Web::Scraper; +use Path::Class; + +my $mech = FixMyStreet::TestMech->new; +$mech->get_ok('/import'); + +my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; +ok -e $sample_file, "sample file $sample_file exists"; + +# submit an empty report to import - check we get all errors +subtest "Test creating bad partial entries" => sub { + + foreach my $test ( + { + fields => { email => 'bob', }, + errors => [ + 'You must supply a service', + 'Please enter a subject', + 'Please enter your name', + 'Please enter a valid email', + 'Either a location or a photo must be provided.', + ], + }, + { + fields => { email => 'bob@example.com' }, + errors => [ + 'You must supply a service', + 'Please enter a subject', + 'Please enter your name', + 'Either a location or a photo must be provided.', + ], + }, + { + fields => { lat => 1, lon => 1, }, + errors => [ + 'You must supply a service', + 'Please enter a subject', + 'Please enter your name', + 'Please enter your email', +'We had a problem with the supplied co-ordinates - outside the UK?', + ], + }, + { + fields => { photo => $sample_file, }, + errors => [ + 'You must supply a service', + 'Please enter a subject', + 'Please enter your name', + 'Please enter your email', + ], + }, + ) + { + $mech->get_ok('/import'); + + $mech->submit_form_ok( # + { with_fields => $test->{fields} }, + "fill in form" + ); + + is_deeply( $mech->import_errors, $test->{errors}, "expected errors" ); + } + +}; + +# submit an empty report to import - check we get all errors +subtest "Submit a correct entry" => sub { + + $mech->get_ok('/import'); + + $mech->submit_form_ok( # + { + with_fields => { + service => 'test-script', + name => 'Test User', + email => 'test@example.com', + subject => 'Test report', + detail => 'This is a test report', + photo => $sample_file, + } + }, + "fill in form" + ); + + is_deeply( $mech->import_errors, [], "got no errors" ); + is $mech->content, 'SUCCESS', "Got success response"; + + # check that we have received the email + $mech->email_count_is(1); + my $email = $mech->get_email; + $mech->clear_emails_ok; + + my ($token_url) = $email->body =~ m{(http://\S+)}; + ok $token_url, "Found a token url $token_url"; + + # go to the token url + $mech->get_ok($token_url); + + # check that we are not shown anything as we don't have a location yet + is_deeply $mech->visible_form_values, { pc => '' }, + "check only pc field is shown"; + + $mech->submit_form_ok( # + { with_fields => { pc => 'SW1A 1AA' } }, + "fill in postcode" + ); + + # check that we are not shown anything as we don't have a location yet + is_deeply $mech->visible_form_values, + { + name => 'Test User', + email => 'test@example.com', + title => 'Test report', + detail => 'This is a test report', + photo => '', + phone => '', + may_show_name => '1', + }, + "check imported fields are shown"; + + TODO: { + local $TODO = "'/report/123' urls not srved by catalyst yet"; + + # change the details + $mech->submit_form_ok( # + { + with_fields => { + name => 'New Test User', + email => 'test@example.com', + title => 'New Test report', + detail => 'This is a test report', + phone => '01234 567 890', + may_show_name => '1', + } + }, + "Update details and save" + ); + } + + # check that report has been created + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test@example.com' } ); + ok $user, "Found a user"; + + my $report = $user->problems->first; + is $report->state, 'confirmed', 'is confirmed'; + is $report->title, 'New Test report', 'title is correct'; + + $mech->delete_user($user); +}; + +done_testing(); diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t new file mode 100644 index 000000000..5221a601a --- /dev/null +++ b/t/app/controller/report_new.t @@ -0,0 +1,451 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +use Web::Scraper; + +my $mech = FixMyStreet::TestMech->new; +$mech->get_ok('/report/new'); + +# TODO: { +# local $TODO = "paths to '/report/new' not handled by catalyst yet"; +# fail "Test that clicking on map sends user here"; +# fail "Test that clicking on 'skip map' link sends user here"; +# fail +# "Test that clicking on 'Report a Problem' in header link sends user here"; +# fail "Test that partial token sends user here"; +# } + +# test various locations on inital search box +foreach my $test ( + { + pc => '', # + errors => [], + pc_alternatives => [], + }, + { + pc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', + errors => ['Sorry, we could not find that location.'], + pc_alternatives => [], + }, + { + pc => 'glenthorpe', + errors => [], + pc_alternatives => [ # TODO - should filter out these non-UK addresses + 'Glenthorpe Crescent, Leeds LS9 7, UK', + 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', + 'Glenthorpe Ln, Katy, TX 77494, USA', + 'Glenthorpe Dr, Walnut, CA 91789, USA', + 'Glenthorpe Ave, Leeds LS9 7, UK', + 'Glenthorpe Ct, Katy, TX 77494, USA', + ], + }, + { + pc => 'Glenthorpe Ct, Katy, TX 77494, USA', + errors => + ['We had a problem with the supplied co-ordinates - outside the UK?'], + pc_alternatives => [], + }, + ) +{ + subtest "test bad pc value '$test->{pc}'" => sub { + $mech->get_ok('/report/new'); + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "bad location" ); + is_deeply $mech->form_errors, $test->{errors}, + "expected errors for pc '$test->{pc}'"; + is_deeply $mech->pc_alternatives, $test->{pc_alternatives}, + "expected alternatives for pc '$test->{pc}'"; + }; +} + +# check that exact queries result in the correct lat,lng +foreach my $test ( + { + pc => 'SW1A 1AA', + latitude => '51.5010096115539', + longitude => '-0.141587067110009', + }, + { + pc => 'Manchester', + latitude => '53.4807125', + longitude => '-2.2343765', + }, + { + pc => 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', + latitude => '51.3937997', + longitude => '-0.2209596', + }, + ) +{ + subtest "check lat/lng for '$test->{pc}'" => sub { + $mech->get_ok('/report/new'); + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "good location" ); + is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + is_deeply $mech->extract_location, $test, + "got expected location for pc '$test->{pc}'"; + }; +} + +# test that the various bit of form get filled in and errors correctly +# generated. +foreach my $test ( + { + msg => 'all fields empty', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => '', + may_show_name => '1', + email => '', + phone => '', + }, + changes => {}, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please enter your name', + 'Please enter your email', + ], + }, + { + msg => 'may_show_name defaults to true', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => '', + may_show_name => undef, + email => '', + phone => '', + }, + changes => { may_show_name => '1' }, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please enter your name', + 'Please enter your email', + ], + }, + { + msg => 'may_show_name unchanged if name is present (stays false)', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => 'Bob Jones', + may_show_name => undef, + email => '', + phone => '', + }, + changes => {}, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please enter your email', + ], + }, + { + msg => 'may_show_name unchanged if name is present (stays true)', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => 'Bob Jones', + may_show_name => '1', + email => '', + phone => '', + }, + changes => {}, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please enter your email', + ], + }, + { + msg => 'title and details tidied up', + pc => 'SW1A 1AA', + fields => { + title => 'DOG SHIT ON WALLS', + detail => 'on this portakabin - more of a portaloo HEH!!', + photo => '', + name => 'Bob Jones', + may_show_name => '1', + email => '', + phone => '', + }, + changes => { + title => 'Dog poo on walls', + detail => + 'On this [portable cabin] - more of a [portable loo] HEH!!', + }, + errors => [ 'Please enter your email', ], + }, + { + msg => 'name too short', + pc => 'SW1A 1AA', + fields => { + title => 'Test title', + detail => 'Test detail', + photo => '', + name => 'DUDE', + may_show_name => '1', + email => '', + phone => '', + }, + changes => {}, + errors => [ +'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', + 'Please enter your email', + ], + }, + { + msg => 'name is anonymous', + pc => 'SW1A 1AA', + fields => { + title => 'Test title', + detail => 'Test detail', + photo => '', + name => 'anonymous', + may_show_name => '1', + email => '', + phone => '', + }, + changes => {}, + errors => [ +'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', + 'Please enter your email', + ], + }, + { + msg => 'email invalid', + pc => 'SW1A 1AA', + fields => { + title => 'Test title', + detail => 'Test detail', + photo => '', + name => 'Joe Smith', + may_show_name => '1', + email => 'not an email', + phone => '', + }, + changes => { email => 'notanemail', }, + errors => [ 'Please enter a valid email', ], + }, + { + msg => 'cleanup title and detail', + pc => 'SW1A 1AA', + fields => { + title => " Test title ", + detail => " first line \n\n second\nline\n\n ", + photo => '', + name => '', + may_show_name => '1', + email => '', + phone => '', + }, + changes => { + title => 'Test title', + detail => "First line\n\nSecond line", + }, + errors => [ 'Please enter your name', 'Please enter your email', ], + }, + { + msg => 'clean up name and email', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => '', + photo => '', + name => ' Bob Jones ', + may_show_name => '1', + email => ' BOB @ExAmplE.COM ', + phone => '', + }, + changes => { + name => 'Bob Jones', + email => 'bob@example.com', + }, + errors => [ 'Please enter a subject', 'Please enter some details', ], + }, + ) +{ + subtest "check form errors where $test->{msg}" => sub { + $mech->get_ok('/report/new'); + + # submit initial pc form + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "submit location" ); + is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + + # submit the main form + $mech->submit_form_ok( { with_fields => $test->{fields} }, + "submit form" ); + + # check that we got the errors expected + is_deeply $mech->form_errors, $test->{errors}, "check errors"; + + # check that fields have changed as expected + my $new_values = { + %{ $test->{fields} }, # values added to form + %{ $test->{changes} }, # changes we expect + }; + is_deeply $mech->visible_form_values, $new_values, + "values correctly changed"; + }; +} + +subtest "test report creation for a user who does not have an account" => sub { + $mech->log_out_ok; + $mech->clear_emails_ok; + + # check that the user does not exist + my $test_email = 'test-1@example.com'; + ok !FixMyStreet::App->model('DB::User')->find( { email => $test_email } ), + "test user does not exist"; + + # submit initial pc form + $mech->get_ok('/report/new'); + $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, + "submit location" ); + $mech->submit_form_ok( + { + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + email => 'test-1@example.com', + phone => '07903 123 456', + } + }, + "submit good details" + ); + + # check that we got the errors expected + is_deeply $mech->form_errors, [], "check there were no errors"; + + # check that the user has been created + my $user = + FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + ok $user, "created new user"; + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # check that the report is not available yet. + is $report->state, 'unconfirmed', "report not confirmed"; + is $mech->get( '/report/' . $report->id )->code, 404, "report not found"; + + # receive token + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the problem/i, "confirm the problem"; + + my ($url) = $email->body =~ m{(http://\S+)}; + ok $url, "extracted confirm url '$url'"; + + # confirm token + $mech->get_ok($url); + $report->discard_changes; + is $report->state, 'confirmed', "Report is now confirmed"; + is $report->state, 'confirmed', "report is now confirmed"; + + TODO: { + local $TODO = "'/report/<>' not handled by catalyst yet"; + $mech->get_ok( '/report/' . $report->id ); + } + + # user is created and logged in + $mech->logged_in_ok; + + # cleanup + $mech->delete_user($user); +}; + +#### test report creation for a user who has account but is not logged in +# come to site +# fill in report +# receive token +# confirm token +# report is confirmed + +#### test report creation for user with account and logged in +subtest "test report creation for a user who is logged in" => sub { + + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + $mech->clear_emails_ok; + my $user = $mech->log_in_ok($test_email); + + # submit initial pc form + $mech->get_ok('/report/new'); + $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, + "submit location" ); + + TODO: { + local $TODO = +"'/report/<>' not handled by catalyst yet - form creation redirects to there on success if logged in"; + eval { + $mech->submit_form_ok( + { + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + email => $test_email, + phone => '07903 123 456', + } + }, + "submit good details" + ); + }; + } + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # check that we got redirected to /report/ + is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + + # check that no emails have been sent + $mech->email_count_is(0); + + # check report is confirmed and available + is $report->state, 'confirmed', "report is now confirmed"; + TODO: { + local $TODO = "'/report/<>' not handled by catalyst yet"; + $mech->get_ok( '/report/' . $report->id ); + } + + # user is still logged in + $mech->logged_in_ok; + + # cleanup + $mech->delete_user($user); +}; + +#### test uploading an image + +#### test completing a partial report (eq flickr upload) + +#### possibly manual testing +# create report without using map +# create report by clicking on may with javascript off +# create report with images off + +done_testing(); diff --git a/t/app/controller/reports_import.t b/t/app/controller/reports_import.t deleted file mode 100644 index 5c16324d3..000000000 --- a/t/app/controller/reports_import.t +++ /dev/null @@ -1,158 +0,0 @@ -use strict; -use warnings; -use Test::More; - -use FixMyStreet::TestMech; -use Web::Scraper; -use Path::Class; - -my $mech = FixMyStreet::TestMech->new; -$mech->get_ok('/import'); - -my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; -ok -e $sample_file, "sample file $sample_file exists"; - -# submit an empty report to import - check we get all errors -subtest "Test creating bad partial entries" => sub { - - foreach my $test ( - { - fields => { email => 'bob', }, - errors => [ - 'You must supply a service', - 'Please enter a subject', - 'Please enter your name', - 'Please enter a valid email', - 'Either a location or a photo must be provided.', - ], - }, - { - fields => { email => 'bob@example.com' }, - errors => [ - 'You must supply a service', - 'Please enter a subject', - 'Please enter your name', - 'Either a location or a photo must be provided.', - ], - }, - { - fields => { lat => 1, lon => 1, }, - errors => [ - 'You must supply a service', - 'Please enter a subject', - 'Please enter your name', - 'Please enter your email', -'We had a problem with the supplied co-ordinates - outside the UK?', - ], - }, - { - fields => { photo => $sample_file, }, - errors => [ - 'You must supply a service', - 'Please enter a subject', - 'Please enter your name', - 'Please enter your email', - ], - }, - ) - { - $mech->get_ok('/import'); - - $mech->submit_form_ok( # - { with_fields => $test->{fields} }, - "fill in form" - ); - - is_deeply( $mech->import_errors, $test->{errors}, "expected errors" ); - } - -}; - -# submit an empty report to import - check we get all errors -subtest "Submit a correct entry" => sub { - - $mech->get_ok('/import'); - - $mech->submit_form_ok( # - { - with_fields => { - service => 'test-script', - name => 'Test User', - email => 'test@example.com', - subject => 'Test report', - detail => 'This is a test report', - photo => $sample_file, - } - }, - "fill in form" - ); - - is_deeply( $mech->import_errors, [], "got no errors" ); - is $mech->content, 'SUCCESS', "Got success response"; - - # check that we have received the email - $mech->email_count_is(1); - my $email = $mech->get_email; - $mech->clear_emails_ok; - - my ($token_url) = $email->body =~ m{(http://\S+)}; - ok $token_url, "Found a token url $token_url"; - - # go to the token url - $mech->get_ok($token_url); - - # check that we are not shown anything as we don't have a location yet - is_deeply $mech->visible_form_values, { pc => '' }, - "check only pc field is shown"; - - $mech->submit_form_ok( # - { with_fields => { pc => 'SW1A 1AA' } }, - "fill in postcode" - ); - - # check that we are not shown anything as we don't have a location yet - is_deeply $mech->visible_form_values, - { - name => 'Test User', - email => 'test@example.com', - title => 'Test report', - detail => 'This is a test report', - photo => '', - phone => '', - may_show_name => '1', - }, - "check imported fields are shown"; - - TODO: { - local $TODO = "'/report/123' urls not srved by catalyst yet"; - - # change the details - $mech->submit_form_ok( # - { - with_fields => { - name => 'New Test User', - email => 'test@example.com', - title => 'New Test report', - detail => 'This is a test report', - phone => '01234 567 890', - may_show_name => '1', - } - }, - "Update details and save" - ); - } - - # check that report has been created - my $user = - FixMyStreet::App->model('DB::User') - ->find( { email => 'test@example.com' } ); - ok $user, "Found a user"; - - my $report = $user->problems->first; - is $report->state, 'confirmed', 'is confirmed'; - is $report->title, 'New Test report', 'title is correct'; - - $mech->delete_user($user); -}; - -done_testing(); diff --git a/t/app/controller/reports_new.t b/t/app/controller/reports_new.t deleted file mode 100644 index c87571a9d..000000000 --- a/t/app/controller/reports_new.t +++ /dev/null @@ -1,451 +0,0 @@ -use strict; -use warnings; -use Test::More; - -use FixMyStreet::TestMech; -use Web::Scraper; - -my $mech = FixMyStreet::TestMech->new; -$mech->get_ok('/reports/new'); - -# TODO: { -# local $TODO = "paths to '/reports/new' not handled by catalyst yet"; -# fail "Test that clicking on map sends user here"; -# fail "Test that clicking on 'skip map' link sends user here"; -# fail -# "Test that clicking on 'Report a Problem' in header link sends user here"; -# fail "Test that partial token sends user here"; -# } - -# test various locations on inital search box -foreach my $test ( - { - pc => '', # - errors => [], - pc_alternatives => [], - }, - { - pc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', - errors => ['Sorry, we could not find that location.'], - pc_alternatives => [], - }, - { - pc => 'glenthorpe', - errors => [], - pc_alternatives => [ # TODO - should filter out these non-UK addresses - 'Glenthorpe Crescent, Leeds LS9 7, UK', - 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', - 'Glenthorpe Ln, Katy, TX 77494, USA', - 'Glenthorpe Dr, Walnut, CA 91789, USA', - 'Glenthorpe Ave, Leeds LS9 7, UK', - 'Glenthorpe Ct, Katy, TX 77494, USA', - ], - }, - { - pc => 'Glenthorpe Ct, Katy, TX 77494, USA', - errors => - ['We had a problem with the supplied co-ordinates - outside the UK?'], - pc_alternatives => [], - }, - ) -{ - subtest "test bad pc value '$test->{pc}'" => sub { - $mech->get_ok('/reports/new'); - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "bad location" ); - is_deeply $mech->form_errors, $test->{errors}, - "expected errors for pc '$test->{pc}'"; - is_deeply $mech->pc_alternatives, $test->{pc_alternatives}, - "expected alternatives for pc '$test->{pc}'"; - }; -} - -# check that exact queries result in the correct lat,lng -foreach my $test ( - { - pc => 'SW1A 1AA', - latitude => '51.5010096115539', - longitude => '-0.141587067110009', - }, - { - pc => 'Manchester', - latitude => '53.4807125', - longitude => '-2.2343765', - }, - { - pc => 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', - latitude => '51.3937997', - longitude => '-0.2209596', - }, - ) -{ - subtest "check lat/lng for '$test->{pc}'" => sub { - $mech->get_ok('/reports/new'); - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "good location" ); - is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; - is_deeply $mech->extract_location, $test, - "got expected location for pc '$test->{pc}'"; - }; -} - -# test that the various bit of form get filled in and errors correctly -# generated. -foreach my $test ( - { - msg => 'all fields empty', - pc => 'SW1A 1AA', - fields => { - title => '', - detail => '', - photo => '', - name => '', - may_show_name => '1', - email => '', - phone => '', - }, - changes => {}, - errors => [ - 'Please enter a subject', - 'Please enter some details', - 'Please enter your name', - 'Please enter your email', - ], - }, - { - msg => 'may_show_name defaults to true', - pc => 'SW1A 1AA', - fields => { - title => '', - detail => '', - photo => '', - name => '', - may_show_name => undef, - email => '', - phone => '', - }, - changes => { may_show_name => '1' }, - errors => [ - 'Please enter a subject', - 'Please enter some details', - 'Please enter your name', - 'Please enter your email', - ], - }, - { - msg => 'may_show_name unchanged if name is present (stays false)', - pc => 'SW1A 1AA', - fields => { - title => '', - detail => '', - photo => '', - name => 'Bob Jones', - may_show_name => undef, - email => '', - phone => '', - }, - changes => {}, - errors => [ - 'Please enter a subject', - 'Please enter some details', - 'Please enter your email', - ], - }, - { - msg => 'may_show_name unchanged if name is present (stays true)', - pc => 'SW1A 1AA', - fields => { - title => '', - detail => '', - photo => '', - name => 'Bob Jones', - may_show_name => '1', - email => '', - phone => '', - }, - changes => {}, - errors => [ - 'Please enter a subject', - 'Please enter some details', - 'Please enter your email', - ], - }, - { - msg => 'title and details tidied up', - pc => 'SW1A 1AA', - fields => { - title => 'DOG SHIT ON WALLS', - detail => 'on this portakabin - more of a portaloo HEH!!', - photo => '', - name => 'Bob Jones', - may_show_name => '1', - email => '', - phone => '', - }, - changes => { - title => 'Dog poo on walls', - detail => - 'On this [portable cabin] - more of a [portable loo] HEH!!', - }, - errors => [ 'Please enter your email', ], - }, - { - msg => 'name too short', - pc => 'SW1A 1AA', - fields => { - title => 'Test title', - detail => 'Test detail', - photo => '', - name => 'DUDE', - may_show_name => '1', - email => '', - phone => '', - }, - changes => {}, - errors => [ -'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', - 'Please enter your email', - ], - }, - { - msg => 'name is anonymous', - pc => 'SW1A 1AA', - fields => { - title => 'Test title', - detail => 'Test detail', - photo => '', - name => 'anonymous', - may_show_name => '1', - email => '', - phone => '', - }, - changes => {}, - errors => [ -'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box', - 'Please enter your email', - ], - }, - { - msg => 'email invalid', - pc => 'SW1A 1AA', - fields => { - title => 'Test title', - detail => 'Test detail', - photo => '', - name => 'Joe Smith', - may_show_name => '1', - email => 'not an email', - phone => '', - }, - changes => { email => 'notanemail', }, - errors => [ 'Please enter a valid email', ], - }, - { - msg => 'cleanup title and detail', - pc => 'SW1A 1AA', - fields => { - title => " Test title ", - detail => " first line \n\n second\nline\n\n ", - photo => '', - name => '', - may_show_name => '1', - email => '', - phone => '', - }, - changes => { - title => 'Test title', - detail => "First line\n\nSecond line", - }, - errors => [ 'Please enter your name', 'Please enter your email', ], - }, - { - msg => 'clean up name and email', - pc => 'SW1A 1AA', - fields => { - title => '', - detail => '', - photo => '', - name => ' Bob Jones ', - may_show_name => '1', - email => ' BOB @ExAmplE.COM ', - phone => '', - }, - changes => { - name => 'Bob Jones', - email => 'bob@example.com', - }, - errors => [ 'Please enter a subject', 'Please enter some details', ], - }, - ) -{ - subtest "check form errors where $test->{msg}" => sub { - $mech->get_ok('/reports/new'); - - # submit initial pc form - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "submit location" ); - is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; - - # submit the main form - $mech->submit_form_ok( { with_fields => $test->{fields} }, - "submit form" ); - - # check that we got the errors expected - is_deeply $mech->form_errors, $test->{errors}, "check errors"; - - # check that fields have changed as expected - my $new_values = { - %{ $test->{fields} }, # values added to form - %{ $test->{changes} }, # changes we expect - }; - is_deeply $mech->visible_form_values, $new_values, - "values correctly changed"; - }; -} - -subtest "test report creation for a user who does not have an account" => sub { - $mech->log_out_ok; - $mech->clear_emails_ok; - - # check that the user does not exist - my $test_email = 'test-1@example.com'; - ok !FixMyStreet::App->model('DB::User')->find( { email => $test_email } ), - "test user does not exist"; - - # submit initial pc form - $mech->get_ok('/reports/new'); - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, - "submit location" ); - $mech->submit_form_ok( - { - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo => '', - name => 'Joe Bloggs', - may_show_name => '1', - email => 'test-1@example.com', - phone => '07903 123 456', - } - }, - "submit good details" - ); - - # check that we got the errors expected - is_deeply $mech->form_errors, [], "check there were no errors"; - - # check that the user has been created - my $user = - FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); - ok $user, "created new user"; - - # find the report - my $report = $user->problems->first; - ok $report, "Found the report"; - - # check that the report is not available yet. - is $report->state, 'unconfirmed', "report not confirmed"; - is $mech->get( '/reports/' . $report->id )->code, 404, "report not found"; - - # receive token - my $email = $mech->get_email; - ok $email, "got an email"; - like $email->body, qr/confirm the problem/i, "confirm the problem"; - - my ($url) = $email->body =~ m{(http://\S+)}; - ok $url, "extracted confirm url '$url'"; - - # confirm token - $mech->get_ok($url); - $report->discard_changes; - is $report->state, 'confirmed', "Report is now confirmed"; - is $report->state, 'confirmed', "report is now confirmed"; - - TODO: { - local $TODO = "'/reports/<>' not handled by catalyst yet"; - $mech->get_ok( '/reports/' . $report->id ); - } - - # user is created and logged in - $mech->logged_in_ok; - - # cleanup - $mech->delete_user($user); -}; - -#### test report creation for a user who has account but is not logged in -# come to site -# fill in report -# receive token -# confirm token -# report is confirmed - -#### test report creation for user with account and logged in -subtest "test report creation for a user who is logged in" => sub { - - # check that the user does not exist - my $test_email = 'test-2@example.com'; - - $mech->clear_emails_ok; - my $user = $mech->log_in_ok($test_email); - - # submit initial pc form - $mech->get_ok('/reports/new'); - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, - "submit location" ); - - TODO: { - local $TODO = -"'/reports/<>' not handled by catalyst yet - form creation redirects to there on success if logged in"; - eval { - $mech->submit_form_ok( - { - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo => '', - name => 'Joe Bloggs', - may_show_name => '1', - email => $test_email, - phone => '07903 123 456', - } - }, - "submit good details" - ); - }; - } - - # find the report - my $report = $user->problems->first; - ok $report, "Found the report"; - - # check that we got redirected to /reports/ - is $mech->uri->path, "/reports/" . $report->id, "redirected to report page"; - - # check that no emails have been sent - $mech->email_count_is(0); - - # check report is confirmed and available - is $report->state, 'confirmed', "report is now confirmed"; - TODO: { - local $TODO = "'/reports/<>' not handled by catalyst yet"; - $mech->get_ok( '/reports/' . $report->id ); - } - - # user is still logged in - $mech->logged_in_ok; - - # cleanup - $mech->delete_user($user); -}; - -#### test uploading an image - -#### test completing a partial report (eq flickr upload) - -#### possibly manual testing -# create report without using map -# create report by clicking on may with javascript off -# create report with images off - -done_testing(); -- cgit v1.2.3 From ded9698102ad0bde486dd414d4cca5a679c9172d Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 1 Apr 2011 11:25:03 +0100 Subject: remove silly tests --- t/app/controller/report_new.t | 9 --------- 1 file changed, 9 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 5221a601a..61f009619 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -8,15 +8,6 @@ use Web::Scraper; my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/report/new'); -# TODO: { -# local $TODO = "paths to '/report/new' not handled by catalyst yet"; -# fail "Test that clicking on map sends user here"; -# fail "Test that clicking on 'skip map' link sends user here"; -# fail -# "Test that clicking on 'Report a Problem' in header link sends user here"; -# fail "Test that partial token sends user here"; -# } - # test various locations on inital search box foreach my $test ( { -- cgit v1.2.3 From 48fac6844f4a55c2086e17e9c75819a8ebc8c156 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 1 Apr 2011 15:20:23 +0100 Subject: Prevent access to '/my' for users who are not logged in --- t/app/controller/my.t | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/my.t b/t/app/controller/my.t index e018a8941..1ed6806a4 100644 --- a/t/app/controller/my.t +++ b/t/app/controller/my.t @@ -1,10 +1,19 @@ use strict; use warnings; -use Test::More; +use Test::More tests => 11; -use Catalyst::Test 'FixMyStreet::App'; -use FixMyStreet::App::Controller::My; +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +$mech->get_ok('/my'); +is $mech->uri->path, '/auth', "got sent to the login page"; + +# login +my $user = $mech->log_in_ok( 'test@example.com' ); +$mech->get_ok('/my'); +is $mech->uri->path, '/my', "stayed on '/my/' page"; + +# cleanup +$mech->delete_user( $user ); -ok( request('/my')->is_success, 'Request should succeed' ); -done_testing(); -- cgit v1.2.3 From 00f183081599bfbb0b68724d058658123639fb84 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 1 Apr 2011 15:45:17 +0100 Subject: prefill user's details if logged in --- t/app/controller/report_new.t | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 61f009619..dca86db77 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -380,11 +380,35 @@ subtest "test report creation for a user who is logged in" => sub { $mech->clear_emails_ok; my $user = $mech->log_in_ok($test_email); + # setup the user. + ok $user->update( + { + name => 'Test User', + phone => '01234 567 890', + } + ), + "set users details"; + # submit initial pc form $mech->get_ok('/report/new'); $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, "submit location" ); + # check that the fields are correctly prefilled + is_deeply( + $mech->visible_form_values, + { + title => '', + detail => '', + may_show_name => '1', + email => $test_email, + name => 'Test User', + phone => '01234 567 890', + photo => '', + }, + "user's details prefilled" + ); + TODO: { local $TODO = "'/report/<>' not handled by catalyst yet - form creation redirects to there on success if logged in"; @@ -397,7 +421,6 @@ subtest "test report creation for a user who is logged in" => sub { photo => '', name => 'Joe Bloggs', may_show_name => '1', - email => $test_email, phone => '07903 123 456', } }, -- cgit v1.2.3 From d0059b5b46bf16d5adbeddffc412699a8c815725 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 7 Apr 2011 15:41:59 +0100 Subject: Add the 'remember_me' checkbox on login --- t/app/controller/auth.t | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 6e1e8d58d..78d3a5abf 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 97; +use Test::More tests => 94; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -178,23 +178,33 @@ $mech->not_logged_in_ok; ok $user->password, "user now has a password"; } -# login using valid details -$mech->get_ok('/auth'); -$mech->submit_form_ok( - { - form_name => 'general_auth', - fields => { - email => $test_email, - password => $test_password, - }, - button => 'login', - }, - "login with '$test_email' & '$test_password" -); -is $mech->uri->path, '/my', "redirected to correct page"; +foreach my $remember_me ( '1', '0' ) { + subtest "login using valid details (remember_me => '$remember_me')" => sub { + $mech->get_ok('/auth'); + $mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { + email => $test_email, + password => $test_password, + remember_me => ( $remember_me ? 1 : undef ), + }, + button => 'login', + }, + "login with '$test_email' & '$test_password" + ); + is $mech->uri->path, '/my', "redirected to correct page"; -# logout -$mech->log_out_ok; + # check that the cookie has no expiry set + my $expiry = $mech->session_cookie_expiry; + $remember_me + ? cmp_ok( $expiry, '>', 86400, "long expiry time" ) + : is( $expiry, 0, "no expiry time" ); + + # logout + $mech->log_out_ok; + }; +} # try to login with bad details $mech->get_ok('/auth'); -- cgit v1.2.3 From 0786cbc17ad0d773c3fe125a43bd8b6e058a22dc Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Mon, 11 Apr 2011 17:15:16 +0100 Subject: More robust tests --- t/app/controller/auth.t | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 78d3a5abf..9f08c8aa9 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -1,18 +1,18 @@ use strict; use warnings; -use Test::More tests => 94; +use Test::More; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; my $test_email = 'test@example.com'; my $test_password = 'foobar'; +$mech->delete_user($test_email); END { - ok( FixMyStreet::App->model('DB::User')->find( { email => $_ } )->delete, - "delete test user '$_'" ) - for ($test_email); + $mech->delete_user($test_email); + done_testing(); } $mech->get_ok('/auth'); @@ -224,4 +224,3 @@ $mech->content_contains( 'Email or password wrong', 'found error message' ); # more test: # TODO: test that email are always lowercased - -- cgit v1.2.3 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') 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') 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/around.t | 31 +++++++++++++++++++++++++++++++ t/app/controller/index.t | 7 +++---- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 t/app/controller/around.t (limited to 't/app/controller') diff --git a/t/app/controller/around.t b/t/app/controller/around.t new file mode 100644 index 000000000..021cf8f7d --- /dev/null +++ b/t/app/controller/around.t @@ -0,0 +1,31 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +subtest "check that if no query we get sent back to the homepage" => sub { + $mech->get_ok('/around'); + is $mech->uri->path, '/', "sent back to '/'"; +}; + +# x,y requests were generated by the old map code. We keep the behavior for +# historic links +subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub { + + $mech->get_ok('/around?x=3281&y=1113'); + + # did we redirect to lat,lon? + is $mech->uri->path, '/around', "still on /around"; + is_deeply { $mech->uri->query_form }, + { lat => 51.4998246332569, lon => -0.140137309739907, }, + "lat,lon correctly set"; + + # was it a 301? + is $mech->res->code, 200, "got 200 for final destination"; + is $mech->res->previous->code, 301, "got 301 for redirect"; + +}; + +done_testing(); 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 90c05378d5b870b94865189f7b72583ac5022c94 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Wed, 13 Apr 2011 11:13:39 +0100 Subject: Moved some of the location smarts from '/report/new' to '/around' --- t/app/controller/around.t | 74 +++++++++++++++++++++++++++++++++++++++- t/app/controller/report_import.t | 8 +++-- t/app/controller/report_new.t | 73 ++------------------------------------- 3 files changed, 82 insertions(+), 73 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 021cf8f7d..069ec605a 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -7,7 +7,7 @@ my $mech = FixMyStreet::TestMech->new; subtest "check that if no query we get sent back to the homepage" => sub { $mech->get_ok('/around'); - is $mech->uri->path, '/', "sent back to '/'"; + is $mech->uri->path, '/around', "still at '/around'"; }; # x,y requests were generated by the old map code. We keep the behavior for @@ -28,4 +28,76 @@ subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub { }; +# test various locations on inital search box +foreach my $test ( + { + pc => '', # + errors => [], + pc_alternatives => [], + }, + { + pc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', + errors => ['Sorry, we could not find that location.'], + pc_alternatives => [], + }, + { + pc => 'glenthorpe', + errors => [], + pc_alternatives => [ # TODO - should filter out these non-UK addresses + 'Glenthorpe Crescent, Leeds LS9 7', + 'Glenthorpe Rd, Merton, Greater London SM4 4', + 'Glenthorpe Ln, Katy, TX 77494, USA', + 'Glenthorpe Dr, Walnut, CA 91789, USA', + 'Glenthorpe Ave, Leeds LS9 7', + 'Glenthorpe Ct, Katy, TX 77494, USA', + ], + }, + { + pc => 'Glenthorpe Ct, Katy, TX 77494, USA', + errors => + ['We had a problem with the supplied co-ordinates - outside the UK?'], + pc_alternatives => [], + }, + ) +{ + subtest "test bad pc value '$test->{pc}'" => sub { + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "bad location" ); + is_deeply $mech->page_errors, $test->{errors}, + "expected errors for pc '$test->{pc}'"; + is_deeply $mech->pc_alternatives, $test->{pc_alternatives}, + "expected alternatives for pc '$test->{pc}'"; + }; +} + +# check that exact queries result in the correct lat,lng +foreach my $test ( + { + pc => 'SW1A 1AA', + latitude => '51.5010096115539', + longitude => '-0.141587067110009', + }, + { + pc => 'Manchester', + latitude => '53.4807125', + longitude => '-2.2343765', + }, + { + pc => 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', + latitude => '51.3937997', + longitude => '-0.2209596', + }, + ) +{ + subtest "check lat/lng for '$test->{pc}'" => sub { + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "good location" ); + is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + is_deeply $mech->extract_location, $test, + "got expected location for pc '$test->{pc}'"; + }; +} + done_testing(); diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 5c16324d3..764357b57 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -105,12 +105,16 @@ subtest "Submit a correct entry" => sub { is_deeply $mech->visible_form_values, { pc => '' }, "check only pc field is shown"; + is $mech->uri->path, '/around', "sent to report page"; + $mech->submit_form_ok( # { with_fields => { pc => 'SW1A 1AA' } }, "fill in postcode" ); - # check that we are not shown anything as we don't have a location yet + is $mech->uri->path, '/report/new', "sent to report page"; + + # check that fields are prefilled for us is_deeply $mech->visible_form_values, { name => 'Test User', @@ -124,7 +128,7 @@ subtest "Submit a correct entry" => sub { "check imported fields are shown"; TODO: { - local $TODO = "'/report/123' urls not srved by catalyst yet"; + local $TODO = "'/report/123' urls not served by catalyst yet"; # change the details $mech->submit_form_ok( # diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index dca86db77..1310a3e35 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -8,77 +8,10 @@ use Web::Scraper; my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/report/new'); -# test various locations on inital search box -foreach my $test ( - { - pc => '', # - errors => [], - pc_alternatives => [], - }, - { - pc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', - errors => ['Sorry, we could not find that location.'], - pc_alternatives => [], - }, - { - pc => 'glenthorpe', - errors => [], - pc_alternatives => [ # TODO - should filter out these non-UK addresses - 'Glenthorpe Crescent, Leeds LS9 7, UK', - 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', - 'Glenthorpe Ln, Katy, TX 77494, USA', - 'Glenthorpe Dr, Walnut, CA 91789, USA', - 'Glenthorpe Ave, Leeds LS9 7, UK', - 'Glenthorpe Ct, Katy, TX 77494, USA', - ], - }, - { - pc => 'Glenthorpe Ct, Katy, TX 77494, USA', - errors => - ['We had a problem with the supplied co-ordinates - outside the UK?'], - pc_alternatives => [], - }, - ) -{ - subtest "test bad pc value '$test->{pc}'" => sub { - $mech->get_ok('/report/new'); - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "bad location" ); - is_deeply $mech->form_errors, $test->{errors}, - "expected errors for pc '$test->{pc}'"; - is_deeply $mech->pc_alternatives, $test->{pc_alternatives}, - "expected alternatives for pc '$test->{pc}'"; - }; -} +fail "test that lat,lon not covered by council goes to '/around'"; + +fail "test that partial code is transferred"; -# check that exact queries result in the correct lat,lng -foreach my $test ( - { - pc => 'SW1A 1AA', - latitude => '51.5010096115539', - longitude => '-0.141587067110009', - }, - { - pc => 'Manchester', - latitude => '53.4807125', - longitude => '-2.2343765', - }, - { - pc => 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', - latitude => '51.3937997', - longitude => '-0.2209596', - }, - ) -{ - subtest "check lat/lng for '$test->{pc}'" => sub { - $mech->get_ok('/report/new'); - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "good location" ); - is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; - is_deeply $mech->extract_location, $test, - "got expected location for pc '$test->{pc}'"; - }; -} # test that the various bit of form get filled in and errors correctly # generated. -- cgit v1.2.3 From 998a7b4aa08b9b4f5f857ad652d6f3f90eec076b Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 14 Apr 2011 10:33:50 +0100 Subject: Match title now that it has newlines in it --- t/app/controller/about.t | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/about.t b/t/app/controller/about.t index aeca47d86..a086be98d 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -8,19 +8,19 @@ ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); # check that we can get the page $mech->get_ok('/about'); -$mech->content_contains('About Us :: FixMyStreet.com'); +$mech->content_like(qr{About Us ::\s+FixMyStreet.com}); $mech->content_contains('html lang="en-gb"'); # check that geting the page as EHA produces a different page ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; $mech->get_ok('/about'); -$mech->content_contains('About us :: Report Empty Homes'); +$mech->content_like(qr{About us ::\s+Report Empty Homes}); $mech->content_contains('html lang="en-gb"'); # check that geting the page as EHA in welsh produces a different page ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes'; $mech->get_ok('/about'); -$mech->content_contains('Amdanom ni :: Adrodd am Eiddo Gwag'); +$mech->content_like(qr{Amdanom ni ::\s+Adrodd am Eiddo Gwag}); $mech->content_contains('html lang="cy"'); done_testing(); -- cgit v1.2.3 From 1031d78748f88c57d78fb79cb6771ab698b7d284 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 14 Apr 2011 11:38:25 +0100 Subject: Fim report creation tests --- t/app/controller/report_new.t | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 1310a3e35..e9dae0da5 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -8,10 +8,19 @@ use Web::Scraper; my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/report/new'); -fail "test that lat,lon not covered by council goes to '/around'"; - fail "test that partial code is transferred"; +subtest "test that bare requests to /report/new get redirected" => sub { + + $mech->get_ok('/report/new'); + is $mech->uri->path, '/around', "went to /around"; + is_deeply { $mech->uri->query_form }, {}, "query empty"; + + $mech->get_ok('/report/new?pc=SW1A%201AA'); + is $mech->uri->path, '/around', "went to /around"; + is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' }, + "pc correctly transferred"; +}; # test that the various bit of form get filled in and errors correctly # generated. @@ -203,13 +212,17 @@ foreach my $test ( ) { subtest "check form errors where $test->{msg}" => sub { - $mech->get_ok('/report/new'); + $mech->get_ok('/around'); # submit initial pc form $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "submit location" ); is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); + # submit the main form $mech->submit_form_ok( { with_fields => $test->{fields} }, "submit form" ); @@ -237,9 +250,14 @@ subtest "test report creation for a user who does not have an account" => sub { "test user does not exist"; # submit initial pc form - $mech->get_ok('/report/new'); + $mech->get_ok('/around'); $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); + $mech->submit_form_ok( { with_fields => { @@ -323,10 +341,14 @@ subtest "test report creation for a user who is logged in" => sub { "set users details"; # submit initial pc form - $mech->get_ok('/report/new'); + $mech->get_ok('/around'); $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, "submit location" ); + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); + # check that the fields are correctly prefilled is_deeply( $mech->visible_form_values, @@ -395,4 +417,25 @@ subtest "test report creation for a user who is logged in" => sub { # create report by clicking on may with javascript off # create report with images off +subtest "check that a lat/lon off coast leads to /around" => sub { + my $off_coast_latitude = 50.78301; + my $off_coast_longitude = -0.646929; + + $mech->get_ok( # + "/report/new" + . "?latitude=$off_coast_latitude" + . "&longitude=$off_coast_longitude" + ); + + is $mech->uri->path, '/around', "redirected to '/around'"; + + is_deeply # + $mech->page_errors, + [ 'That spot does not appear to be covered by a council. If you have' + . ' tried to report an issue past the shoreline, for example, please' + . ' specify the closest point on land.' ], # + "Found location error"; + +}; + done_testing(); -- cgit v1.2.3 From 0cc37c30af2ab2826b376cc1406f6a79dd0f46fd Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 14 Apr 2011 12:47:40 +0100 Subject: Corrected tests and docs. Still need to fix code. --- t/app/controller/report_import.t | 90 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 764357b57..25f5dddf9 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -101,12 +101,13 @@ subtest "Submit a correct entry" => sub { # go to the token url $mech->get_ok($token_url); + # check that we are on '/around' + is $mech->uri->path, '/around', "sent to /around"; + # check that we are not shown anything as we don't have a location yet is_deeply $mech->visible_form_values, { pc => '' }, "check only pc field is shown"; - is $mech->uri->path, '/around', "sent to report page"; - $mech->submit_form_ok( # { with_fields => { pc => 'SW1A 1AA' } }, "fill in postcode" @@ -159,4 +160,89 @@ subtest "Submit a correct entry" => sub { $mech->delete_user($user); }; +# submit an empty report to import - check we get all errors +subtest "Submit a correct entry (with location)" => sub { + + $mech->get_ok('/import'); + + $mech->submit_form_ok( # + { + with_fields => { + service => 'test-script', + latitude => '51.5010096115539', # SW1A 1AA + longitude => '-0.141587067110009', + latitude => '', + longitude => '', + name => 'Test User ll', + email => 'test-ll@example.com', + subject => 'Test report ll', + detail => 'This is a test report ll', + photo => $sample_file, + } + }, + "fill in form" + ); + + is_deeply( $mech->import_errors, [], "got no errors" ); + is $mech->content, 'SUCCESS', "Got success response"; + + # check that we have received the email + $mech->email_count_is(1); + my $email = $mech->get_email; + $mech->clear_emails_ok; + + my ($token_url) = $email->body =~ m{(http://\S+)}; + ok $token_url, "Found a token url $token_url"; + + # go to the token url + $mech->get_ok($token_url); + + # check that we are on '/around' + is $mech->uri->path, '/report/new', "sent to /around"; + + # check that fields are prefilled for us + is_deeply $mech->visible_form_values, + { + name => 'Test User ll', + email => 'test-ll@example.com', + title => 'Test report ll', + detail => 'This is a test report ll', + photo => '', + phone => '', + may_show_name => '1', + }, + "check imported fields are shown"; + + TODO: { + local $TODO = "'/report/123' urls not served by catalyst yet"; + + # change the details + $mech->submit_form_ok( # + { + with_fields => { + name => 'New Test User', + email => 'test@example.com', + title => 'New Test report', + detail => 'This is a test report', + phone => '01234 567 890', + may_show_name => '1', + } + }, + "Update details and save" + ); + } + + # check that report has been created + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test-ll@example.com' } ); + ok $user, "Found a user"; + + my $report = $user->problems->first; + is $report->state, 'confirmed', 'is confirmed'; + is $report->title, 'New Test report ll', 'title is correct'; + + $mech->delete_user($user); +}; + done_testing(); -- cgit v1.2.3 From db605d2095fc8ada23447e93c168f375d6f44738 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 14 Apr 2011 13:05:38 +0100 Subject: fixes to import --- t/app/controller/report_import.t | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 25f5dddf9..5bd0b21b8 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -168,16 +168,14 @@ subtest "Submit a correct entry (with location)" => sub { $mech->submit_form_ok( # { with_fields => { - service => 'test-script', - latitude => '51.5010096115539', # SW1A 1AA - longitude => '-0.141587067110009', - latitude => '', - longitude => '', - name => 'Test User ll', - email => 'test-ll@example.com', - subject => 'Test report ll', - detail => 'This is a test report ll', - photo => $sample_file, + service => 'test-script', + lat => '51.5010096115539', # SW1A 1AA + lon => '-0.141587067110009', + name => 'Test User ll', + email => 'test-ll@example.com', + subject => 'Test report ll', + detail => 'This is a test report ll', + photo => $sample_file, } }, "fill in form" @@ -220,10 +218,10 @@ subtest "Submit a correct entry (with location)" => sub { $mech->submit_form_ok( # { with_fields => { - name => 'New Test User', - email => 'test@example.com', - title => 'New Test report', - detail => 'This is a test report', + name => 'New Test User ll', + email => 'test-ll@example.com', + title => 'New Test report ll', + detail => 'This is a test report ll', phone => '01234 567 890', may_show_name => '1', } -- cgit v1.2.3 From aefe47ffe17ce5c727380ef8e5e20fbdd19ed281 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 14 Apr 2011 14:31:54 +0100 Subject: Take out test placeholder --- t/app/controller/report_new.t | 2 -- 1 file changed, 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index e9dae0da5..16e8e6445 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -8,8 +8,6 @@ use Web::Scraper; my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/report/new'); -fail "test that partial code is transferred"; - subtest "test that bare requests to /report/new get redirected" => sub { $mech->get_ok('/report/new'); -- cgit v1.2.3 From bf017708ac209924a98c594dcb5b8614b28e0d32 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Thu, 14 Apr 2011 15:50:51 +0100 Subject: Added Tilma proxy for dev server --- t/app/controller/tilma.t | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 t/app/controller/tilma.t (limited to 't/app/controller') diff --git a/t/app/controller/tilma.t b/t/app/controller/tilma.t new file mode 100644 index 000000000..0eb0b251e --- /dev/null +++ b/t/app/controller/tilma.t @@ -0,0 +1,12 @@ +use strict; +use warnings; + +use Test::More; +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +$mech->get_ok('/tilma/tileserver/10k-full/3278-3283,1110-1115/JSON'); +is $mech->res->content_type, 'text/javascript', "got JS response"; + +done_testing(); \ No newline at end of file -- 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') 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 From 3f61e32c2530dedc8069bd8d1290d590434a44ea Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 15 Apr 2011 16:40:47 +0100 Subject: Prep to port '/report/123' page --- t/app/controller/report_display.t | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 t/app/controller/report_display.t (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From f95ec28737b06671b58eaa89ae752d78b03f2a87 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 15 Apr 2011 17:28:10 +0100 Subject: Test and implement bad requests --- t/app/controller/report_display.t | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index e69de29bb..888e5e5b9 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -0,0 +1,75 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +use Web::Scraper; +use Path::Class; + +my $mech = FixMyStreet::TestMech->new; + +# create a test user and report +$mech->delete_user('test@example.com'); +my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); +ok $user, "created test user"; + +my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'SW1A 1AA', + council => '2504', + areas => ',105255,11806,11828,2247,2504,', + category => 'Other', + title => 'Test 2', + detail => 'Test 2', + used_map => 't', + name => 'Test User', + anonymous => 'f', + state => 'confirmed', + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '51.5016605453401', + longitude => '-0.142497580865087', + user_id => $user->id, + } +); +my $report_id = $report->id; +ok $report, "created test report - $report_id"; + +subtest "check that no id redirects to homepage" => sub { + $mech->get_ok('/report'); + is $mech->uri->path, '/', "at home page"; +}; + +subtest "test id=NNN redirects to /NNN" => sub { + $mech->get_ok("/report?id=$report_id"); + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; +}; + +subtest "test bad council email clients web links" => sub { + $mech->get_ok("/report/3D$report_id"); + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; +}; + +subtest "test bad ids get dealt with (404)" => sub { + foreach my $id ( 'XXX', 99999999 ) { + ok $mech->get("/report/$id"), "get '/report/$id'"; + is $mech->res->code, 404, "page not found"; + is $mech->uri->path, "/report/$id", "at /report/$id"; + } +}; + +subtest "test a good report" => sub { + $mech->get_ok("/report/$report_id"); + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; +}; + +fail "change report to hidden and check for 400 status"; + +# tidy up +$mech->delete_user('test@example.com'); +done_testing(); -- cgit v1.2.3 From bd8134a37058a5d8e562bc04bfec16fdb4a19446 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 15 Apr 2011 17:36:04 +0100 Subject: test for proper 404 page --- t/app/controller/report_display.t | 1 + 1 file changed, 1 insertion(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 888e5e5b9..24a62b958 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -60,6 +60,7 @@ subtest "test bad ids get dealt with (404)" => sub { ok $mech->get("/report/$id"), "get '/report/$id'"; is $mech->res->code, 404, "page not found"; is $mech->uri->path, "/report/$id", "at /report/$id"; + $mech->content_contains('Unknown problem ID'); } }; -- cgit v1.2.3 From 898d7c6f5f4c38ca2dd19df5c8a80ee222820130 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 15 Apr 2011 17:40:07 +0100 Subject: rename 404 error to be clearer --- t/app/controller/page_not_found.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/page_not_found.t b/t/app/controller/page_not_found.t index 9c8d7e5a6..05e983109 100644 --- a/t/app/controller/page_not_found.t +++ b/t/app/controller/page_not_found.t @@ -13,7 +13,7 @@ my $mech = Test::WWW::Mechanize::Catalyst->new; $mech->get_ok('/'); # get 404 page -my $path_to_404 = '/bad/path/page_not_found'; +my $path_to_404 = '/bad/path/page_error_404_not_found'; my $res = $mech->get($path_to_404); ok !$res->is_success(), "want a bad response"; is $res->code, 404, "got 404"; -- cgit v1.2.3 From 8cdbfa9706eb1e69f4e975646fcde99dd41a9064 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 15 Apr 2011 17:49:58 +0100 Subject: Show 410 page for hidden reports, and 404 for ones that are not confirmed yet. --- t/app/controller/report_display.t | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 24a62b958..f979cc4ed 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -64,13 +64,29 @@ subtest "test bad ids get dealt with (404)" => sub { } }; +subtest "change report to unconfirmed and check for 404 status" => sub { + ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report'; + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->res->code, 404, "page not found"; + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + $mech->content_contains('Unknown problem ID'); + ok $report->update( { state => 'confirmed' } ), 'confirm report again'; +}; + +subtest "change report to hidden and check for 410 status" => sub { + ok $report->update( { state => 'hidden' } ), 'hide report'; + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->res->code, 410, "page gone"; + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + $mech->content_contains('That report has been removed from FixMyStreet.'); + ok $report->update( { state => 'confirmed' } ), 'confirm report again'; +}; + subtest "test a good report" => sub { $mech->get_ok("/report/$report_id"); is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; }; -fail "change report to hidden and check for 400 status"; - # tidy up $mech->delete_user('test@example.com'); done_testing(); -- cgit v1.2.3 From 7b423553479055afebbe408d05dc616ca980a29f Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 15 Apr 2011 18:07:32 +0100 Subject: deal with trailing garbage on url --- t/app/controller/report_display.t | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index f979cc4ed..f0f1bdcba 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -55,6 +55,11 @@ subtest "test bad council email clients web links" => sub { is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; }; +subtest "test tailing non-ints get stripped" => sub { + $mech->get_ok("/report/${report_id}xx "); + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; +}; + subtest "test bad ids get dealt with (404)" => sub { foreach my $id ( 'XXX', 99999999 ) { ok $mech->get("/report/$id"), "get '/report/$id'"; -- cgit v1.2.3 From 3903fa098c3acd275cbabe2c309cf38e64bd88e5 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Tue, 3 May 2011 13:54:07 +0100 Subject: CHeck that 'emptyhomes' cobrand is available before using it in tests --- t/app/controller/about.t | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/about.t b/t/app/controller/about.t index a086be98d..e1a1641fd 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -11,16 +11,21 @@ $mech->get_ok('/about'); $mech->content_like(qr{About Us ::\s+FixMyStreet.com}); $mech->content_contains('html lang="en-gb"'); -# check that geting the page as EHA produces a different page -ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; -$mech->get_ok('/about'); -$mech->content_like(qr{About us ::\s+Report Empty Homes}); -$mech->content_contains('html lang="en-gb"'); +SKIP: { + skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 8 ) + unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{emptyhomes}; -# check that geting the page as EHA in welsh produces a different page -ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes'; -$mech->get_ok('/about'); -$mech->content_like(qr{Amdanom ni ::\s+Adrodd am Eiddo Gwag}); -$mech->content_contains('html lang="cy"'); + # check that geting the page as EHA produces a different page + ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; + $mech->get_ok('/about'); + $mech->content_like(qr{About us ::\s+Report Empty Homes}); + $mech->content_contains('html lang="en-gb"'); + + # check that geting the page as EHA in welsh produces a different page + ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes'; + $mech->get_ok('/about'); + $mech->content_like(qr{Amdanom ni ::\s+Adrodd am Eiddo Gwag}); + $mech->content_contains('html lang="cy"'); +} done_testing(); -- cgit v1.2.3 From fb8ddac45d81e40daee88aab963ac09423762e76 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 13:49:43 +0100 Subject: Skeleton catalyst alerts page --- t/app/controller/alert.t | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 t/app/controller/alert.t (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t new file mode 100644 index 000000000..77ed63ea7 --- /dev/null +++ b/t/app/controller/alert.t @@ -0,0 +1,16 @@ +use strict; +use warnings; +use Test::More; + + +use Catalyst::Test 'FixMyStreet::App'; +use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; + +ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); + +# check that we can get the page +$mech->get_ok('/alert'); +$mech->content_contains('Local RSS feeds and email alerts'); +$mech->content_contains('html lang="en-gb"'); + +done_testing(); -- cgit v1.2.3 From b55733c9614b2f8ebd09d31f3c2750959942effa Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 18:49:39 +0100 Subject: add in prettyfication of postcode --- t/app/controller/alert.t | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 77ed63ea7..4f5ee818c 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -13,4 +13,13 @@ $mech->get_ok('/alert'); $mech->content_contains('Local RSS feeds and email alerts'); $mech->content_contains('html lang="en-gb"'); +# check that we can get list page +$mech->get_ok('/alert/list'); +$mech->content_contains('Local RSS feeds and email alerts'); +$mech->content_contains('html lang="en-gb"'); + +$mech->get_ok('/alert/list?pc=ZZ99ZY'); +$mech->content_contains('RSS feeds and email alerts for ZZ9 9ZY'); +$mech->content_contains('html lang="en-gb"'); + done_testing(); -- cgit v1.2.3 From 5adb3f33342dda3d2a904c8dda2a4281366094c3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 19:07:11 +0100 Subject: test that we are getting the titles right as well --- t/app/controller/alert.t | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 4f5ee818c..d644c4f78 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -10,16 +10,19 @@ ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); # check that we can get the page $mech->get_ok('/alert'); +$mech->title_like(qr/^Local RSS feeds and email alerts/); $mech->content_contains('Local RSS feeds and email alerts'); $mech->content_contains('html lang="en-gb"'); # check that we can get list page $mech->get_ok('/alert/list'); +$mech->title_like(qr/^Local RSS feeds and email alerts/); $mech->content_contains('Local RSS feeds and email alerts'); $mech->content_contains('html lang="en-gb"'); $mech->get_ok('/alert/list?pc=ZZ99ZY'); -$mech->content_contains('RSS feeds and email alerts for ZZ9 9ZY'); +$mech->title_like(qr/^Local RSS feeds and email alerts for ZZ9 9ZY/); +$mech->content_contains('Local RSS feeds and email alerts for ZZ9 9ZY'); $mech->content_contains('html lang="en-gb"'); done_testing(); -- cgit v1.2.3 From c245810f3b2549dfeded4511cd4ec1b13e5bdfd3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 5 May 2011 14:13:40 +0100 Subject: do not put postcode in alert page title --- t/app/controller/alert.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index d644c4f78..25feaf20d 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -21,7 +21,7 @@ $mech->content_contains('Local RSS feeds and email alerts'); $mech->content_contains('html lang="en-gb"'); $mech->get_ok('/alert/list?pc=ZZ99ZY'); -$mech->title_like(qr/^Local RSS feeds and email alerts for ZZ9 9ZY/); +$mech->title_like(qr/^Local RSS feeds and email alerts/); $mech->content_contains('Local RSS feeds and email alerts for ZZ9 9ZY'); $mech->content_contains('html lang="en-gb"'); -- cgit v1.2.3 From ce6b34aa866e246fae2aadc9308a27638d8eccb3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 5 May 2011 17:10:54 +0100 Subject: display choices for ambigious location searches --- t/app/controller/alert.t | 2 ++ 1 file changed, 2 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 25feaf20d..80037fafe 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -25,4 +25,6 @@ $mech->title_like(qr/^Local RSS feeds and email alerts/); $mech->content_contains('Local RSS feeds and email alerts for ZZ9 9ZY'); $mech->content_contains('html lang="en-gb"'); +$mech->get_ok('/alert/list?pc=High Street'); +$mech->content_contains('We found more than one match for that location'); done_testing(); -- cgit v1.2.3 From aaf60ba622748d8f5a5c4eb16fe663ff9fec5a0d Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 6 May 2011 11:24:28 +0100 Subject: created council controller and use that for load and check councils --- t/app/controller/alert.t | 7 +++++-- t/app/controller/council.t | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 t/app/controller/council.t (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 80037fafe..31b5fb3cf 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -20,11 +20,14 @@ $mech->title_like(qr/^Local RSS feeds and email alerts/); $mech->content_contains('Local RSS feeds and email alerts'); $mech->content_contains('html lang="en-gb"'); -$mech->get_ok('/alert/list?pc=ZZ99ZY'); +$mech->get_ok('/alert/list?pc=EH99 1SP'); $mech->title_like(qr/^Local RSS feeds and email alerts/); -$mech->content_contains('Local RSS feeds and email alerts for ZZ9 9ZY'); +$mech->content_contains('Local RSS feeds and email alerts for EH99 1SP'); $mech->content_contains('html lang="en-gb"'); $mech->get_ok('/alert/list?pc=High Street'); $mech->content_contains('We found more than one match for that location'); + +$mech->get_ok('/alert/list?pc='); +$mech->content_contains('hat location does not appear to be covered by a council'); done_testing(); diff --git a/t/app/controller/council.t b/t/app/controller/council.t new file mode 100644 index 000000000..d01b3ccd7 --- /dev/null +++ b/t/app/controller/council.t @@ -0,0 +1,9 @@ +use strict; +use warnings; +use Test::More; + + +use Catalyst::Test 'FixMyStreet::App'; +use FixMyStreet::App::Controller::Council; + +done_testing(); -- cgit v1.2.3 From b1ca5c65e80f340c9e0bd6ee7bd6ab667073389b Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 6 May 2011 17:17:54 +0100 Subject: added in rss feed links --- t/app/controller/alert.t | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 31b5fb3cf..ceb1a3554 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -24,6 +24,11 @@ $mech->get_ok('/alert/list?pc=EH99 1SP'); $mech->title_like(qr/^Local RSS feeds and email alerts/); $mech->content_contains('Local RSS feeds and email alerts for EH99 1SP'); $mech->content_contains('html lang="en-gb"'); +$mech->content_contains('Problems within 8.5km'); +$mech->content_contains('rss/pc/EH991SP/2'); +$mech->content_contains('rss/pc/EH991SP/5'); +$mech->content_contains('rss/pc/EH991SP/10'); +$mech->content_contains('rss/pc/EH991SP/20'); $mech->get_ok('/alert/list?pc=High Street'); $mech->content_contains('We found more than one match for that location'); -- cgit v1.2.3 From d01b9bc2e42e46d5415a5464eb2ee063f43a8464 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 9 May 2011 12:49:18 +0100 Subject: rss feeds for single tier councils --- t/app/controller/alert.t | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index ceb1a3554..9b10070b2 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -29,10 +29,19 @@ $mech->content_contains('rss/pc/EH991SP/2'); $mech->content_contains('rss/pc/EH991SP/5'); $mech->content_contains('rss/pc/EH991SP/10'); $mech->content_contains('rss/pc/EH991SP/20'); +$mech->content_contains('Problems within City of Edinburgh'); +$mech->content_contains('Problems within City Centre ward'); +$mech->content_contains('/rss/reports/City+of+Edinburgh'); +$mech->content_contains('/rss/reports/City+of+Edinburgh/City+Centre'); +$mech->content_contains('council:2651:City_of_Edinburgh'); +$mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre'); $mech->get_ok('/alert/list?pc=High Street'); $mech->content_contains('We found more than one match for that location'); $mech->get_ok('/alert/list?pc='); $mech->content_contains('hat location does not appear to be covered by a council'); + +$mech->get_ok('/alert/list?pc=GL502PR'); +$mech->content_contains('Problems within the boundary of'); done_testing(); -- cgit v1.2.3 From 6ff9e651989a835c996635bf502723a4701ed483 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 10:55:42 +0100 Subject: Add in RSS redirects --- t/app/controller/alert.t | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 9b10070b2..f3b705650 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -44,4 +44,27 @@ $mech->content_contains('hat location does not appear to be covered by a council $mech->get_ok('/alert/list?pc=GL502PR'); $mech->content_contains('Problems within the boundary of'); + +$mech->get_ok('/alert/rss?type=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy=' ); +$mech->content_contains('Please select the feed you want'); + +$mech->get_ok('/alert/rss?feed=invalid:1000:A_Locationtype=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy='); +$mech->content_contains('Illegal feed selection'); + +TODO: { + local $TODO = 'not implemented rss feeds yet'; + + $mech->get_ok('/alert/rss?feed=area:1000:A_Location'); + $mech->uri->path('/rss/area/A+Location'); + + $mech->get_ok('/alert/rss?feed=area:1000:1001:A_Location:Diff_Location'); + $mech->uri->path('/rss/area/A+Location/Diff+Location'); + + $mech->get_ok('/alert/rss?feed=council:1000:A_Location'); + $mech->uri->path('/rss/reports/A+Location'); + + $mech->get_ok('/alert/rss?feed=ward:1000:1001:A_Location:Diff_Location'); + $mech->uri->path('/rss/ward/A+Location/Diff+Location'); +} + done_testing(); -- cgit v1.2.3 From 7011ca98493656f98433d644ffa922c8b3720adc Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 11:56:07 +0100 Subject: add subscribe target and get to rss through that instead --- t/app/controller/alert.t | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index f3b705650..2f25a1c23 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -45,25 +45,25 @@ $mech->content_contains('hat location does not appear to be covered by a council $mech->get_ok('/alert/list?pc=GL502PR'); $mech->content_contains('Problems within the boundary of'); -$mech->get_ok('/alert/rss?type=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy=' ); +$mech->get_ok('/alert/subscribe?rss=1&type=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy=' ); $mech->content_contains('Please select the feed you want'); -$mech->get_ok('/alert/rss?feed=invalid:1000:A_Locationtype=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy='); +$mech->get_ok('/alert/subscribe?rss=1&feed=invalid:1000:A_Locationtype=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy='); $mech->content_contains('Illegal feed selection'); TODO: { local $TODO = 'not implemented rss feeds yet'; - $mech->get_ok('/alert/rss?feed=area:1000:A_Location'); + $mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:A_Location'); $mech->uri->path('/rss/area/A+Location'); - $mech->get_ok('/alert/rss?feed=area:1000:1001:A_Location:Diff_Location'); + $mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:1001:A_Location:Diff_Location'); $mech->uri->path('/rss/area/A+Location/Diff+Location'); - $mech->get_ok('/alert/rss?feed=council:1000:A_Location'); + $mech->get_ok('/alert/subscribe?rss=1&feed=council:1000:A_Location'); $mech->uri->path('/rss/reports/A+Location'); - $mech->get_ok('/alert/rss?feed=ward:1000:1001:A_Location:Diff_Location'); + $mech->get_ok('/alert/subscribe?rss=1&feed=ward:1000:1001:A_Location:Diff_Location'); $mech->uri->path('/rss/ward/A+Location/Diff+Location'); } -- cgit v1.2.3 From a1fa6aa37ce73e2a637e4bac565cd0a199f551e2 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 16:16:02 +0100 Subject: local alert email signup --- t/app/controller/alert_new.t | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 t/app/controller/alert_new.t (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t new file mode 100644 index 000000000..3d1bfeabf --- /dev/null +++ b/t/app/controller/alert_new.t @@ -0,0 +1,83 @@ +use strict; +use warnings; +use Test::More; + + +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +foreach my $test ( + { + email => 'test@example.com', + type => 'area', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + uri => + '/alert/subscribe?type=local&rznvy=test@example.com&feed=area:1000:A_Location', + param1 => 1000 + }, + { + email => 'test@example.com', + type => 'council', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + uri => + '/alert/subscribe?type=local&rznvy=test@example.com&feed=council:1000:A_Location', + param1 => 1000, + param2 => 1000, + }, + { + email => 'test@example.com', + type => 'ward', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + uri => + '/alert/subscribe?type=local&rznvy=test@example.com&feed=ward:1000:1001:A_Location:Diff_Location', + param1 => 1000, + param2 => 1001, + }, + { + email => 'test@example.com', + type => 'local', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + uri => + '/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1', + param1 => 10.2, + param2 => 20.1, + } +) { + subtest "$test->{type} alert correctly created" => sub { + $mech->clear_emails_ok; + + my $type = $test->{type} . '_problems'; + + # we don't want an alert + my $alert = FixMyStreet::App->model('DB::Alert')->find( { email => + $test->{email}, alert_type => $type } ); + $alert->delete() if $alert; + + $mech->get_ok($test->{uri}); + $mech->content_contains($test->{content}); + + $alert = FixMyStreet::App->model('DB::Alert')->find( { email => + $test->{email}, alert_type => $type, parameter => + $test->{param1}, parameter2 => $test->{param2} } ); + + ok $alert, "Found the alert"; + + SKIP: { + skip 'sending email not yet implemented', 4; + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/$test->{email_text}/i, "Correct email text"; + + my ($url) = $email->body =~ m{(http://\S+)}; + ok $url, "extracted confirm url '$url'"; + }; + }; +} + +done_testing(); -- cgit v1.2.3 From 00177a5cd2ebbfeb08082712c1a1c392276c4a83 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 17:23:20 +0100 Subject: send out alert subscription email confirmations --- t/app/controller/alert_new.t | 96 +++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 41 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 3d1bfeabf..72467d31c 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -2,82 +2,96 @@ use strict; use warnings; use Test::More; - use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -foreach my $test ( +foreach my $test ( { - email => 'test@example.com', - type => 'area', - content => 'your alert will not be activated', + email => 'test@example.com', + type => 'area', + content => 'your alert will not be activated', email_text => 'confirm the alert', - uri => - '/alert/subscribe?type=local&rznvy=test@example.com&feed=area:1000:A_Location', + uri => +'/alert/subscribe?type=local&rznvy=test@example.com&feed=area:1000:A_Location', param1 => 1000 }, { - email => 'test@example.com', - type => 'council', - content => 'your alert will not be activated', + email => 'test@example.com', + type => 'council', + content => 'your alert will not be activated', email_text => 'confirm the alert', - uri => - '/alert/subscribe?type=local&rznvy=test@example.com&feed=council:1000:A_Location', + uri => +'/alert/subscribe?type=local&rznvy=test@example.com&feed=council:1000:A_Location', param1 => 1000, param2 => 1000, }, { - email => 'test@example.com', - type => 'ward', - content => 'your alert will not be activated', + email => 'test@example.com', + type => 'ward', + content => 'your alert will not be activated', email_text => 'confirm the alert', - uri => - '/alert/subscribe?type=local&rznvy=test@example.com&feed=ward:1000:1001:A_Location:Diff_Location', + uri => +'/alert/subscribe?type=local&rznvy=test@example.com&feed=ward:1000:1001:A_Location:Diff_Location', param1 => 1000, param2 => 1001, }, { - email => 'test@example.com', - type => 'local', - content => 'your alert will not be activated', + email => 'test@example.com', + type => 'local', + content => 'your alert will not be activated', email_text => 'confirm the alert', - uri => - '/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1', + uri => +'/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1', param1 => 10.2, param2 => 20.1, } -) { - subtest "$test->{type} alert correctly created" => sub { - $mech->clear_emails_ok; - - my $type = $test->{type} . '_problems'; + ) +{ + subtest "$test->{type} alert correctly created" => sub { + $mech->clear_emails_ok; - # we don't want an alert - my $alert = FixMyStreet::App->model('DB::Alert')->find( { email => - $test->{email}, alert_type => $type } ); - $alert->delete() if $alert; + my $type = $test->{type} . '_problems'; - $mech->get_ok($test->{uri}); - $mech->content_contains($test->{content}); + # we don't want an alert + my $alert = FixMyStreet::App->model('DB::Alert')->find( + { + email => $test->{email}, + alert_type => $type + } + ); + $alert->delete() if $alert; - $alert = FixMyStreet::App->model('DB::Alert')->find( { email => - $test->{email}, alert_type => $type, parameter => - $test->{param1}, parameter2 => $test->{param2} } ); + $mech->get_ok( $test->{uri} ); + $mech->content_contains( $test->{content} ); - ok $alert, "Found the alert"; + $alert = FixMyStreet::App->model('DB::Alert')->find( + { + email => $test->{email}, + alert_type => $type, + parameter => $test->{param1}, + parameter2 => $test->{param2} + } + ); - SKIP: { - skip 'sending email not yet implemented', 4; + ok $alert, "Found the alert"; my $email = $mech->get_email; ok $email, "got an email"; like $email->body, qr/$test->{email_text}/i, "Correct email text"; - my ($url) = $email->body =~ m{(http://\S+)}; + my ( $url, $url_token ) = $email->body =~ m{(http://\S+/A/)(\S+)}; ok $url, "extracted confirm url '$url'"; + + my $token = FixMyStreet::App->model('DB::Token')->find( + { + token => $url_token, + scope => 'alert' + } + ); + ok $token, 'Token found in database'; + ok $alert->id == $token->data->{id}, 'token alertid matches alert id'; }; - }; } done_testing(); -- cgit v1.2.3 From 0a38fbfb7d21e0e9c79a747b17c7f4058c791e06 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 17:32:58 +0100 Subject: test that we do not duplicate existing alerts --- t/app/controller/alert_new.t | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 72467d31c..8ee9d071b 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -91,6 +91,29 @@ foreach my $test ( ); ok $token, 'Token found in database'; ok $alert->id == $token->data->{id}, 'token alertid matches alert id'; + + $mech->clear_emails_ok; + + my $existing_id = $alert->id; + my $existing_token = $url_token; + + $mech->get_ok( $test->{uri} ); + + $email = $mech->get_email; + ok $email, 'got a second email'; + + ($url_token) = $email->body =~ m{http://\S+/A/(\S+)}; + ok $url_token ne $existing_token, 'sent out a new token'; + + $token = FixMyStreet::App->model('DB::Token')->find( + { + token => $url_token, + scope => 'alert' + } + ); + + ok $token, 'new token found in database'; + ok $token->data->{id} == $existing_id, 'subscribed to exsiting alert'; }; } -- cgit v1.2.3 From 5f1db7700255e00ce492d57939f861f76b6ddadf Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 May 2011 11:37:36 +0100 Subject: confirm alert subscription --- t/app/controller/alert_new.t | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 8ee9d071b..94a4229ff 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -70,7 +70,8 @@ foreach my $test ( email => $test->{email}, alert_type => $type, parameter => $test->{param1}, - parameter2 => $test->{param2} + parameter2 => $test->{param2}, + confirmed => 0, } ); @@ -114,6 +115,14 @@ foreach my $test ( ok $token, 'new token found in database'; ok $token->data->{id} == $existing_id, 'subscribed to exsiting alert'; + + $mech->get_ok("/A/$url_token"); + $mech->content_contains('subscribed'); + + $alert = + FixMyStreet::App->model('DB::Alert')->find( { id => $existing_id, } ); + + ok $alert->confirmed, 'alert set to confirmed'; }; } -- cgit v1.2.3 From c3adef1dea602a181521f2bc0848ec47d67198d0 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 May 2011 14:55:39 +0100 Subject: moving alerts to use users instead of email in table --- t/app/controller/alert_new.t | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 94a4229ff..0b4cacfdc 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -53,21 +53,38 @@ foreach my $test ( my $type = $test->{type} . '_problems'; - # we don't want an alert - my $alert = FixMyStreet::App->model('DB::Alert')->find( + my $user = FixMyStreet::App->model('DB::User')->find( { - email => $test->{email}, - alert_type => $type + email => $test->{email} } ); + + # we don't want an alert + my $alert; + if ( $user ) { + $alert = FixMyStreet::App->model('DB::Alert')->find( + { + user => $user, + alert_type => $type + } + ); + } $alert->delete() if $alert; $mech->get_ok( $test->{uri} ); $mech->content_contains( $test->{content} ); + $user = FixMyStreet::App->model('DB::User')->find( + { + email => $test->{email} + } + ); + + ok $user, 'user for report'; + $alert = FixMyStreet::App->model('DB::Alert')->find( { - email => $test->{email}, + user => $user, alert_type => $type, parameter => $test->{param1}, parameter2 => $test->{param2}, @@ -117,7 +134,7 @@ foreach my $test ( ok $token->data->{id} == $existing_id, 'subscribed to exsiting alert'; $mech->get_ok("/A/$url_token"); - $mech->content_contains('subscribed'); + $mech->content_contains('successfully confirmed'); $alert = FixMyStreet::App->model('DB::Alert')->find( { id => $existing_id, } ); -- cgit v1.2.3 From 148d4edd7689f6df3b56678f6c9eb620cc219cd6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 May 2011 15:46:34 +0100 Subject: tests for reusing existing users when creating an alert --- t/app/controller/alert_new.t | 59 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 8 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 0b4cacfdc..bc4b11230 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -62,14 +62,8 @@ foreach my $test ( # we don't want an alert my $alert; if ( $user ) { - $alert = FixMyStreet::App->model('DB::Alert')->find( - { - user => $user, - alert_type => $type - } - ); + $mech->delete_user( $user ); } - $alert->delete() if $alert; $mech->get_ok( $test->{uri} ); $mech->content_contains( $test->{content} ); @@ -80,7 +74,7 @@ foreach my $test ( } ); - ok $user, 'user for report'; + ok $user, 'user created for alert'; $alert = FixMyStreet::App->model('DB::Alert')->find( { @@ -143,4 +137,53 @@ foreach my $test ( }; } +foreach my $test ( + { + email => 'test-new@example.com', + type => 'area', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + uri => +'/alert/subscribe?type=local&rznvy=test-new@example.com&feed=area:1000:A_Location', + param1 => 1000 + } +) { + subtest "use existing user in a alert" => sub { + my $type = $test->{type} . '_problems'; + + my $user = FixMyStreet::App->model('DB::User')->find_or_create( + { + email => $test->{email} + } + ); + + my $alert; + if ( $user ) { + $alert = FixMyStreet::App->model('DB::Alert')->find( + { + user => $user, + alert_type => $type + } + ); + + # clear existing data so we can be sure we're creating it + $alert->delete() if $alert; + } + + $mech->get_ok( $test->{uri} ); + + $alert = FixMyStreet::App->model('DB::Alert')->find( + { + user => $user, + alert_type => $type, + parameter => $test->{param1}, + parameter2 => $test->{param2}, + confirmed => 0, + } + ); + + ok $alert, 'New alert created with existing user'; + }; +} + done_testing(); -- cgit v1.2.3 From 6cd84f2e112b0f388266d6c64b634f31bafb264d Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 May 2011 16:48:51 +0100 Subject: Automatically fill in email address of logged in user --- t/app/controller/alert_new.t | 85 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 17 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index bc4b11230..c44d14a30 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -53,26 +53,22 @@ foreach my $test ( my $type = $test->{type} . '_problems'; - my $user = FixMyStreet::App->model('DB::User')->find( - { - email => $test->{email} - } - ); + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => $test->{email} } ); # we don't want an alert my $alert; - if ( $user ) { - $mech->delete_user( $user ); + if ($user) { + $mech->delete_user($user); } $mech->get_ok( $test->{uri} ); $mech->content_contains( $test->{content} ); - $user = FixMyStreet::App->model('DB::User')->find( - { - email => $test->{email} - } - ); + $user = + FixMyStreet::App->model('DB::User') + ->find( { email => $test->{email} } ); ok $user, 'user created for alert'; @@ -147,18 +143,66 @@ foreach my $test ( '/alert/subscribe?type=local&rznvy=test-new@example.com&feed=area:1000:A_Location', param1 => 1000 } -) { + ) +{ subtest "use existing user in a alert" => sub { my $type = $test->{type} . '_problems'; - my $user = FixMyStreet::App->model('DB::User')->find_or_create( + my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => $test->{email} } ); + + my $alert; + if ($user) { + $alert = FixMyStreet::App->model('DB::Alert')->find( + { + user => $user, + alert_type => $type + } + ); + + # clear existing data so we can be sure we're creating it + $alert->delete() if $alert; + } + + $mech->get_ok( $test->{uri} ); + + $alert = FixMyStreet::App->model('DB::Alert')->find( { - email => $test->{email} + user => $user, + alert_type => $type, + parameter => $test->{param1}, + parameter2 => $test->{param2}, + confirmed => 0, } ); + ok $alert, 'New alert created with existing user'; + }; +} + +foreach my $test ( + { + email => 'test-login@example.com', + type => 'council', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + param1 => 2651, + param2 => 2651, + } + ) +{ + subtest "use logged in user in an alert" => sub { + my $type = $test->{type} . '_problems'; + + my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => $test->{email} } ); + + $mech->log_in_ok( $test->{email} ); + my $alert; - if ( $user ) { + if ($user) { $alert = FixMyStreet::App->model('DB::Alert')->find( { user => $user, @@ -170,7 +214,14 @@ foreach my $test ( $alert->delete() if $alert; } - $mech->get_ok( $test->{uri} ); + $mech->get_ok('/alert/list?pc=EH991SP'); + + my $form_values = $mech->visible_form_values(); + ok $form_values->{rznvy} eq $test->{email}, + 'auto filled in correct email'; + + $mech->set_visible( [ radio => 'council:2651:City_of_Edinburgh' ] ); + $mech->click('alert'); $alert = FixMyStreet::App->model('DB::Alert')->find( { -- cgit v1.2.3 From a9b2134ef5c94a74f840315aee987bfc57680c69 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 13:14:23 +0100 Subject: problem update alert subscription --- t/app/controller/alert_new.t | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index c44d14a30..7cbf6188a 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -9,7 +9,7 @@ my $mech = FixMyStreet::TestMech->new; foreach my $test ( { email => 'test@example.com', - type => 'area', + type => 'area_problems', content => 'your alert will not be activated', email_text => 'confirm the alert', uri => @@ -18,7 +18,7 @@ foreach my $test ( }, { email => 'test@example.com', - type => 'council', + type => 'council_problems', content => 'your alert will not be activated', email_text => 'confirm the alert', uri => @@ -28,7 +28,7 @@ foreach my $test ( }, { email => 'test@example.com', - type => 'ward', + type => 'ward_problems', content => 'your alert will not be activated', email_text => 'confirm the alert', uri => @@ -38,20 +38,28 @@ foreach my $test ( }, { email => 'test@example.com', - type => 'local', + type => 'local_problems', content => 'your alert will not be activated', email_text => 'confirm the alert', uri => '/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1', param1 => 10.2, param2 => 20.1, + }, + { + email => 'test@example.com', + type => 'new_updates', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + uri => '/alert/subscribe?type=updates&rznvy=test@example.com&id=1', + param1 => 1, } ) { subtest "$test->{type} alert correctly created" => sub { $mech->clear_emails_ok; - my $type = $test->{type} . '_problems'; + my $type = $test->{type}; my $user = FixMyStreet::App->model('DB::User') -- cgit v1.2.3 From a6aeadb959c6eb5e8e87f0a79ecd5ff53e3a7e56 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 10:18:22 +0100 Subject: start adding contact form --- t/app/controller/contact.t | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 t/app/controller/contact.t (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t new file mode 100644 index 000000000..a15f08118 --- /dev/null +++ b/t/app/controller/contact.t @@ -0,0 +1,14 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + + + +$mech->get_ok( '/contact' ); +$mech->content_contains( "We'd love to hear what you think about this site" ); + +done_testing(); -- cgit v1.2.3 From acec961ab9961b69e43a7cc95616577021bbd47d Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 10:21:56 +0100 Subject: fix contact page title --- t/app/controller/contact.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index a15f08118..2ddc279bc 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -7,8 +7,8 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; - $mech->get_ok( '/contact' ); +$mech->title_like( qr/Contact Us/ ); $mech->content_contains( "We'd love to hear what you think about this site" ); done_testing(); -- cgit v1.2.3 From 959acf33e06ea8ea3bae7fa89e800dfd8c45621e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 12:06:57 +0100 Subject: display problem and update information as appropriate --- t/app/controller/contact.t | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 2ddc279bc..60e330776 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -11,4 +11,38 @@ $mech->get_ok( '/contact' ); $mech->title_like( qr/Contact Us/ ); $mech->content_contains( "We'd love to hear what you think about this site" ); +subtest 'check reporting a problem displays correctly' => sub { + my $user = FixMyStreet::App->model('DB::User')->find_or_create( + { + name => 'A User', + email => 'problem_report_rest@example.com' + } + ); + + my $problem = FixMyStreet::App->model('DB::Problem')->create( + { + title => 'Some problem or other', + detail => 'More detail on the problem', + postcode => 'EH99 1SP', + latitude => 0, + longitude => 0, + areas => 0, + used_map => 0, + name => 'Problem User', + anonymous => 0, + state => 'confirmed', + user => $user + } + ); + + ok $problem, 'succesfully create a problem'; + + $mech->get_ok( '/contact?id=' . $problem->id ); + $mech->content_contains( 'reporting the following problem' ); + $mech->content_contains( 'Some problem or other' ); + $mech->content_contains( 'Reported by A User' ); + + $problem->delete; +}; + done_testing(); -- cgit v1.2.3 From 76715723f615a5858587586df395072745f9e5cb Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 12:42:32 +0100 Subject: make problem report date pretty --- t/app/controller/contact.t | 2 ++ 1 file changed, 2 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 60e330776..d4c31bd20 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -24,6 +24,7 @@ subtest 'check reporting a problem displays correctly' => sub { title => 'Some problem or other', detail => 'More detail on the problem', postcode => 'EH99 1SP', + confirmed => '2011-05-04 10:44:28.145168', latitude => 0, longitude => 0, areas => 0, @@ -41,6 +42,7 @@ subtest 'check reporting a problem displays correctly' => sub { $mech->content_contains( 'reporting the following problem' ); $mech->content_contains( 'Some problem or other' ); $mech->content_contains( 'Reported by A User' ); + $mech->content_contains( 'Reported by A User at 10:44, Wednesday 4 May 2011' ); $problem->delete; }; -- cgit v1.2.3 From ae9bd9cab0b338a1f07721e7ec4a8cba68ff8f7b Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 12:44:43 +0100 Subject: perltidy --- t/app/controller/contact.t | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index d4c31bd20..9d232c8ff 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -6,10 +6,9 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; - -$mech->get_ok( '/contact' ); -$mech->title_like( qr/Contact Us/ ); -$mech->content_contains( "We'd love to hear what you think about this site" ); +$mech->get_ok('/contact'); +$mech->title_like(qr/Contact Us/); +$mech->content_contains("We'd love to hear what you think about this site"); subtest 'check reporting a problem displays correctly' => sub { my $user = FixMyStreet::App->model('DB::User')->find_or_create( @@ -21,28 +20,29 @@ subtest 'check reporting a problem displays correctly' => sub { my $problem = FixMyStreet::App->model('DB::Problem')->create( { - title => 'Some problem or other', - detail => 'More detail on the problem', - postcode => 'EH99 1SP', + title => 'Some problem or other', + detail => 'More detail on the problem', + postcode => 'EH99 1SP', confirmed => '2011-05-04 10:44:28.145168', - latitude => 0, + latitude => 0, longitude => 0, - areas => 0, - used_map => 0, - name => 'Problem User', + areas => 0, + used_map => 0, + name => 'Problem User', anonymous => 0, - state => 'confirmed', - user => $user + state => 'confirmed', + user => $user } ); ok $problem, 'succesfully create a problem'; $mech->get_ok( '/contact?id=' . $problem->id ); - $mech->content_contains( 'reporting the following problem' ); - $mech->content_contains( 'Some problem or other' ); - $mech->content_contains( 'Reported by A User' ); - $mech->content_contains( 'Reported by A User at 10:44, Wednesday 4 May 2011' ); + $mech->content_contains('reporting the following problem'); + $mech->content_contains('Some problem or other'); + $mech->content_contains('Reported by A User'); + $mech->content_contains( + 'Reported by A User at 10:44, Wednesday 4 May 2011'); $problem->delete; }; -- cgit v1.2.3 From 84053fd846af39f03c8e6087e9f1df41dffe62ff Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 13:12:08 +0100 Subject: tests/fixes for anonymous reports --- t/app/controller/contact.t | 94 ++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 36 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 9d232c8ff..412b834f3 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -10,41 +10,63 @@ $mech->get_ok('/contact'); $mech->title_like(qr/Contact Us/); $mech->content_contains("We'd love to hear what you think about this site"); -subtest 'check reporting a problem displays correctly' => sub { - my $user = FixMyStreet::App->model('DB::User')->find_or_create( - { - name => 'A User', - email => 'problem_report_rest@example.com' - } - ); - - my $problem = FixMyStreet::App->model('DB::Problem')->create( - { - title => 'Some problem or other', - detail => 'More detail on the problem', - postcode => 'EH99 1SP', - confirmed => '2011-05-04 10:44:28.145168', - latitude => 0, - longitude => 0, - areas => 0, - used_map => 0, - name => 'Problem User', - anonymous => 0, - state => 'confirmed', - user => $user - } - ); - - ok $problem, 'succesfully create a problem'; - - $mech->get_ok( '/contact?id=' . $problem->id ); - $mech->content_contains('reporting the following problem'); - $mech->content_contains('Some problem or other'); - $mech->content_contains('Reported by A User'); - $mech->content_contains( - 'Reported by A User at 10:44, Wednesday 4 May 2011'); - - $problem->delete; -}; +for my $test ( + { + name => 'A User', + email => 'problem_report_test@example.com', + title => 'Some problem or other', + detail => 'More detail on the problem', + postcode => 'EH99 1SP', + confirmed => '2011-05-04 10:44:28.145168', + anonymous => 0, + meta => 'Reported by A User at 10:44, Wednesday 4 May 2011', + }, + { + name => 'A User', + email => 'problem_report_test@example.com', + title => 'A different problem', + detail => 'More detail on the different problem', + postcode => 'EH99 1SP', + confirmed => '2011-05-03 13:24:28.145168', + anonymous => 1, + meta => 'Reported anonymously at 13:24, Tuesday 3 May 2011', + }, + ) +{ + subtest 'check reporting a problem displays correctly' => sub { + my $user = FixMyStreet::App->model('DB::User')->find_or_create( + { + name => $test->{name}, + email => $test->{email} + } + ); + + my $problem = FixMyStreet::App->model('DB::Problem')->create( + { + title => $test->{title}, + detail => $test->{detail}, + postcode => $test->{postcode}, + confirmed => $test->{confirmed}, + name => $test->{name}, + anonymous => $test->{anonymous}, + state => 'confirmed', + user => $user, + latitude => 0, + longitude => 0, + areas => 0, + used_map => 0, + } + ); + + ok $problem, 'succesfully create a problem'; + + $mech->get_ok( '/contact?id=' . $problem->id ); + $mech->content_contains('reporting the following problem'); + $mech->content_contains( $test->{title} ); + $mech->content_contains( $test->{meta} ); + + $problem->delete; + }; +} done_testing(); -- cgit v1.2.3 From fbb8d5ca4e3bfecf5c276f4a8dd43fb5fc4002d9 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 16:36:13 +0100 Subject: contact form validation and post submission page --- t/app/controller/contact.t | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 412b834f3..a5135c60a 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -69,4 +69,80 @@ for my $test ( }; } +for my $test ( + { + fields => { + em => ' ', + name => '', + subject => '', + message => '', + }, + errors => [ + 'Please give your name', + 'Please give your email', + 'Please give a subject', + 'Please write a message', + ] + }, + { + fields => { + em => 'invalidemail', + name => '', + subject => '', + message => '', + }, + errors => [ + 'Please give your name', + 'Please give a valid email address', + 'Please give a subject', + 'Please write a message', + ] + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => '', + message => '', + }, + errors => [ 'Please give a subject', 'Please write a message', ] + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => '', + }, + errors => [ 'Please write a message', ] + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => ' ', + message => '', + }, + errors => [ 'Please give a subject', 'Please write a message', ] + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => ' ', + }, + errors => [ 'Please write a message', ] + }, + + ) +{ + subtest 'check submit page error handling' => sub { + $mech->get_ok('/contact'); + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + is_deeply $mech->form_errors, $test->{errors}; + is_deeply $mech->visible_form_values, $test->{fields}; + }; +} + done_testing(); -- cgit v1.2.3 From b683026c94f15f6f4b5214820b1446a8ef684658 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 17:07:46 +0100 Subject: placeholder for email sending code --- t/app/controller/contact.t | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index a5135c60a..c4bf83613 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -145,4 +145,22 @@ for my $test ( }; } +for my $test ( + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + }, + }, + + ) +{ + subtest 'check email sent correctly' => sub { + $mech->get_ok('/contact'); + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + $mech->content_contains('Thanks for your feedback'); + }; +} done_testing(); -- cgit v1.2.3 From 8dae03ed508f07265727005bbce9570e51c6c33c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 13 May 2011 17:52:15 +0100 Subject: display correct error messages and test for bad problem ids --- t/app/controller/contact.t | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index c4bf83613..860ada4ce 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -77,7 +77,9 @@ for my $test ( subject => '', message => '', }, - errors => [ + page_errors => + [ 'There were problems with your report. Please see below.', ], + field_errors => [ 'Please give your name', 'Please give your email', 'Please give a subject', @@ -91,7 +93,9 @@ for my $test ( subject => '', message => '', }, - errors => [ + page_errors => + [ 'There were problems with your report. Please see below.', ], + field_errors => [ 'Please give your name', 'Please give a valid email address', 'Please give a subject', @@ -105,7 +109,9 @@ for my $test ( subject => '', message => '', }, - errors => [ 'Please give a subject', 'Please write a message', ] + page_errors => + [ 'There were problems with your report. Please see below.', ], + field_errors => [ 'Please give a subject', 'Please write a message', ] }, { fields => { @@ -114,7 +120,9 @@ for my $test ( subject => 'A subject', message => '', }, - errors => [ 'Please write a message', ] + page_errors => + [ 'There were problems with your report. Please see below.', ], + field_errors => [ 'Please write a message', ] }, { fields => { @@ -123,7 +131,9 @@ for my $test ( subject => ' ', message => '', }, - errors => [ 'Please give a subject', 'Please write a message', ] + page_errors => + [ 'There were problems with your report. Please see below.', ], + field_errors => [ 'Please give a subject', 'Please write a message', ] }, { fields => { @@ -132,15 +142,33 @@ for my $test ( subject => 'A subject', message => ' ', }, - errors => [ 'Please write a message', ] + page_errors => + [ 'There were problems with your report. Please see below.', ], + field_errors => [ 'Please write a message', ] + }, + { + url => '/contact?id=1', + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + id => 'invalid', + }, + page_errors => [ 'Illegal ID' ], + field_errors => [] }, - ) { subtest 'check submit page error handling' => sub { - $mech->get_ok('/contact'); + $mech->get_ok( $test->{url} ? $test->{url} : '/contact' ); $mech->submit_form_ok( { with_fields => $test->{fields} } ); - is_deeply $mech->form_errors, $test->{errors}; + is_deeply $mech->page_errors, $test->{page_errors}; + is_deeply $mech->form_errors, $test->{field_errors}; + + # we santise this when we submit so need to remove it + delete $test->{fields}->{id} + if $test->{fields}->{id} and $test->{fields}->{id} eq 'invalid'; is_deeply $mech->visible_form_values, $test->{fields}; }; } -- cgit v1.2.3 From ac3eda01d488dc166596d266c82523a5f3a2670a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 16 May 2011 13:55:56 +0100 Subject: put in a use test to stop irritating test failure --- t/app/controller/council.t | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/council.t b/t/app/controller/council.t index d01b3ccd7..11898995a 100644 --- a/t/app/controller/council.t +++ b/t/app/controller/council.t @@ -4,6 +4,11 @@ use Test::More; use Catalyst::Test 'FixMyStreet::App'; -use FixMyStreet::App::Controller::Council; +use_ok( 'FixMyStreet::App::Controller::Council' ); + +TODO: { + local $TODO = 'need to write some tests for this'; + +} done_testing(); -- cgit v1.2.3 From 19bd438d52aa3f0bd707a899025b38eb9d4f27c4 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 16 May 2011 16:11:08 +0100 Subject: tests for correct problem page meta information --- t/app/controller/report_display.t | 81 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index f0f1bdcba..8a0bfb4c3 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -5,6 +5,7 @@ use Test::More; use FixMyStreet::TestMech; use Web::Scraper; use Path::Class; +use DateTime; my $mech = FixMyStreet::TestMech->new; @@ -15,6 +16,15 @@ my $user = ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); ok $user, "created test user"; +my $dt = DateTime->new( + year => 2011, + month => 04, + day => 16, + hour => 15, + minute => 47, + second => 23 +); + my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'SW1A 1AA', @@ -27,6 +37,7 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( name => 'Test User', anonymous => 'f', state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, lang => 'en-gb', service => '', cobrand => 'default', @@ -90,8 +101,78 @@ subtest "change report to hidden and check for 410 status" => sub { subtest "test a good report" => sub { $mech->get_ok("/report/$report_id"); is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + is $mech->extract_problem_meta, + 'Reported by Test User at 15:47, Saturday 16 April 2011', + 'correct problem meta information'; }; +foreach my $meta ( + { + anonymous => 'f', + category => 'Other', + service => '', + meta => 'Reported by Test User at 15:47, Saturday 16 April 2011' + }, + { + anonymous => 'f', + category => 'Roads', + service => '', + meta => +'Reported in the Roads category by Test User at 15:47, Saturday 16 April 2011' + }, + { + anonymous => 'f', + category => '', + service => 'Transport service', + meta => +'Reported by Transport service by Test User at 15:47, Saturday 16 April 2011' + }, + { + anonymous => 'f', + category => 'Roads', + service => 'Transport service', + meta => +'Reported by Transport service in the Roads category by Test User at 15:47, Saturday 16 April 2011' + }, + { + anonymous => 't', + category => 'Other', + service => '', + meta => 'Reported anonymously at 15:47, Saturday 16 April 2011' + }, + { + anonymous => 'f', + category => 'Roads', + service => '', + meta => +'Reported in the Roads category anonymously at 15:47, Saturday 16 April 2011' + }, + { + anonymous => 'f', + category => '', + service => 'Transport service', + meta => +'Reported by Transport service anonymously at 15:47, Saturday 16 April 2011' + }, + { + anonymous => 'f', + category => 'Roads', + service => 'Transport service', + meta => +'Reported by Transport service in the Roads category anonymously at 15:47, Saturday 16 April 2011' + }, + ) +{ + $report->service( $meta->{service} ); + $report->category( $meta->{category} ); + $report->anonymous( $meta->{anonymous} ); + $report->update; + subtest "test correct problem meta information" => sub { + $mech->get_ok("/report/$report_id"); + + }; +} + # tidy up $mech->delete_user('test@example.com'); done_testing(); -- cgit v1.2.3 From 44cdd0e57a323c7d1faf2e1fe4ad3bb473f70c92 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 16 May 2011 16:41:45 +0100 Subject: few more tests for correct problem display --- t/app/controller/report_display.t | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 8a0bfb4c3..6fadd6b9b 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -32,7 +32,7 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( areas => ',105255,11806,11828,2247,2504,', category => 'Other', title => 'Test 2', - detail => 'Test 2', + detail => 'Test 2 Detail', used_map => 't', name => 'Test User', anonymous => 'f', @@ -101,9 +101,11 @@ subtest "change report to hidden and check for 410 status" => sub { subtest "test a good report" => sub { $mech->get_ok("/report/$report_id"); is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + is $mech->extract_problem_title, 'Test 2', 'problem title'; is $mech->extract_problem_meta, 'Reported by Test User at 15:47, Saturday 16 April 2011', 'correct problem meta information'; + $mech->content_contains( 'Test 2 Detail' ); }; foreach my $meta ( -- cgit v1.2.3 From 69e6532d4fa39441a1e78241336e2df60b432aa3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 16 May 2011 17:31:10 +0100 Subject: display/hide problem fixed checkbox --- t/app/controller/report_display.t | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 6fadd6b9b..346722c64 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -106,6 +106,9 @@ subtest "test a good report" => sub { 'Reported by Test User at 15:47, Saturday 16 April 2011', 'correct problem meta information'; $mech->content_contains( 'Test 2 Detail' ); + + my $update_form = $mech->form_name( 'updateForm' ); + is $update_form->value( 'fixed' ), undef, 'problem is not fixed'; }; foreach my $meta ( @@ -175,6 +178,22 @@ foreach my $meta ( }; } +subtest "test a fixed report" => sub { + $report->state( 'fixed' ); + $report->update; + $mech->get_ok("/report/$report_id"); + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + + my $update_form = $mech->form_name( 'updateForm' ); + my $banner = $mech->extract_problem_banner; + $banner->{text} =~ s/^ //g; + $banner->{text} =~ s/ $//g; + + is $banner->{id}, 'fixed', 'banner id'; + is $banner->{text}, 'This problem has been fixed.', 'banner text'; + is $update_form->find_input( 'fixed' ), undef, 'problem is fixed'; +}; + # tidy up $mech->delete_user('test@example.com'); done_testing(); -- cgit v1.2.3 From f8d743d74930d7632d00718be697c11a7c3581a7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 16 May 2011 18:04:50 +0100 Subject: tests for different banner states --- t/app/controller/report_display.t | 75 +++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 14 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 346722c64..26b7db759 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -178,21 +178,68 @@ foreach my $meta ( }; } -subtest "test a fixed report" => sub { - $report->state( 'fixed' ); - $report->update; - $mech->get_ok("/report/$report_id"); - is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; - - my $update_form = $mech->form_name( 'updateForm' ); - my $banner = $mech->extract_problem_banner; - $banner->{text} =~ s/^ //g; - $banner->{text} =~ s/ $//g; +for my $test ( + { + description => 'old report', + date => DateTime->new( + year => 2009, + month => 6, + day => 12, + hour => 9, + minute => 43, + second => 12 + ), + state => 'confirmed', + banner_id => 'unknown', + banner_text => 'This problem is old and of unknown status.', + fixed => 0 + }, + { + description => 'old fixed report', + date => DateTime->new( + year => 2009, + month => 6, + day => 12, + hour => 9, + minute => 43, + second => 12 + ), + state => 'fixed', + banner_id => 'fixed', + banner_text => 'This problem has been fixed.', + fixed => 1 + }, + { + description => 'fixed report', + date => DateTime->now, + state => 'fixed', + banner_id => 'fixed', + banner_text => 'This problem has been fixed.', + fixed => 1 + }, +) { + subtest "banner for $test->{description}" => sub { + $report->confirmed( $test->{date}->ymd . ' ' . $test->{date}->hms ); + $report->state( $test->{state} ); + $report->update; - is $banner->{id}, 'fixed', 'banner id'; - is $banner->{text}, 'This problem has been fixed.', 'banner text'; - is $update_form->find_input( 'fixed' ), undef, 'problem is fixed'; -}; + $mech->get_ok("/report/$report_id"); + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + my $banner = $mech->extract_problem_banner; + $banner->{text} =~ s/^ //g; + $banner->{text} =~ s/ $//g; + + is $banner->{id}, $test->{banner_id}, 'banner id'; + is $banner->{text}, $test->{banner_text}, 'banner text'; + + my $update_form = $mech->form_name( 'updateForm' ); + if ( $test->{fixed} ) { + is $update_form->find_input( 'fixed' ), undef, 'problem is fixed'; + } else { + ok $update_form->find_input( 'fixed' ) != undef, 'problem is not fixed'; + } + }; +} # tidy up $mech->delete_user('test@example.com'); -- cgit v1.2.3 From 202abd84b382816d7095929a8d4b85a395f21489 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 17 May 2011 10:55:26 +0100 Subject: replace more old template tags with TT ones --- t/app/controller/report_display.t | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 26b7db759..ee9172d11 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -105,10 +105,18 @@ subtest "test a good report" => sub { is $mech->extract_problem_meta, 'Reported by Test User at 15:47, Saturday 16 April 2011', 'correct problem meta information'; - $mech->content_contains( 'Test 2 Detail' ); - - my $update_form = $mech->form_name( 'updateForm' ); - is $update_form->value( 'fixed' ), undef, 'problem is not fixed'; + $mech->content_contains('Test 2 Detail'); + + my $update_form = $mech->form_name('updateForm'); + + my %fields = ( + name => '', + rznvy => '', + update => '', + add_alert => undef, + fixed => undef + ); + is $update_form->value($_), $fields{$_}, "$_ value" for keys %fields; }; foreach my $meta ( -- cgit v1.2.3 From 9c9d6f649c962bc5902809e3c652d757a6849525 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 17 May 2011 18:13:48 +0100 Subject: display problem updates --- t/app/controller/report_updates.t | 113 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 t/app/controller/report_updates.t (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t new file mode 100644 index 000000000..fca9a8063 --- /dev/null +++ b/t/app/controller/report_updates.t @@ -0,0 +1,113 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +use Web::Scraper; +use Path::Class; +use DateTime; + +my $mech = FixMyStreet::TestMech->new; + +# create a test user and report +$mech->delete_user('test@example.com'); +my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); +ok $user, "created test user"; + +my $dt = DateTime->new( + year => 2011, + month => 04, + day => 16, + hour => 15, + minute => 47, + second => 23 +); + +my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'SW1A 1AA', + council => '2504', + areas => ',105255,11806,11828,2247,2504,', + category => 'Other', + title => 'Test 2', + detail => 'Test 2 Detail', + used_map => 't', + name => 'Test User', + anonymous => 'f', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '51.5016605453401', + longitude => '-0.142497580865087', + user_id => $user->id, + } +); +my $report_id = $report->id; +ok $report, "created test report - $report_id"; + +my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( + { + problem_id => $report_id, + name => 'Other User', + mark_fixed => 'false', + text => 'This is some update text', + email => 'commenter@example.com', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, + } +); + +my $comment_id = $comment->id; +ok $comment, "created test update - $comment_id"; + +for my $test ( + { + name => 'Other User', + mark_fixed => 'false', + mark_open => 'false', + meta => 'Posted by Other User at 15:47, Saturday 16 April 2011', + }, + { + name => '', + mark_fixed => 'false', + mark_open => 'false', + meta => 'Posted anonymously at 15:47, Saturday 16 April 2011', + }, + { + name => '', + mark_fixed => 'true', + mark_open => 'false', + meta => 'Posted anonymously at 15:47, Saturday 16 April 2011, marked as fixed', + }, + { + name => '', + mark_fixed => 'false', + mark_open => 'true', + meta => 'Posted anonymously at 15:47, Saturday 16 April 2011, reopened', + } +) { + subtest "test update displayed" => sub { + $comment->name( $test->{name} ); + $comment->mark_fixed( $test->{mark_fixed} ); + $comment->mark_open( $test->{mark_open} ); + $comment->update; + + $mech->get_ok("/report/$report_id"); + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + $mech->content_contains('This is some update text'); + + my $meta = $mech->extract_update_metas; + is scalar @$meta, 1, 'number of updates'; + is $meta->[0], $test->{meta}; + }; +} + +ok $comment->delete, 'deleted comment'; +$mech->delete_user('test@example.com'); +done_testing(); -- cgit v1.2.3 From bcdaabb1938a948eeffae6cb5bbd42bc310efc5a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 17 May 2011 18:14:26 +0100 Subject: perltidy --- t/app/controller/report_updates.t | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index fca9a8063..466fa71c1 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -56,42 +56,44 @@ my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( problem_id => $report_id, name => 'Other User', mark_fixed => 'false', - text => 'This is some update text', - email => 'commenter@example.com', - state => 'confirmed', - confirmed => $dt->ymd . ' ' . $dt->hms, + text => 'This is some update text', + email => 'commenter@example.com', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, } ); my $comment_id = $comment->id; ok $comment, "created test update - $comment_id"; -for my $test ( +for my $test ( { - name => 'Other User', + name => 'Other User', mark_fixed => 'false', - mark_open => 'false', - meta => 'Posted by Other User at 15:47, Saturday 16 April 2011', + mark_open => 'false', + meta => 'Posted by Other User at 15:47, Saturday 16 April 2011', }, { - name => '', + name => '', mark_fixed => 'false', - mark_open => 'false', - meta => 'Posted anonymously at 15:47, Saturday 16 April 2011', + mark_open => 'false', + meta => 'Posted anonymously at 15:47, Saturday 16 April 2011', }, { - name => '', + name => '', mark_fixed => 'true', - mark_open => 'false', - meta => 'Posted anonymously at 15:47, Saturday 16 April 2011, marked as fixed', + mark_open => 'false', + meta => +'Posted anonymously at 15:47, Saturday 16 April 2011, marked as fixed', }, { - name => '', + name => '', mark_fixed => 'false', - mark_open => 'true', + mark_open => 'true', meta => 'Posted anonymously at 15:47, Saturday 16 April 2011, reopened', } -) { + ) +{ subtest "test update displayed" => sub { $comment->name( $test->{name} ); $comment->mark_fixed( $test->{mark_fixed} ); -- cgit v1.2.3 From 35f1983f535f0d9208525aa1d1369ebf35d8097f Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 17 May 2011 18:18:21 +0100 Subject: actually compare the problem meta information in the tests --- t/app/controller/report_display.t | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index ee9172d11..2afff21dd 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -154,21 +154,21 @@ foreach my $meta ( meta => 'Reported anonymously at 15:47, Saturday 16 April 2011' }, { - anonymous => 'f', + anonymous => 't', category => 'Roads', service => '', meta => 'Reported in the Roads category anonymously at 15:47, Saturday 16 April 2011' }, { - anonymous => 'f', + anonymous => 't', category => '', service => 'Transport service', meta => 'Reported by Transport service anonymously at 15:47, Saturday 16 April 2011' }, { - anonymous => 'f', + anonymous => 't', category => 'Roads', service => 'Transport service', meta => @@ -182,6 +182,8 @@ foreach my $meta ( $report->update; subtest "test correct problem meta information" => sub { $mech->get_ok("/report/$report_id"); + + is $mech->extract_problem_meta, $meta->{meta}; }; } -- cgit v1.2.3 From c3b33bfac3b15c869fc24aacc403e148b2079edc Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 May 2011 12:43:52 +0100 Subject: rejig now that we can mark comments as anonymous --- t/app/controller/report_updates.t | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 466fa71c1..13908fbff 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -10,12 +10,19 @@ use DateTime; my $mech = FixMyStreet::TestMech->new; # create a test user and report +$mech->delete_user('commenter@example.com'); $mech->delete_user('test@example.com'); + my $user = FixMyStreet::App->model('DB::User') ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); ok $user, "created test user"; +my $user2 = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'commenter@example.com', name => 'Commenter' } ); +ok $user2, "created comment user"; + my $dt = DateTime->new( year => 2011, month => 04, @@ -54,10 +61,10 @@ ok $report, "created test report - $report_id"; my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( { problem_id => $report_id, + user_id => $user2->id, name => 'Other User', mark_fixed => 'false', text => 'This is some update text', - email => 'commenter@example.com', state => 'confirmed', confirmed => $dt->ymd . ' ' . $dt->hms, } @@ -68,36 +75,53 @@ ok $comment, "created test update - $comment_id"; for my $test ( { + description => 'named user, anon is false', name => 'Other User', + anonymous => 'f', mark_fixed => 'false', mark_open => 'false', meta => 'Posted by Other User at 15:47, Saturday 16 April 2011', }, { + description => 'blank user, anon is false', name => '', + anonymous => 'f', mark_fixed => 'false', mark_open => 'false', meta => 'Posted anonymously at 15:47, Saturday 16 April 2011', }, { - name => '', + description => 'named user, anon is true', + name => 'Other User', + anonymous => 't', + mark_fixed => 'false', + mark_open => 'false', + meta => 'Posted anonymously at 15:47, Saturday 16 April 2011', + }, + { + description => 'named user, anon is true, fixed', + name => 'Other User', + anonymous => 't', mark_fixed => 'true', mark_open => 'false', meta => 'Posted anonymously at 15:47, Saturday 16 April 2011, marked as fixed', }, { - name => '', + description => 'named user, anon is true, reopened', + name => 'Other User', + anonymous => 't', mark_fixed => 'false', mark_open => 'true', meta => 'Posted anonymously at 15:47, Saturday 16 April 2011, reopened', } ) { - subtest "test update displayed" => sub { + subtest "test update displayed for $test->{description}" => sub { $comment->name( $test->{name} ); $comment->mark_fixed( $test->{mark_fixed} ); $comment->mark_open( $test->{mark_open} ); + $comment->anonymous( $test->{anonymous} ); $comment->update; $mech->get_ok("/report/$report_id"); @@ -111,5 +135,6 @@ for my $test ( } ok $comment->delete, 'deleted comment'; +$mech->delete_user('commenter@example.com'); $mech->delete_user('test@example.com'); done_testing(); -- cgit v1.2.3 From 7acea67840e3b289f03ab728a257510671ee9c8d Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 May 2011 12:44:34 +0100 Subject: don't display unconfirmed updates --- t/app/controller/report_updates.t | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 13908fbff..55b181178 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -134,6 +134,15 @@ for my $test ( }; } +subtest "unconfirmed updates not displayed" => sub { + $comment->state( 'unconfirmed' ); + $comment->update; + $mech->get_ok("/report/$report_id"); + + my $meta = $mech->extract_update_metas; + is scalar @$meta, 0, 'update not displayed'; +}; + ok $comment->delete, 'deleted comment'; $mech->delete_user('commenter@example.com'); $mech->delete_user('test@example.com'); -- cgit v1.2.3 From 6b304e144051fe6d531ca475cd6fe43fd3705c7f Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 May 2011 14:55:47 +0100 Subject: test comment ordering --- t/app/controller/report_updates.t | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 55b181178..a3a612c95 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -143,6 +143,50 @@ subtest "unconfirmed updates not displayed" => sub { is scalar @$meta, 0, 'update not displayed'; }; +subtest "several updates shown in correct order" => sub { + for my $fields ( { + problem_id => $report_id, + user_id => $user2->id, + name => 'Other User', + mark_fixed => 'false', + text => 'First update', + state => 'confirmed', + confirmed => '2011-03-10 12:23:15', + }, + { + problem_id => $report_id, + user_id => $user->id, + name => 'Main User', + mark_fixed => 'false', + text => 'Second update', + state => 'confirmed', + confirmed => '2011-03-10 12:23:16', + }, + { + problem_id => $report_id, + user_id => $user->id, + name => 'Other User', + anonymous => 'true', + mark_fixed => 'true', + text => 'Third update', + state => 'confirmed', + confirmed => '2011-03-15 08:12:36', + } + ) { + my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( + $fields + ); + } + + $mech->get_ok("/report/$report_id"); + + my $meta = $mech->extract_update_metas; + is scalar @$meta, 3, 'number of updates'; + is $meta->[0], 'Posted by Other User at 12:23, Thursday 10 March 2011', 'first update'; + is $meta->[1], 'Posted by Main User at 12:23, Thursday 10 March 2011', 'second update'; + is $meta->[2], 'Posted anonymously at 08:12, Tuesday 15 March 2011, marked as fixed', 'third update'; +}; + ok $comment->delete, 'deleted comment'; $mech->delete_user('commenter@example.com'); $mech->delete_user('test@example.com'); -- cgit v1.2.3 From c40da27da59b74c32db0a50a2a03473ec4cdba2c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 May 2011 15:48:00 +0100 Subject: initial problem update reporting. only does basic validation so far --- t/app/controller/report_updates.t | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index a3a612c95..1ecdef96d 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -187,6 +187,35 @@ subtest "several updates shown in correct order" => sub { is $meta->[2], 'Posted anonymously at 08:12, Tuesday 15 March 2011, marked as fixed', 'third update'; }; +for my $test ( + { + fields => { + rznvy => '', + update => '', + name => '', + }, + field_errors => [ 'Please enter your email', 'Please enter a message' ] + }, + { + fields => { + rznvy => 'test', + update => '', + name => '', + }, + field_errors => [ 'Please enter a valid email', 'Please enter a message' ] + }, + ) +{ + subtest "submit an update" => sub { + $mech->get_ok("/report/$report_id"); + + $mech->submit_form_ok( { with_fields => $test->{fields} }, + 'submit update' ); + + is_deeply $mech->form_errors, $test->{field_errors}, 'field errors'; + }; +} + ok $comment->delete, 'deleted comment'; $mech->delete_user('commenter@example.com'); $mech->delete_user('test@example.com'); -- cgit v1.2.3 From 2e361587044731fc6101f0978aaa0dad3fdc2b93 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 13:07:21 +0100 Subject: save and confirm update or email for confirmation as appropriate --- t/app/controller/report_updates.t | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 1ecdef96d..83df55f30 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -216,6 +216,71 @@ for my $test ( }; } +subtest "submit an update for a non registered user" => sub { + $mech->clear_emails_ok(); + + $mech->get_ok("/report/$report_id"); + + $mech->submit_form_ok( + { + with_fields => { + rznvy => 'unregistered@example.com', + update => 'update from an unregistered user' + } + }, + 'submit update' + ); + + $mech->content_contains('Nearly Done! Now check your email'); + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the update you/i, "Correct email text"; + + + my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)}; + ok $url, "extracted confirm url '$url'"; + + my $token = FixMyStreet::App->model('DB::Token')->find( + { + token => $url_token, + scope => 'comment' + } + ); + ok $token, 'Token found in database'; + + my $update_id = $token->data; + my $update = FixMyStreet::App->model( 'DB::Comment' )->find( + { id => $update_id } + ); + + ok $update, 'found update in database'; + is $update->state, 'unconfirmed', 'update unconfirmed'; + is $update->user->email, 'unregistered@example.com', 'update email'; + is $update->text, 'update from an unregistered user', 'update text'; +}; + +subtest "submit an update for a registered user" => sub { + $mech->clear_emails_ok(); + + $mech->log_in_ok( $user->email ); + $mech->get_ok("/report/$report_id"); + + $mech->submit_form_ok( + { + with_fields => { + rznvy => 'test@example.com', + update => 'update from a registered user' + } + }, + 'submit update' + ); + + is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; + + $mech->email_count_is(0); +}; + ok $comment->delete, 'deleted comment'; $mech->delete_user('commenter@example.com'); $mech->delete_user('test@example.com'); -- cgit v1.2.3 From e855197af0611d768304ac4ee5734c819d275ffb Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 13:58:11 +0100 Subject: test registered user update correct --- t/app/controller/report_updates.t | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 83df55f30..e64e2f4d6 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -261,6 +261,11 @@ subtest "submit an update for a non registered user" => sub { }; subtest "submit an update for a registered user" => sub { + # clear out comments for this problem to make + # checking details easier later + ok( $_->delete, 'deleted comment ' . $_->id ) + for $report->comments; + $mech->clear_emails_ok(); $mech->log_in_ok( $user->email ); @@ -279,6 +284,12 @@ subtest "submit an update for a registered user" => sub { is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; $mech->email_count_is(0); + + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, 'update from a registered user', 'update text'; + is $update->user->email, 'test@example.com', 'update user'; + is $update->state, 'confirmed', 'update confirmed'; }; ok $comment->delete, 'deleted comment'; -- cgit v1.2.3 From b7cd54ecbf9c9bfcfe68b55676c2387fe7a8239f Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 19 May 2011 14:21:09 +0100 Subject: Starting tests for /reports, fix for warning. --- t/app/controller/report_display.t | 2 +- t/app/controller/reports.t | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 t/app/controller/reports.t (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 2afff21dd..7be9f387e 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -246,7 +246,7 @@ for my $test ( if ( $test->{fixed} ) { is $update_form->find_input( 'fixed' ), undef, 'problem is fixed'; } else { - ok $update_form->find_input( 'fixed' ) != undef, 'problem is not fixed'; + ok $update_form->find_input( 'fixed' ), 'problem is not fixed'; } }; } diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t new file mode 100644 index 000000000..312297436 --- /dev/null +++ b/t/app/controller/reports.t @@ -0,0 +1,34 @@ +use strict; +use warnings; +use Test::More; +use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; +use mySociety::MaPit; + +ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); + +# check that we can get the page +$mech->get_ok('/reports'); +$mech->title_like(qr{Summary reports}); +$mech->content_contains('Birmingham'); +$mech->follow_link_ok( { text_regex => qr/Birmingham/ } ); + +SKIP: { + skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 8 ) + unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{emptyhomes}; + ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; + $mech->get_ok('/reports'); + # EHA lacks one column the others have + $mech->content_lacks('state unknown'); + + # FIXME To do the below, need a way of altering where MaPit is pointing + # skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 ) + # unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami}; + # ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; + # $mech->get_ok('/reports'); + # # There should only be one Oslo + # $mech->content_contains('Oslo'); + # $mech->content_unlike(qr{Oslo.*Oslo}s); +} + +done_testing(); + -- cgit v1.2.3 From 7d563605520e92c6c3c1441a2c89cce127e16b72 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 19 May 2011 14:56:50 +0100 Subject: Check Norwegian version of /reports. --- t/app/controller/reports.t | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 312297436..6cb12e20f 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -20,14 +20,14 @@ SKIP: { # EHA lacks one column the others have $mech->content_lacks('state unknown'); - # FIXME To do the below, need a way of altering where MaPit is pointing - # skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 ) - # unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami}; - # ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; - # $mech->get_ok('/reports'); - # # There should only be one Oslo - # $mech->content_contains('Oslo'); - # $mech->content_unlike(qr{Oslo.*Oslo}s); + skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 ) + unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami}; + mySociety::MaPit::configure('http://mapit.nuug.no/'); + ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; + $mech->get_ok('/reports'); + # There should only be one Oslo + $mech->content_contains('Oslo'); + $mech->content_unlike(qr{Oslo">Oslo.*Oslo}s); } done_testing(); -- cgit v1.2.3 From 1463288a3282ec5d0f195e2ed44253b78f5b915b Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 17:07:24 +0100 Subject: create token for comment confirmation correctly --- t/app/controller/report_updates.t | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index e64e2f4d6..8f64f1109 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -249,7 +249,8 @@ subtest "submit an update for a non registered user" => sub { ); ok $token, 'Token found in database'; - my $update_id = $token->data; + my $update_id = $token->data->{id}; + my $add_alerts = $token->data->{add_alert}; my $update = FixMyStreet::App->model( 'DB::Comment' )->find( { id => $update_id } ); @@ -258,6 +259,7 @@ subtest "submit an update for a non registered user" => sub { is $update->state, 'unconfirmed', 'update unconfirmed'; is $update->user->email, 'unregistered@example.com', 'update email'; is $update->text, 'update from an unregistered user', 'update text'; + is $add_alerts, 0, 'do not sign up for alerts'; }; subtest "submit an update for a registered user" => sub { -- cgit v1.2.3 From 2c3160b0fb07d9412925a3d57f4017c998de835e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 17:11:37 +0100 Subject: sign up logged in users for alerts as appropriate --- t/app/controller/report_updates.t | 73 +++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 25 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 8f64f1109..182f3a244 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -262,37 +262,60 @@ subtest "submit an update for a non registered user" => sub { is $add_alerts, 0, 'do not sign up for alerts'; }; -subtest "submit an update for a registered user" => sub { - # clear out comments for this problem to make - # checking details easier later - ok( $_->delete, 'deleted comment ' . $_->id ) - for $report->comments; +for my $test ( + { + desc => 'submit update for register user', + fields => { + rznvy => 'test@example.com', + update => 'update from a registered user' + }, + alert => 0, + }, + { + desc => 'submit update for register user and sign up', + fields => { + rznvy => 'test@example.com', + update => 'update from a registered user', + add_alert => 1, + }, + alert => 1, + }, +) { + subtest $test->{desc} => sub { + # clear out comments for this problem to make + # checking details easier later + ok( $_->delete, 'deleted comment ' . $_->id ) + for $report->comments; - $mech->clear_emails_ok(); + $mech->clear_emails_ok(); - $mech->log_in_ok( $user->email ); - $mech->get_ok("/report/$report_id"); + $mech->log_in_ok( $user->email ); + $mech->get_ok("/report/$report_id"); - $mech->submit_form_ok( - { - with_fields => { - rznvy => 'test@example.com', - update => 'update from a registered user' - } - }, - 'submit update' - ); + $mech->submit_form_ok( + { + with_fields => $test->{fields}, + }, + 'submit update' + ); - is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; + is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; - $mech->email_count_is(0); + $mech->email_count_is(0); - my $update = $report->comments->first; - ok $update, 'found update'; - is $update->text, 'update from a registered user', 'update text'; - is $update->user->email, 'test@example.com', 'update user'; - is $update->state, 'confirmed', 'update confirmed'; -}; + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, $test->{fields}->{update}, 'update text'; + is $update->user->email, 'test@example.com', 'update user'; + is $update->state, 'confirmed', 'update confirmed'; + + my $alert = + FixMyStreet::App->model('DB::Alert') + ->find( { user => $user, alert_type => 'new_updates' } ); + + ok $test->{alert} ? $alert : !$alert, 'not signed up for alerts'; + }; +} ok $comment->delete, 'deleted comment'; $mech->delete_user('commenter@example.com'); -- cgit v1.2.3 From c81d9ee2c13b5430be1beb4210d10e1cbb31c194 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 10:42:47 +0100 Subject: move trim_text and cleanup_text to Utils --- t/app/controller/report_updates.t | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 182f3a244..f1717a64e 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -258,7 +258,7 @@ subtest "submit an update for a non registered user" => sub { ok $update, 'found update in database'; is $update->state, 'unconfirmed', 'update unconfirmed'; is $update->user->email, 'unregistered@example.com', 'update email'; - is $update->text, 'update from an unregistered user', 'update text'; + is $update->text, 'Update from an unregistered user', 'update text'; is $add_alerts, 0, 'do not sign up for alerts'; }; @@ -269,6 +269,9 @@ for my $test ( rznvy => 'test@example.com', update => 'update from a registered user' }, + changed => { + update => 'Update from a registered user' + }, alert => 0, }, { @@ -278,6 +281,9 @@ for my $test ( update => 'update from a registered user', add_alert => 1, }, + changed => { + update => 'Update from a registered user' + }, alert => 1, }, ) { @@ -303,9 +309,14 @@ for my $test ( $mech->email_count_is(0); + my $results = { + %{ $test->{fields} }, + %{ $test->{changed} }, + }; + my $update = $report->comments->first; ok $update, 'found update'; - is $update->text, $test->{fields}->{update}, 'update text'; + is $update->text, $results->{update}, 'update text'; is $update->user->email, 'test@example.com', 'update user'; is $update->state, 'confirmed', 'update confirmed'; -- cgit v1.2.3 From ce75c68071fc362b986cdc1b64695f50f9c2bf72 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 12:00:53 +0100 Subject: default add_alerts to on --- t/app/controller/report_display.t | 2 +- t/app/controller/report_updates.t | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 7be9f387e..aa7e507d9 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -113,7 +113,7 @@ subtest "test a good report" => sub { name => '', rznvy => '', update => '', - add_alert => undef, + add_alert => 1, # defaults to true fixed => undef ); is $update_form->value($_), $fields{$_}, "$_ value" for keys %fields; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index f1717a64e..7f6f4dc1a 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -224,8 +224,10 @@ subtest "submit an update for a non registered user" => sub { $mech->submit_form_ok( { with_fields => { + submit_update => 1, rznvy => 'unregistered@example.com', - update => 'update from an unregistered user' + update => 'update from an unregistered user', + add_alert => 0, } }, 'submit update' @@ -266,8 +268,10 @@ for my $test ( { desc => 'submit update for register user', fields => { + submit_update => 1, rznvy => 'test@example.com', - update => 'update from a registered user' + update => 'update from a registered user', + add_alert => 0, }, changed => { update => 'Update from a registered user' @@ -277,6 +281,7 @@ for my $test ( { desc => 'submit update for register user and sign up', fields => { + submit_update => 1, rznvy => 'test@example.com', update => 'update from a registered user', add_alert => 1, -- cgit v1.2.3 From b994038f7d169ac6a3bf270c8a371fa7d285e4b2 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 12:29:33 +0100 Subject: anonymous cannot be null --- t/app/controller/report_updates.t | 3 +++ 1 file changed, 3 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 7f6f4dc1a..3c07ac054 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -67,6 +67,7 @@ my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( text => 'This is some update text', state => 'confirmed', confirmed => $dt->ymd . ' ' . $dt->hms, + anonymous => 'f', } ); @@ -152,6 +153,7 @@ subtest "several updates shown in correct order" => sub { text => 'First update', state => 'confirmed', confirmed => '2011-03-10 12:23:15', + anonymous => 'f', }, { problem_id => $report_id, @@ -161,6 +163,7 @@ subtest "several updates shown in correct order" => sub { text => 'Second update', state => 'confirmed', confirmed => '2011-03-10 12:23:16', + anonymous => 'f', }, { problem_id => $report_id, -- cgit v1.2.3 From cfcda98c6859672b843c15407e0c55d39da98b83 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 20 May 2011 16:05:15 +0100 Subject: Added tests for bad requests --- t/app/controller/json.t | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 t/app/controller/json.t (limited to 't/app/controller') diff --git a/t/app/controller/json.t b/t/app/controller/json.t new file mode 100644 index 000000000..e5fda5d27 --- /dev/null +++ b/t/app/controller/json.t @@ -0,0 +1,36 @@ +use strict; +use warnings; + +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +subtest "check that a bad request produces the right response" => sub { + + my $bad_date = "Invalid dates supplied"; + my $bad_type = "Invalid type supplied"; + + my %tests = ( + '' => $bad_date, + 'foo=bar' => $bad_date, + 'type=&start_date=&end_date=' => $bad_date, + 'type=&start_date=bad&end_date=2000-02-01' => $bad_date, + 'type=&start_date=2000-01-01&end_date=bad' => $bad_date, + 'type=&start_date=2000-02-31&end_date=2000-02-01' => $bad_date, + 'type=&start_date=2000-01-01&end_date=2000-02-31' => $bad_date, + + 'type=&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, + 'type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, + ); + + foreach my $q ( sort keys %tests ) { + is_deeply # + $mech->get_ok_json("/json?$q"), # + { error => $tests{$q} }, # + "correct error for query '$q'"; + } + +}; + +done_testing(); -- cgit v1.2.3 From 285b42fd8e8a5f4099c8163ee4a7c89813111c80 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 17:04:10 +0100 Subject: rss implemented --- t/app/controller/alert.t | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 2f25a1c23..f32d0d6e9 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -51,20 +51,16 @@ $mech->content_contains('Please select the feed you want'); $mech->get_ok('/alert/subscribe?rss=1&feed=invalid:1000:A_Locationtype=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy='); $mech->content_contains('Illegal feed selection'); -TODO: { - local $TODO = 'not implemented rss feeds yet'; +$mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:A_Location'); +$mech->uri->path('/rss/area/A+Location'); - $mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:A_Location'); - $mech->uri->path('/rss/area/A+Location'); +$mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:1001:A_Location:Diff_Location'); +$mech->uri->path('/rss/area/A+Location/Diff+Location'); - $mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:1001:A_Location:Diff_Location'); - $mech->uri->path('/rss/area/A+Location/Diff+Location'); +$mech->get_ok('/alert/subscribe?rss=1&feed=council:1000:A_Location'); +$mech->uri->path('/rss/reports/A+Location'); - $mech->get_ok('/alert/subscribe?rss=1&feed=council:1000:A_Location'); - $mech->uri->path('/rss/reports/A+Location'); - - $mech->get_ok('/alert/subscribe?rss=1&feed=ward:1000:1001:A_Location:Diff_Location'); - $mech->uri->path('/rss/ward/A+Location/Diff+Location'); -} +$mech->get_ok('/alert/subscribe?rss=1&feed=ward:1000:1001:A_Location:Diff_Location'); +$mech->uri->path('/rss/ward/A+Location/Diff+Location'); done_testing(); -- cgit v1.2.3 From fb2eae201d01d285ac2b21fd32c2ff35a6f7aae5 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 17:17:12 +0100 Subject: update confirmation from tokens --- t/app/controller/report_updates.t | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 3c07ac054..8c34541ed 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -265,6 +265,13 @@ subtest "submit an update for a non registered user" => sub { is $update->user->email, 'unregistered@example.com', 'update email'; is $update->text, 'Update from an unregistered user', 'update text'; is $add_alerts, 0, 'do not sign up for alerts'; + + $mech->get_ok( $url . $url_token ); + $mech->content_contains( "/report/$report_id#$update_id" ); + + $update->discard_changes; + + is $update->state, 'confirmed', 'update confirmed'; }; for my $test ( -- cgit v1.2.3 From 1e67ddbedf6481e3e8650a498679eafd710230ca Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 20 May 2011 17:33:34 +0100 Subject: port json.cgi code to Catalyst --- t/app/controller/json.t | 75 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/json.t b/t/app/controller/json.t index e5fda5d27..2c9ff4a61 100644 --- a/t/app/controller/json.t +++ b/t/app/controller/json.t @@ -6,9 +6,10 @@ use Test::More; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -subtest "check that a bad request produces the right response" => sub { +subtest "check that a bad request produces the appropriate response" => sub { my $bad_date = "Invalid dates supplied"; + my $mad_date = "Start date after end date"; my $bad_type = "Invalid type supplied"; my %tests = ( @@ -20,6 +21,8 @@ subtest "check that a bad request produces the right response" => sub { 'type=&start_date=2000-02-31&end_date=2000-02-01' => $bad_date, 'type=&start_date=2000-01-01&end_date=2000-02-31' => $bad_date, + 'type=&start_date=2000-02-01&end_date=2000-01-01' => $mad_date, + 'type=&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, 'type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, ); @@ -33,4 +36,74 @@ subtest "check that a bad request produces the right response" => sub { }; +is_deeply # + $mech->get_ok_json( + "/json?type=new_problems&start_date=2000-01-01&end_date=2000-02-01"), # + [], # + "correct response"; + +# put an entry in the database for this test +my $user = $mech->create_user_ok('test@example.com'); + +my $problem_args = { + postcode => 'sw1a 1aa', + council => '2501', + areas => ',105164,11806,11827,2247,2501,34817,42011,66045,70786,8519,', + category => 'test category', + title => 'Test title', + detail => 'Test detail', + used_map => 't', + name => 'Test Name', + created => '2000-01-01 12:00:00', + confirmed => '2000-01-01 12:01:00', + state => 'confirmed', + lang => 'en-gb', + service => '', + cobrand => '', + cobrand_data => '', + lastupdate => '2000-01-01 12:00:00', + whensent => undef, + send_questionnaire => 't', + latitude => '51.4531988729771', + longitude => '-0.23021896608596', +}; +my $problem = $user->add_to_problems( { %$problem_args, anonymous => 0 } ); +my $anon_problem = $user->add_to_problems( { %$problem_args, anonymous => 1 } ); + +ok $problem, "created normal test problem"; +ok $anon_problem, "created anon test problem"; + +is_deeply # + $mech->get_ok_json( + "/json?type=new_problems&start_date=2000-01-01&end_date=2000-02-01"), # + [ + { + 'anonymous' => 0, + 'category' => 'test category', + 'confirmed' => '2000-01-01 12:01:00', + 'council' => 'Wandsworth Borough Council', + 'detail' => 'Test detail', + 'id' => $problem->id, + 'name' => 'Test Name', + 'service' => 'Web interface', + 'title' => 'Test title', + 'whensent' => undef + }, + { + 'anonymous' => 1, + 'category' => 'test category', + 'confirmed' => '2000-01-01 12:01:00', + 'council' => 'Wandsworth Borough Council', + 'detail' => 'Test detail', + 'id' => $anon_problem->id, + 'name' => '', + 'service' => 'Web interface', + 'title' => 'Test title', + 'whensent' => undef + } + ], + "correct response"; + +$mech->delete_user($user); + done_testing(); -- cgit v1.2.3 From 8fbb9539e8ada7faf6c54c40bda7d059bdfd0c12 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sat, 21 May 2011 00:29:08 +0100 Subject: Fix bug whereby 'old and of unknown status' was shown on all open reports. --- t/app/controller/report_display.t | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index aa7e507d9..1f857a387 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -189,6 +189,14 @@ foreach my $meta ( } for my $test ( + { + description => 'new report', + date => DateTime->now, + state => 'confirmed', + banner_id => '', + banner_text => '', + fixed => 0 + }, { description => 'old report', date => DateTime->new( @@ -230,6 +238,7 @@ for my $test ( ) { subtest "banner for $test->{description}" => sub { $report->confirmed( $test->{date}->ymd . ' ' . $test->{date}->hms ); + $report->lastupdate( $test->{date}->ymd . ' ' . $test->{date}->hms ); $report->state( $test->{state} ); $report->update; -- cgit v1.2.3 From 9b12f95ffb23f7a1e45f47c0bf860ed348ddbf39 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 23 May 2011 11:39:05 +0100 Subject: Add a may show name publicly checkbox to updates form --- t/app/controller/report_updates.t | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 8c34541ed..ccbdfd9bf 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -277,29 +277,136 @@ subtest "submit an update for a non registered user" => sub { for my $test ( { desc => 'submit update for register user', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from a registered user', + add_alert => 0, + fixed => 0, + }, + changed => { + update => 'Update from a registered user' + }, + initial_banner => '', + endstate_banner => '', + alert => 0, + anonymous => 0, + }, + { + desc => 'submit update for register user anonymously by unchecking', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from a registered user', + may_show_name => 0, + add_alert => 0, + fixed => 0, + }, + changed => { + update => 'Update from a registered user' + }, + initial_banner => '', + endstate_banner => '', + alert => 0, + anonymous => 1, + }, + { + desc => 'submit update for register user anonymously by deleting name', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, fields => { submit_update => 1, + name => '', rznvy => 'test@example.com', update => 'update from a registered user', + may_show_name => 1, add_alert => 0, + fixed => 0, }, changed => { update => 'Update from a registered user' }, + initial_banner => '', + endstate_banner => '', alert => 0, + anonymous => 1, }, { desc => 'submit update for register user and sign up', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, fields => { submit_update => 1, rznvy => 'test@example.com', update => 'update from a registered user', add_alert => 1, + fixed => 0, }, changed => { update => 'Update from a registered user' }, + initial_banner => '', + endstate_banner => '', alert => 1, + anonymous => 0, + }, + { + desc => 'submit update for register user and mark fixed', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from a registered user', + add_alert => 0, + fixed => 1, + }, + changed => { + update => 'Update from a registered user' + }, + initial_banner => '', + endstate_banner => ' This problem has been fixed. ', + alert => 1, # we signed up for alerts before, do not unsign us + anonymous => 0, }, ) { subtest $test->{desc} => sub { @@ -313,6 +420,12 @@ for my $test ( $mech->log_in_ok( $user->email ); $mech->get_ok("/report/$report_id"); + my $values = $mech->visible_form_values( 'updateForm' ); + + is_deeply $values, $test->{initial_values}, 'initial form values'; + + is $mech->extract_problem_banner->{text}, $test->{initial_banner}, 'initial banner'; + $mech->submit_form_ok( { with_fields => $test->{fields}, @@ -322,6 +435,8 @@ for my $test ( is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; + is $mech->extract_problem_banner->{text}, $test->{endstate_banner}, 'submitted banner'; + $mech->email_count_is(0); my $results = { @@ -334,6 +449,7 @@ for my $test ( is $update->text, $results->{update}, 'update text'; is $update->user->email, 'test@example.com', 'update user'; is $update->state, 'confirmed', 'update confirmed'; + is $update->anonymous, $test->{anonymous}, 'user anonymous'; my $alert = FixMyStreet::App->model('DB::Alert') -- cgit v1.2.3 From ebba62505cf7e9d3b9ef4ea6aa97cd62eda6c2d7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 23 May 2011 12:58:15 +0100 Subject: tests for correctly normalising fields and resulting bugfixes --- t/app/controller/report_updates.t | 83 ++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 10 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index ccbdfd9bf..6e93a7d74 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -192,30 +192,81 @@ subtest "several updates shown in correct order" => sub { for my $test ( { + desc => 'No email, no message', fields => { rznvy => '', update => '', name => '', + photo => '', + fixed => undef, + add_alert => 1, + may_show_name => undef, }, + changes => {}, field_errors => [ 'Please enter your email', 'Please enter a message' ] }, { + desc => 'Invalid email, no message', fields => { rznvy => 'test', update => '', name => '', + photo => '', + fixed => undef, + add_alert => 1, + may_show_name => undef, }, + changes => {}, field_errors => [ 'Please enter a valid email', 'Please enter a message' ] }, + { + desc => 'email with spaces, no message', + fields => { + rznvy => 'test @ example. com', + update => '', + name => '', + photo => '', + fixed => undef, + add_alert => 1, + may_show_name => undef, + }, + changes => { + rznvy => 'test@example.com', + }, + field_errors => [ 'Please enter a message' ] + }, + { + desc => 'email with uppercase, no message', + fields => { + rznvy => 'test@EXAMPLE.COM', + update => '', + name => '', + photo => '', + fixed => undef, + add_alert => 1, + may_show_name => undef, + }, + changes => { + rznvy => 'test@example.com', + }, + field_errors => [ 'Please enter a message' ] + }, ) { - subtest "submit an update" => sub { + subtest "submit an update - $test->{desc}" => sub { $mech->get_ok("/report/$report_id"); $mech->submit_form_ok( { with_fields => $test->{fields} }, 'submit update' ); is_deeply $mech->form_errors, $test->{field_errors}, 'field errors'; + + my $values = { + %{ $test->{fields} }, + %{ $test->{changes} }, + }; + + is_deeply $mech->visible_form_values('updateForm'), $values, 'form changes'; }; } @@ -224,13 +275,27 @@ subtest "submit an update for a non registered user" => sub { $mech->get_ok("/report/$report_id"); + my $values = $mech->visible_form_values('updateForm'); + + is_deeply $values, + { + name => '', + rznvy => '', + may_show_name => undef, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + 'initial form values'; + $mech->submit_form_ok( { with_fields => { submit_update => 1, - rznvy => 'unregistered@example.com', - update => 'update from an unregistered user', - add_alert => 0, + rznvy => 'unregistered@example.com', + update => 'update from an unregistered user', + add_alert => 0, } }, 'submit update' @@ -242,7 +307,6 @@ subtest "submit an update for a non registered user" => sub { ok $email, "got an email"; like $email->body, qr/confirm the update you/i, "Correct email text"; - my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)}; ok $url, "extracted confirm url '$url'"; @@ -254,11 +318,10 @@ subtest "submit an update for a non registered user" => sub { ); ok $token, 'Token found in database'; - my $update_id = $token->data->{id}; + my $update_id = $token->data->{id}; my $add_alerts = $token->data->{add_alert}; - my $update = FixMyStreet::App->model( 'DB::Comment' )->find( - { id => $update_id } - ); + my $update = + FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } ); ok $update, 'found update in database'; is $update->state, 'unconfirmed', 'update unconfirmed'; @@ -267,7 +330,7 @@ subtest "submit an update for a non registered user" => sub { is $add_alerts, 0, 'do not sign up for alerts'; $mech->get_ok( $url . $url_token ); - $mech->content_contains( "/report/$report_id#$update_id" ); + $mech->content_contains("/report/$report_id#$update_id"); $update->discard_changes; -- cgit v1.2.3 From 388a9b16d9dfa25b4854c8a3685dc3c764c391a5 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 24 May 2011 13:05:51 +0100 Subject: Move lat/lon to templates and use shortened forms. --- t/app/controller/around.t | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 069ec605a..76f504d7e 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -75,18 +75,18 @@ foreach my $test ( foreach my $test ( { pc => 'SW1A 1AA', - latitude => '51.5010096115539', - longitude => '-0.141587067110009', + latitude => '51.50101', + longitude => '-0.141587', }, { pc => 'Manchester', - latitude => '53.4807125', - longitude => '-2.2343765', + latitude => '53.480713', + longitude => '-2.234376', }, { pc => 'Glenthorpe Rd, Merton, Greater London SM4 4, UK', - latitude => '51.3937997', - longitude => '-0.2209596', + latitude => '51.3938', + longitude => '-0.22096', }, ) { -- cgit v1.2.3 From 7b0d984bd9607e5b7e12184f1d91bc52a0280417 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 24 May 2011 13:14:45 +0100 Subject: google maps don't seem to pay as much attention to region hinting as they once did so make sure we add UK on to the end. also update tests to take into account changed results because of this. --- t/app/controller/around.t | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 069ec605a..12b26cec7 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -43,19 +43,22 @@ foreach my $test ( { pc => 'glenthorpe', errors => [], - pc_alternatives => [ # TODO - should filter out these non-UK addresses + pc_alternatives => [ 'Glenthorpe Crescent, Leeds LS9 7', 'Glenthorpe Rd, Merton, Greater London SM4 4', - 'Glenthorpe Ln, Katy, TX 77494, USA', - 'Glenthorpe Dr, Walnut, CA 91789, USA', 'Glenthorpe Ave, Leeds LS9 7', - 'Glenthorpe Ct, Katy, TX 77494, USA', + 'Glenthorne Rd, Hammersmith, Greater London W6 0', + 'Glenthorne Ave, Yeovil, Somerset BA21 4', + 'Glenthorne Rd, Kenwyn, Cornwall TR3 6', + 'Glenthorne Dr, Cheslyn Hay, Staffordshire WS6 7', + 'Glenthorne Gardens, Ilford, Greater London IG5 0', + 'Glenthorne Ave, Croydon, Greater London CR0 7', ], }, { pc => 'Glenthorpe Ct, Katy, TX 77494, USA', errors => - ['We had a problem with the supplied co-ordinates - outside the UK?'], + ['Sorry, we could not find that location.'], pc_alternatives => [], }, ) -- cgit v1.2.3 From 02de04c365b8d7e8323e556b6258c1c92ba672e6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 24 May 2011 17:41:48 +0100 Subject: if the person who created the problem is marking it as fixed show them a questionnaire directly ( no submission yet ) --- t/app/controller/report_updates.t | 92 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 5 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 6e93a7d74..3815fb14f 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -448,8 +448,8 @@ for my $test ( { desc => 'submit update for register user and mark fixed', initial_values => { - name => 'Test User', - rznvy => 'test@example.com', + name => 'Commenter', + rznvy => 'commenter@example.com', may_show_name => 1, add_alert => 1, photo => '', @@ -458,7 +458,7 @@ for my $test ( }, fields => { submit_update => 1, - rznvy => 'test@example.com', + rznvy => 'commenter@example.com', update => 'update from a registered user', add_alert => 0, fixed => 1, @@ -480,7 +480,7 @@ for my $test ( $mech->clear_emails_ok(); - $mech->log_in_ok( $user->email ); + $mech->log_in_ok( $test->{fields}->{rznvy} ); $mech->get_ok("/report/$report_id"); my $values = $mech->visible_form_values( 'updateForm' ); @@ -498,6 +498,10 @@ for my $test ( is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; + if ( $mech->uri->path eq '/report/update' ) { + print $mech->content; + } + is $mech->extract_problem_banner->{text}, $test->{endstate_banner}, 'submitted banner'; $mech->email_count_is(0); @@ -510,7 +514,7 @@ for my $test ( my $update = $report->comments->first; ok $update, 'found update'; is $update->text, $results->{update}, 'update text'; - is $update->user->email, 'test@example.com', 'update user'; + is $update->user->email, $test->{fields}->{rznvy}, 'update user'; is $update->state, 'confirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; @@ -522,6 +526,84 @@ for my $test ( }; } +foreach my $test ( + { + desc => 'reporter submit update mark fixed', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from owner', + add_alert => 0, + fixed => 1, + }, + changed => { + update => 'Update from owner' + }, + initial_banner => '', + alert => 1, # we signed up for alerts before, do not unsign us + anonymous => 0, + }, +) { + subtest $test->{desc} => sub { + # clear out comments for this problem to make + # checking details easier later + ok( $_->delete, 'deleted comment ' . $_->id ) + for $report->comments; + + $report->discard_changes; + $report->state('confirmed'); + $report->update; + + $report->discard_changes; + print 'state is ' . $report->state . "\n"; + + $mech->clear_emails_ok(); + + $mech->log_in_ok( $test->{fields}->{rznvy} ); + $mech->get_ok("/report/$report_id"); + + my $values = $mech->visible_form_values( 'updateForm' ); + + is_deeply $values, $test->{initial_values}, 'initial form values'; + + is $mech->extract_problem_banner->{text}, $test->{initial_banner}, 'initial banner'; + + $mech->submit_form_ok( + { + with_fields => $test->{fields}, + }, + 'submit update' + ); + + is $mech->uri->path, "/report/update", "display questionnaire"; + + $mech->content_contains("Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?"); + + $mech->email_count_is(0); + + my $results = { + %{ $test->{fields} }, + %{ $test->{changed} }, + }; + + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, $results->{update}, 'update text'; + is $update->user->email, $test->{fields}->{rznvy}, 'update user'; + is $update->state, 'confirmed', 'update confirmed'; + is $update->anonymous, $test->{anonymous}, 'user anonymous'; + }; +} + ok $comment->delete, 'deleted comment'; $mech->delete_user('commenter@example.com'); $mech->delete_user('test@example.com'); -- cgit v1.2.3 From ef849541cbe7b200db1bd4af6cdc67e3061d1486 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 25 May 2011 11:51:44 +0100 Subject: don't ask questionnaire if they've ever answered before --- t/app/controller/report_updates.t | 106 ++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 32 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 3815fb14f..f921b9ebb 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -528,72 +528,109 @@ for my $test ( foreach my $test ( { - desc => 'reporter submit update mark fixed', + desc => 'reporter submits update and marks problem fixed', initial_values => { - name => 'Test User', - rznvy => 'test@example.com', + name => 'Test User', + rznvy => 'test@example.com', may_show_name => 1, - add_alert => 1, - photo => '', - update => '', - fixed => undef, + add_alert => 1, + photo => '', + update => '', + fixed => undef, }, fields => { submit_update => 1, - rznvy => 'test@example.com', - update => 'update from owner', - add_alert => 0, - fixed => 1, + rznvy => 'test@example.com', + update => 'update from owner', + add_alert => 0, + fixed => 1, }, - changed => { - update => 'Update from owner' + changed => { update => 'Update from owner' }, + initial_banner => '', + alert => 1, # we signed up for alerts before, do not unsign us + anonymous => 0, + answered => 0, + path => '/report/update', + content => +"Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?", + }, + { + desc => +'reporter submits update and marks problem fixed and has answered questionnaire', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from owner', + add_alert => 0, + fixed => 1, + }, + changed => { update => 'Update from owner' }, initial_banner => '', - alert => 1, # we signed up for alerts before, do not unsign us + alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, + answered => 1, + path => '/report/' . $report->id, + content => $report->title, }, -) { + ) +{ subtest $test->{desc} => sub { + # clear out comments for this problem to make # checking details easier later - ok( $_->delete, 'deleted comment ' . $_->id ) - for $report->comments; + ok( $_->delete, 'deleted comment ' . $_->id ) for $report->comments; $report->discard_changes; $report->state('confirmed'); $report->update; + my $questionnaire; + if ( $test->{answered} ) { + $questionnaire = + FixMyStreet::App->model('DB::Questionnaire')->create( + { + problem_id => $report_id, + ever_reported => 'y', + whensent => \'ms_current_timestamp()', + } + ); + + ok $questionnaire, 'added questionnaire'; + } + $report->discard_changes; - print 'state is ' . $report->state . "\n"; $mech->clear_emails_ok(); $mech->log_in_ok( $test->{fields}->{rznvy} ); $mech->get_ok("/report/$report_id"); - my $values = $mech->visible_form_values( 'updateForm' ); + my $values = $mech->visible_form_values('updateForm'); is_deeply $values, $test->{initial_values}, 'initial form values'; - is $mech->extract_problem_banner->{text}, $test->{initial_banner}, 'initial banner'; + is $mech->extract_problem_banner->{text}, $test->{initial_banner}, + 'initial banner'; - $mech->submit_form_ok( - { - with_fields => $test->{fields}, - }, - 'submit update' - ); + $mech->submit_form_ok( { with_fields => $test->{fields}, }, + 'submit update' ); - is $mech->uri->path, "/report/update", "display questionnaire"; + is $mech->uri->path, $test->{path}, "page after submission"; - $mech->content_contains("Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?"); + $mech->content_contains( $test->{content} ); $mech->email_count_is(0); - my $results = { - %{ $test->{fields} }, - %{ $test->{changed} }, - }; + my $results = { %{ $test->{fields} }, %{ $test->{changed} }, }; my $update = $report->comments->first; ok $update, 'found update'; @@ -601,6 +638,11 @@ foreach my $test ( is $update->user->email, $test->{fields}->{rznvy}, 'update user'; is $update->state, 'confirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; + + if ($questionnaire) { + $questionnaire->delete; + ok !$questionnaire->in_storage, 'questionnaire deleted'; + } }; } -- cgit v1.2.3 From 6a679dbe9f0d7021f176ca23106a74bc2475539e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 25 May 2011 16:43:28 +0100 Subject: submission for questionnaire when problem owner marks it fixed --- t/app/controller/report_updates.t | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index f921b9ebb..1836423ba 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -498,10 +498,6 @@ for my $test ( is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; - if ( $mech->uri->path eq '/report/update' ) { - print $mech->content; - } - is $mech->extract_problem_banner->{text}, $test->{endstate_banner}, 'submitted banner'; $mech->email_count_is(0); @@ -639,6 +635,27 @@ foreach my $test ( is $update->state, 'confirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; + SKIP: { + skip( 'not answering questionnaire', 5 ) if $questionnaire; + + $mech->submit_form_ok( ); + + my @errors = @{ $mech->page_errors }; + ok scalar @errors, 'displayed error messages'; + is $errors[0], "Please say whether you've ever reported a problem to your council before", 'error message'; + + $mech->submit_form_ok( { with_fields => { reported => 'Yes' } } ); + + $mech->content_contains( 'Thank you — you can' ); + + $questionnaire = FixMyStreet::App->model( 'DB::Questionnaire' )->find( + { problem_id => $report_id } + ); + + ok $questionnaire, 'questionnaire exists'; + ok $questionnaire->ever_reported, 'ever reported is yes'; + }; + if ($questionnaire) { $questionnaire->delete; ok !$questionnaire->in_storage, 'questionnaire deleted'; -- cgit v1.2.3 From bbe4d5975fddfc731b0177119bf4cda401d41d97 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 25 May 2011 16:58:31 +0100 Subject: check that flow is the same regardless of whether user is logged in --- t/app/controller/report_updates.t | 63 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 1836423ba..89ce9b6ae 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -523,6 +523,62 @@ for my $test ( } foreach my $test ( + { + desc => 'logged in reporter submits update and marks problem fixed', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from owner', + add_alert => 0, + fixed => 1, + }, + changed => { update => 'Update from owner' }, + initial_banner => '', + alert => 1, # we signed up for alerts before, do not unsign us + anonymous => 0, + answered => 0, + login => 1, + path => '/report/update', + content => +"Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?", + }, + { + desc => +'logged in reporter submits update and marks problem fixed and has answered questionnaire', + initial_values => { + name => 'Test User', + rznvy => 'test@example.com', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + fields => { + submit_update => 1, + rznvy => 'test@example.com', + update => 'update from owner', + add_alert => 0, + fixed => 1, + }, + changed => { update => 'Update from owner' }, + initial_banner => '', + alert => 1, # we signed up for alerts before, do not unsign us + anonymous => 0, + answered => 1, + login => 1, + path => '/report/' . $report->id, + content => $report->title, + }, { desc => 'reporter submits update and marks problem fixed', initial_values => { @@ -546,6 +602,7 @@ foreach my $test ( alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, answered => 0, + login => 0, path => '/report/update', content => "Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?", @@ -574,6 +631,7 @@ foreach my $test ( alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, answered => 1, + login => 0, path => '/report/' . $report->id, content => $report->title, }, @@ -607,7 +665,10 @@ foreach my $test ( $mech->clear_emails_ok(); - $mech->log_in_ok( $test->{fields}->{rznvy} ); + SKIP: { + skip 'not logging user in', 1 unless $test->{login}; + $mech->log_in_ok( $test->{fields}->{rznvy} ); + }; $mech->get_ok("/report/$report_id"); my $values = $mech->visible_form_values('updateForm'); -- cgit v1.2.3 From 09a64afec4e023a184de075df3780c8b525b6066 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 25 May 2011 17:44:37 +0100 Subject: use c->send_email on contact page and add more tests --- t/app/controller/contact.t | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 860ada4ce..fbf794b6b 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -163,13 +163,13 @@ for my $test ( subtest 'check submit page error handling' => sub { $mech->get_ok( $test->{url} ? $test->{url} : '/contact' ); $mech->submit_form_ok( { with_fields => $test->{fields} } ); - is_deeply $mech->page_errors, $test->{page_errors}; - is_deeply $mech->form_errors, $test->{field_errors}; + is_deeply $mech->page_errors, $test->{page_errors}, 'page errors'; + is_deeply $mech->form_errors, $test->{field_errors}, 'field_errors'; # we santise this when we submit so need to remove it delete $test->{fields}->{id} if $test->{fields}->{id} and $test->{fields}->{id} eq 'invalid'; - is_deeply $mech->visible_form_values, $test->{fields}; + is_deeply $mech->visible_form_values, $test->{fields}, 'form values'; }; } @@ -186,9 +186,18 @@ for my $test ( ) { subtest 'check email sent correctly' => sub { + $mech->clear_emails_ok; $mech->get_ok('/contact'); $mech->submit_form_ok( { with_fields => $test->{fields} } ); $mech->content_contains('Thanks for your feedback'); + $mech->email_count_is(1); + + my $email = $mech->get_email; + + is $email->header('Subject'), 'FMS message: ' . $test->{fields}->{subject}, 'subject'; + is $email->header('From'), "\"$test->{fields}->{name}\" <$test->{fields}->{em}>", 'from'; + like $email->body, qr/$test->{fields}->{message}/, 'body'; + like $email->body, qr/Sent by contact.cgi on \S+. IP address (?:\d{1,3}\.){3,}\d{1,3}/, 'body footer' }; } done_testing(); -- cgit v1.2.3 From 0030a9d9760c1f8733fb5b64486aaa634d1023bb Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 26 May 2011 13:12:47 +0100 Subject: update reporting --- t/app/controller/contact.t | 54 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index fbf794b6b..73660306d 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -31,6 +31,21 @@ for my $test ( anonymous => 1, meta => 'Reported anonymously at 13:24, Tuesday 3 May 2011', }, + { + name => 'A User', + email => 'problem_report_test@example.com', + title => 'A different problem', + detail => 'More detail on the different problem', + postcode => 'EH99 1SP', + confirmed => '2011-05-03 13:24:28.145168', + anonymous => 1, + meta => 'Reported anonymously at 13:24, Tuesday 3 May 2011', + update => { + name => 'Different User', + email => 'commenter@example.com', + text => 'This is an update', + }, + }, ) { subtest 'check reporting a problem displays correctly' => sub { @@ -58,13 +73,44 @@ for my $test ( } ); + my $update; + + if ( $test->{update} ) { + my $update_info = $test->{update}; + my $update_user = FixMyStreet::App->model('DB::User')->find_or_create( + { + name => $update_info->{name}, + email => $update_info->{email} + } + ); + + $update = FixMyStreet::App->model('DB::Comment')->create( + { + problem_id => $problem->id, + user => $update_user, + state => 'confirmed', + text => $update_info->{text}, + confirmed => \'ms_current_timestamp()', + mark_fixed => 'f', + anonymous => 'f', + } + ); + } + ok $problem, 'succesfully create a problem'; - $mech->get_ok( '/contact?id=' . $problem->id ); - $mech->content_contains('reporting the following problem'); - $mech->content_contains( $test->{title} ); - $mech->content_contains( $test->{meta} ); + if ( $update ) { + $mech->get_ok( '/contact?id=' . $problem->id . '&update_id=' . $update->id ); + $mech->content_contains('reporting the following update'); + $mech->content_contains( $test->{update}->{text} ); + } else { + $mech->get_ok( '/contact?id=' . $problem->id ); + $mech->content_contains('reporting the following problem'); + $mech->content_contains( $test->{title} ); + $mech->content_contains( $test->{meta} ); + } + $update->delete if $update; $problem->delete; }; } -- cgit v1.2.3 From 408b256e4f863a43c4f81209106b4ac23aaa666a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 26 May 2011 14:33:50 +0100 Subject: If the user already exists in the database then don't sent them a confirmation email when signing up to alerts --- t/app/controller/alert_new.t | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 7cbf6188a..4b23cb950 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -181,7 +181,7 @@ foreach my $test ( alert_type => $type, parameter => $test->{param1}, parameter2 => $test->{param2}, - confirmed => 0, + confirmed => 1, } ); @@ -209,6 +209,8 @@ foreach my $test ( $mech->log_in_ok( $test->{email} ); + $mech->clear_emails_ok; + my $alert; if ($user) { $alert = FixMyStreet::App->model('DB::Alert')->find( @@ -237,11 +239,14 @@ foreach my $test ( alert_type => $type, parameter => $test->{param1}, parameter2 => $test->{param2}, - confirmed => 0, + confirmed => 1, } ); ok $alert, 'New alert created with existing user'; + + $mech->email_count_is(0); + }; } -- cgit v1.2.3 From 860f2965f9af0699a40e022ba7c7370a304a4313 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 26 May 2011 17:17:24 +0100 Subject: use moose role for is_from_abuser method --- t/app/controller/alert_new.t | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 4b23cb950..3d06594de 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -250,4 +250,83 @@ foreach my $test ( }; } +for my $test ( + { + email => 'test@example.com', + type => 'new_updates', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + uri => '/alert/subscribe?type=updates&rznvy=test@example.com&id=1', + param1 => 1, + } + ) +{ + subtest "cannot sign up for alert if in abuse table" => sub { + $mech->clear_emails_ok; + + my $type = $test->{type}; + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => $test->{email} } ); + + # we don't want an alert + my $alert; + if ($user) { + $mech->delete_user($user); + } + + my $abuse = + FixMyStreet::App->model('DB::Abuse') + ->find_or_create( { email => $test->{email} } ); + + $mech->get_ok( $test->{uri} ); + $mech->content_contains( $test->{content} ); + + $user = + FixMyStreet::App->model('DB::User') + ->find( { email => $test->{email} } ); + + ok $user, 'user created for alert'; + + $alert = FixMyStreet::App->model('DB::Alert')->find( + { + user => $user, + alert_type => $type, + parameter => $test->{param1}, + parameter2 => $test->{param2}, + confirmed => 0, + } + ); + + ok $alert, "Found the alert"; + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/$test->{email_text}/i, "Correct email text"; + + my ( $url, $url_token ) = $email->body =~ m{(http://\S+/A/)(\S+)}; + ok $url, "extracted confirm url '$url'"; + + my $token = FixMyStreet::App->model('DB::Token')->find( + { + token => $url_token, + scope => 'alert' + } + ); + ok $token, 'Token found in database'; + ok $alert->id == $token->data->{id}, 'token alertid matches alert id'; + + $mech->clear_emails_ok; + + $mech->get_ok("/A/$url_token"); + $mech->content_contains('error confirming'); + + $alert->discard_changes; + + ok !$alert->confirmed, 'alert not set to confirmed'; + + $abuse->delete; + }; +} done_testing(); -- cgit v1.2.3 From 6feb231029baabe551feae478233a4bffb392d9b Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 26 May 2011 19:59:18 +0100 Subject: Unselected checkboxes must be undef, not 0, to pass here, at any rate. --- t/app/controller/report_updates.t | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 89ce9b6ae..a1c630716 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -295,7 +295,7 @@ subtest "submit an update for a non registered user" => sub { submit_update => 1, rznvy => 'unregistered@example.com', update => 'update from an unregistered user', - add_alert => 0, + add_alert => undef, } }, 'submit update' @@ -353,8 +353,8 @@ for my $test ( submit_update => 1, rznvy => 'test@example.com', update => 'update from a registered user', - add_alert => 0, - fixed => 0, + add_alert => undef, + fixed => undef, }, changed => { update => 'Update from a registered user' @@ -379,9 +379,9 @@ for my $test ( submit_update => 1, rznvy => 'test@example.com', update => 'update from a registered user', - may_show_name => 0, - add_alert => 0, - fixed => 0, + may_show_name => undef, + add_alert => undef, + fixed => undef, }, changed => { update => 'Update from a registered user' @@ -408,8 +408,8 @@ for my $test ( rznvy => 'test@example.com', update => 'update from a registered user', may_show_name => 1, - add_alert => 0, - fixed => 0, + add_alert => undef, + fixed => undef, }, changed => { update => 'Update from a registered user' @@ -435,7 +435,7 @@ for my $test ( rznvy => 'test@example.com', update => 'update from a registered user', add_alert => 1, - fixed => 0, + fixed => undef, }, changed => { update => 'Update from a registered user' @@ -460,7 +460,7 @@ for my $test ( submit_update => 1, rznvy => 'commenter@example.com', update => 'update from a registered user', - add_alert => 0, + add_alert => undef, fixed => 1, }, changed => { @@ -538,7 +538,7 @@ foreach my $test ( submit_update => 1, rznvy => 'test@example.com', update => 'update from owner', - add_alert => 0, + add_alert => undef, fixed => 1, }, changed => { update => 'Update from owner' }, @@ -567,7 +567,7 @@ foreach my $test ( submit_update => 1, rznvy => 'test@example.com', update => 'update from owner', - add_alert => 0, + add_alert => undef, fixed => 1, }, changed => { update => 'Update from owner' }, @@ -594,7 +594,7 @@ foreach my $test ( submit_update => 1, rznvy => 'test@example.com', update => 'update from owner', - add_alert => 0, + add_alert => undef, fixed => 1, }, changed => { update => 'Update from owner' }, @@ -623,7 +623,7 @@ foreach my $test ( submit_update => 1, rznvy => 'test@example.com', update => 'update from owner', - add_alert => 0, + add_alert => undef, fixed => 1, }, changed => { update => 'Update from owner' }, -- cgit v1.2.3 From 0c93edcb7b5634f10438d810407b18cb2fa6ba0c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 27 May 2011 11:24:49 +0100 Subject: only confirm alerts on submission if user is logged in also, tests to make sure we send out emails if a logged in user subscribes with a different address --- t/app/controller/alert_new.t | 51 ++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 3d06594de..91e86bd46 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -153,7 +153,9 @@ foreach my $test ( } ) { - subtest "use existing user in a alert" => sub { + subtest "use existing unlogged in user in a alert" => sub { + $mech->log_out_ok(); + my $type = $test->{type} . '_problems'; my $user = @@ -170,7 +172,7 @@ foreach my $test ( ); # clear existing data so we can be sure we're creating it - $alert->delete() if $alert; + ok $alert->delete() if $alert; } $mech->get_ok( $test->{uri} ); @@ -181,41 +183,61 @@ foreach my $test ( alert_type => $type, parameter => $test->{param1}, parameter2 => $test->{param2}, - confirmed => 1, + confirmed => 0, } ); + $mech->content_contains( 'Now check your email' ); + ok $alert, 'New alert created with existing user'; }; } foreach my $test ( { + desc => 'logged in user signing up', + user => 'test-login@example.com', + email => 'test-login@example.com', + type => 'council', + content => 'your alert will not be activated', + email_text => 'confirm the alert', + param1 => 2651, + param2 => 2651, + confirmed => 1, + }, + { + desc => 'logged in user signing up with different email', + user => 'loggedin@example.com', email => 'test-login@example.com', type => 'council', content => 'your alert will not be activated', email_text => 'confirm the alert', param1 => 2651, param2 => 2651, + confirmed => 0, } ) { - subtest "use logged in user in an alert" => sub { + subtest $test->{desc} => sub { my $type = $test->{type} . '_problems'; my $user = FixMyStreet::App->model('DB::User') - ->find_or_create( { email => $test->{email} } ); + ->find_or_create( { email => $test->{user} } ); + + my $alert_user = + FixMyStreet::App->model('DB::User') + ->find( { email => $test->{email} } ); - $mech->log_in_ok( $test->{email} ); + $mech->log_in_ok( $test->{user} ); $mech->clear_emails_ok; my $alert; - if ($user) { + if ($alert_user) { $alert = FixMyStreet::App->model('DB::Alert')->find( { - user => $user, + user => $alert_user, alert_type => $type } ); @@ -227,25 +249,26 @@ foreach my $test ( $mech->get_ok('/alert/list?pc=EH991SP'); my $form_values = $mech->visible_form_values(); - ok $form_values->{rznvy} eq $test->{email}, + ok $form_values->{rznvy} eq $test->{user}, 'auto filled in correct email'; - $mech->set_visible( [ radio => 'council:2651:City_of_Edinburgh' ] ); + $mech->set_visible( [ radio => 'council:2651:City_of_Edinburgh' ], + [ text => $test->{email} ] ); $mech->click('alert'); $alert = FixMyStreet::App->model('DB::Alert')->find( { - user => $user, + user => $alert_user, alert_type => $type, parameter => $test->{param1}, parameter2 => $test->{param2}, - confirmed => 1, + confirmed => $test->{confirmed}, } ); - ok $alert, 'New alert created with existing user'; + ok $alert, 'New alert created with logged in user'; - $mech->email_count_is(0); + $mech->email_count_is( $test->{confirmed} ? 0 : 1 ); }; } -- cgit v1.2.3 From c1d452268803870478c568f1611a7dc7d211a7be Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 27 May 2011 15:21:52 +0100 Subject: make sure you are allowed to answer the questionnaire asked when a problem reporter marks the problem as fixed. --- t/app/controller/report_updates.t | 173 +++++++++++++++++++++++++++++++------- 1 file changed, 142 insertions(+), 31 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index a1c630716..72a120b0e 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -271,6 +271,7 @@ for my $test ( } subtest "submit an update for a non registered user" => sub { + $mech->log_out_ok(); $mech->clear_emails_ok(); $mech->get_ok("/report/$report_id"); @@ -473,6 +474,8 @@ for my $test ( }, ) { subtest $test->{desc} => sub { + $mech->log_out_ok(); + # clear out comments for this problem to make # checking details easier later ok( $_->delete, 'deleted comment ' . $_->id ) @@ -579,20 +582,104 @@ foreach my $test ( path => '/report/' . $report->id, content => $report->title, }, + ) +{ + subtest $test->{desc} => sub { + + # double check + $mech->log_out_ok(); + + # clear out comments for this problem to make + # checking details easier later + ok( $_->delete, 'deleted comment ' . $_->id ) for $report->comments; + + $report->discard_changes; + $report->state('confirmed'); + $report->update; + + my $questionnaire; + if ( $test->{answered} ) { + $questionnaire = + FixMyStreet::App->model('DB::Questionnaire')->create( + { + problem_id => $report_id, + ever_reported => 'y', + whensent => \'ms_current_timestamp()', + } + ); + + ok $questionnaire, 'added questionnaire'; + } + + $report->discard_changes; + + $mech->clear_emails_ok(); + + $mech->log_in_ok( $test->{fields}->{rznvy} ); + $mech->get_ok("/report/$report_id"); + + my $values = $mech->visible_form_values('updateForm'); + + is_deeply $values, $test->{initial_values}, 'initial form values'; + + is $mech->extract_problem_banner->{text}, $test->{initial_banner}, + 'initial banner'; + + $mech->submit_form_ok( { with_fields => $test->{fields}, }, + 'submit update' ); + + is $mech->uri->path, $test->{path}, "page after submission"; + + $mech->content_contains( $test->{content} ); + + $mech->email_count_is(0); + + my $results = { %{ $test->{fields} }, %{ $test->{changed} }, }; + + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, $results->{update}, 'update text'; + is $update->user->email, $test->{fields}->{rznvy}, 'update user'; + is $update->state, 'confirmed', 'update confirmed'; + is $update->anonymous, $test->{anonymous}, 'user anonymous'; + + SKIP: { + skip( 'not answering questionnaire', 5 ) if $questionnaire; + + $mech->submit_form_ok( ); + + my @errors = @{ $mech->page_errors }; + ok scalar @errors, 'displayed error messages'; + is $errors[0], "Please say whether you've ever reported a problem to your council before", 'error message'; + + $mech->submit_form_ok( { with_fields => { reported => 'Yes' } } ); + + $mech->content_contains( 'Thank you — you can' ); + + $questionnaire = FixMyStreet::App->model( 'DB::Questionnaire' )->find( + { problem_id => $report_id } + ); + + ok $questionnaire, 'questionnaire exists'; + ok $questionnaire->ever_reported, 'ever reported is yes'; + }; + + if ($questionnaire) { + $questionnaire->delete; + ok !$questionnaire->in_storage, 'questionnaire deleted'; + } + }; +} + + +for my $test ( { desc => 'reporter submits update and marks problem fixed', - initial_values => { - name => 'Test User', - rznvy => 'test@example.com', - may_show_name => 1, - add_alert => 1, - photo => '', - update => '', - fixed => undef, - }, fields => { submit_update => 1, + name => 'Test User', rznvy => 'test@example.com', + may_show_name => 1, update => 'update from owner', add_alert => undef, fixed => 1, @@ -602,7 +689,6 @@ foreach my $test ( alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, answered => 0, - login => 0, path => '/report/update', content => "Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?", @@ -610,17 +696,10 @@ foreach my $test ( { desc => 'reporter submits update and marks problem fixed and has answered questionnaire', - initial_values => { - name => 'Test User', - rznvy => 'test@example.com', - may_show_name => 1, - add_alert => 1, - photo => '', - update => '', - fixed => undef, - }, fields => { submit_update => 1, + name => 'Test User', + may_show_name => 1, rznvy => 'test@example.com', update => 'update from owner', add_alert => undef, @@ -631,14 +710,16 @@ foreach my $test ( alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, answered => 1, - login => 0, - path => '/report/' . $report->id, - content => $report->title, + path => '/report/update', + content => "You have successfully confirmed your update", }, ) { subtest $test->{desc} => sub { + # double check + $mech->log_out_ok(); + # clear out comments for this problem to make # checking details easier later ok( $_->delete, 'deleted comment ' . $_->id ) for $report->comments; @@ -665,16 +746,10 @@ foreach my $test ( $mech->clear_emails_ok(); - SKIP: { - skip 'not logging user in', 1 unless $test->{login}; - $mech->log_in_ok( $test->{fields}->{rznvy} ); - }; $mech->get_ok("/report/$report_id"); my $values = $mech->visible_form_values('updateForm'); - is_deeply $values, $test->{initial_values}, 'initial form values'; - is $mech->extract_problem_banner->{text}, $test->{initial_banner}, 'initial banner'; @@ -683,9 +758,9 @@ foreach my $test ( is $mech->uri->path, $test->{path}, "page after submission"; - $mech->content_contains( $test->{content} ); + $mech->content_contains( 'Now check your email' ); - $mech->email_count_is(0); + $mech->email_count_is(1); my $results = { %{ $test->{fields} }, %{ $test->{changed} }, }; @@ -693,9 +768,28 @@ foreach my $test ( ok $update, 'found update'; is $update->text, $results->{update}, 'update text'; is $update->user->email, $test->{fields}->{rznvy}, 'update user'; - is $update->state, 'confirmed', 'update confirmed'; + is $update->state, 'unconfirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the update you/i, "Correct email text"; + + my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)}; + ok $url, "extracted confirm url '$url'"; + + my $token = FixMyStreet::App->model('DB::Token')->find( + { + token => $url_token, + scope => 'comment' + } + ); + ok $token, 'Token found in database'; + + $mech->get_ok( '/C/' . $url_token ); + + $mech->content_contains( $test->{content} ); + SKIP: { skip( 'not answering questionnaire', 5 ) if $questionnaire; @@ -724,6 +818,23 @@ foreach my $test ( }; } +subtest 'check have to be logged in for creator fixed questionnaire' => sub { + $mech->log_out_ok(); + + $mech->get_ok( "/questionnaire/submit?problem=$report_id&reported=Yes" ); + + $mech->content_contains( "I'm afraid we couldn't locate your problem in the database." ) +}; + +subtest 'check cannot answer other user\'s creator fixed questionnaire' => sub { + $mech->log_out_ok(); + $mech->log_in_ok( $user2->email ); + + $mech->get_ok( "/questionnaire/submit?problem=$report_id&reported=Yes" ); + + $mech->content_contains( "I'm afraid we couldn't locate your problem in the database." ) +}; + ok $comment->delete, 'deleted comment'; $mech->delete_user('commenter@example.com'); $mech->delete_user('test@example.com'); -- cgit v1.2.3 From 778f6498b17f51aa30a948ede177f0c681c0f228 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 27 May 2011 14:41:15 +0100 Subject: Questionnaire tests, and fixes due to those tests. --- t/app/controller/questionnaire.t | 278 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 t/app/controller/questionnaire.t (limited to 't/app/controller') diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t new file mode 100644 index 000000000..af14332d4 --- /dev/null +++ b/t/app/controller/questionnaire.t @@ -0,0 +1,278 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +use FixMyStreet::App::Controller::Questionnaire; + +ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' ); + +# create a test user and report +$mech->delete_user('test@example.com'); + +my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); +ok $user, "created test user"; + +my $report_time = '2011-03-01 12:00:00'; + +my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'EH1 1BB', + council => '2651', + areas => ',11808,135007,14419,134935,2651,20728,', + category => 'Street lighting', + title => 'Testing', + detail => 'Testing Detail', + used_map => 1, + name => $user->name, + anonymous => 0, + state => 'confirmed', + confirmed => $report_time, + lastupdate => $report_time, + whensent => '2011-03-01 12:05:00', + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 1, + latitude => '55.951963', + longitude => '-3.189944', + user_id => $user->id, + } +); +my $report_id = $report->id; +ok $report, "created test report - $report_id"; + +# FIXME Should call send-questionnaires here to test that is working okay. +# For now, just generate the questionnaire etc. manually. +# Call send-questionnaires (for normal non-EHA site) +# my $email = $mech->get_email; +# ok $email, "got an email"; +# like $email->body, qr/fill in our short questionnaire/i, "got questionnaire email"; +# my ($url) = $email->body =~ m{(http://\S+)}; +# ok $url, "extracted questionnaire url '$url'"; + +$report->send_questionnaire( 0 ); +$report->update; + +my $questionnaire = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( + { + problem_id => $report->id, + whensent => '2011-04-01 12:00:00', + } +); +ok $questionnaire, 'added questionnaire'; +my $token = FixMyStreet::App->model("DB::Token")->create( + { scope => 'questionnaire', data => $questionnaire->id } +); +ok $token, 'added token for questionnaire'; + +foreach my $test ( + { + desc => 'User goes to questionnaire URL with a bad token', + token_extra => 'BAD', + content => "we couldn't validate that token", + }, + { + desc => 'User goes to questionnaire URL for a now-hidden problem', + state => 'hidden', + content => "we couldn't locate your problem", + }, + { + desc => 'User goes to questionnaire URL for an already answered questionnaire', + answered => \'ms_current_timestamp()', + content => 'already answered this questionnaire', + }, +) { + subtest $test->{desc} => sub { + $report->state( $test->{state} || 'confirmed' ); + $report->update; + $questionnaire->whenanswered( $test->{answered} ); + $questionnaire->update; + (my $token = $token->token); + $token .= $test->{token_extra} if $test->{token_extra}; + $mech->get_ok("/Q/$token"); + $mech->content_contains( $test->{content} ); + # Reset, no matter what test did + $report->state( 'confirmed' ); + $report->update; + $questionnaire->whenanswered( undef ); + $questionnaire->update; + }; +} + +$mech->get_ok("/Q/" . $token->token); +$mech->title_like( qr/Questionnaire/ ); +$mech->submit_form_ok( ); +my @errors = @{ $mech->page_errors }; +ok scalar @errors, 'displayed error messages'; +is $errors[0], "Please state whether or not the problem has been fixed", 'error message'; + +foreach my $test ( + { + desc => 'Open report, has been fixed, first time reporter, no update left', + problem_state => 'confirmed', + fields => { + been_fixed => 'Yes', + reported => 'No', + }, + comment => 'Questionnaire filled in by problem reporter', + }, + { + desc => 'Open report, has been fixed, reported before, leaves an update', + problem_state => 'confirmed', + fields => { + been_fixed => 'Yes', + reported => 'Yes', + update => 'The council fixed this really quickly, thanks!', + }, + }, + { + desc => 'Open report, has not been fixed, not reported before, no update, asks for another questionnaire', + problem_state => 'confirmed', + fields => { + been_fixed => 'No', + reported => 'No', + another => 'Yes', + }, + }, + { + desc => 'Open report, unknown fixed, reported before, update, no further questionnaire', + problem_state => 'confirmed', + fields => { + been_fixed => 'Unknown', + reported => 'Yes', + update => 'This is still going on.', + # another => 'No', Error for not setting this tested below + }, + }, + { + desc => 'Fixed report, confirmed fixed, not reported before, no update', + problem_state => 'fixed', + fields => { + been_fixed => 'Yes', + reported => 'No', + }, + lastupdate_static => 1, + }, + { + desc => 'Fixed report, unknown fixed, not reported before, no update, asks for another', + problem_state => 'fixed', + fields => { + been_fixed => 'Unknown', + reported => 'No', + another => 'Yes', + }, + }, + { + desc => 'Fixed report, reopened, reported before, no update, no further questionnaire', + problem_state => 'fixed', + fields => { + been_fixed => 'No', + reported => 'Yes', + another => 'No', + # update => 'Dummy', Error for not setting this tested below + }, + }, +) { + subtest $test->{desc} => sub { + $report->state ( $test->{problem_state} ); + $report->update; + + $mech->get_ok("/Q/" . $token->token); + $mech->title_like( qr/Questionnaire/ ); + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + + # If reopening, we've just submitted without an update. Should cause an error. + if ($test->{problem_state} eq 'fixed' && $test->{fields}{been_fixed} eq 'No') { + my @errors = @{ $mech->page_errors }; + ok scalar @errors, 'displayed error messages'; + is $errors[0], "Please provide some explanation as to why you're reopening this report", 'error message'; + $test->{fields}{update} = 'This has not been fixed.'; + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + } + + # We forgot to say we wanted another questionnaire or not with this test + if ($test->{problem_state} eq 'confirmed' && $test->{fields}{been_fixed} eq 'Unknown') { + my @errors = @{ $mech->page_errors }; + ok scalar @errors, 'displayed error messages'; + is $errors[0], "Please indicate whether you'd like to receive another questionnaire", 'error message'; + $test->{fields}{another} = 'No'; + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + } + + my $result; + $result = 'fixed' if $test->{fields}{been_fixed} eq 'Yes'; + $result = 'confirmed' if $test->{fields}{been_fixed} eq 'No'; + $result = 'unknown' if $test->{fields}{been_fixed} eq 'Unknown'; + + my $another = 0; + $another = 1 if $test->{fields}{another} && $test->{fields}{another} eq 'Yes'; + + # Check the right HTML page has been returned + $mech->content_contains( 'glad to hear it’s been fixed' ) + if $result eq 'fixed'; + $mech->content_contains( 'get some more information about the status of your problem' ) + if $result eq 'unknown'; + $mech->content_contains( "sorry to hear that" ) + if $result eq 'confirmed'; + + # Check the database has the right information + $report->discard_changes; + $questionnaire->discard_changes; + is $report->state, $result eq 'unknown' ? $test->{problem_state} : $result; + is $report->send_questionnaire, $another; + ok DateTime::Format::Pg->format_datetime( $report->lastupdate) gt $report_time, 'lastupdate changed' + unless $test->{fields}{been_fixed} eq 'Unknown' || $test->{lastupdate_static}; + is $questionnaire->old_state, $test->{problem_state}; + is $questionnaire->new_state, $result; + is $questionnaire->ever_reported, $test->{fields}{reported} eq 'Yes' ? 1 : 0; + if ($test->{fields}{update} || $test->{comment}) { + my $c = FixMyStreet::App->model("DB::Comment")->find( + { problem_id => $report->id } + ); + is $c->text, $test->{fields}{update} || $test->{comment}; + } + + # Reset questionnaire for next test + $questionnaire->old_state( undef ); + $questionnaire->new_state( undef ); + $questionnaire->ever_reported( undef ); + $questionnaire->whenanswered( undef ); + $questionnaire->update; + $report->send_questionnaire( 0 ); + $report->lastupdate( $report_time ); + $report->comments->delete; + $report->update; + }; +} + +# EHA extra checking +ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; +$mech->get_ok("/Q/" . $token->token); +$mech->content_contains( 'should have reported what they have done' ); + +# Test already answered the ever reported question, so not shown again +my $questionnaire2 = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( + { + problem_id => $report->id, + whensent => '2011-03-28 12:00:00', + ever_reported => 1, + } +); +ok $questionnaire, 'added another questionnaire'; +ok $mech->host("fixmystreet.com"), 'change host to fixmystreet'; +$mech->get_ok("/Q/" . $token->token); +$mech->title_like( qr/Questionnaire/ ); +$mech->content_contains( 'Has this problem been fixed?' ); +$mech->content_lacks( 'ever reported' ); + +# EHA extra checking +ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; +$mech->get_ok("/Q/" . $token->token); +$mech->content_contains( 'made a lot of progress' ); + +$mech->delete_user('test@example.com'); +done_testing(); -- cgit v1.2.3 From 454a01584b3b9d58b332813f835eae735894f6a1 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sat, 28 May 2011 03:56:11 +0100 Subject: Last bit from master, some LBO handling (note, if other London things come along, this needs work). Also fix completely broken council assignment, categories, and some spacing. --- t/app/controller/report_import.t | 4 ++++ t/app/controller/report_new.t | 13 +++++++++++++ 2 files changed, 17 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 5bd0b21b8..4f225fc5a 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -125,6 +125,7 @@ subtest "Submit a correct entry" => sub { photo => '', phone => '', may_show_name => '1', + category => '-- Pick a category --', }, "check imported fields are shown"; @@ -141,6 +142,7 @@ subtest "Submit a correct entry" => sub { detail => 'This is a test report', phone => '01234 567 890', may_show_name => '1', + category => 'Street lighting', } }, "Update details and save" @@ -208,6 +210,7 @@ subtest "Submit a correct entry (with location)" => sub { photo => '', phone => '', may_show_name => '1', + category => '-- Pick a category --', }, "check imported fields are shown"; @@ -224,6 +227,7 @@ subtest "Submit a correct entry (with location)" => sub { detail => 'This is a test report ll', phone => '01234 567 890', may_show_name => '1', + category => 'Street lighting', } }, "Update details and save" diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 16e8e6445..160d1a156 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -34,6 +34,7 @@ foreach my $test ( may_show_name => '1', email => '', phone => '', + category => 'Street lighting', }, changes => {}, errors => [ @@ -54,6 +55,7 @@ foreach my $test ( may_show_name => undef, email => '', phone => '', + category => 'Street lighting', }, changes => { may_show_name => '1' }, errors => [ @@ -74,6 +76,7 @@ foreach my $test ( may_show_name => undef, email => '', phone => '', + category => 'Street lighting', }, changes => {}, errors => [ @@ -93,6 +96,7 @@ foreach my $test ( may_show_name => '1', email => '', phone => '', + category => 'Street lighting', }, changes => {}, errors => [ @@ -112,6 +116,7 @@ foreach my $test ( may_show_name => '1', email => '', phone => '', + category => 'Street lighting', }, changes => { title => 'Dog poo on walls', @@ -131,6 +136,7 @@ foreach my $test ( may_show_name => '1', email => '', phone => '', + category => 'Street lighting', }, changes => {}, errors => [ @@ -149,6 +155,7 @@ foreach my $test ( may_show_name => '1', email => '', phone => '', + category => 'Street lighting', }, changes => {}, errors => [ @@ -167,6 +174,7 @@ foreach my $test ( may_show_name => '1', email => 'not an email', phone => '', + category => 'Street lighting', }, changes => { email => 'notanemail', }, errors => [ 'Please enter a valid email', ], @@ -182,6 +190,7 @@ foreach my $test ( may_show_name => '1', email => '', phone => '', + category => 'Street lighting', }, changes => { title => 'Test title', @@ -200,6 +209,7 @@ foreach my $test ( may_show_name => '1', email => ' BOB @ExAmplE.COM ', phone => '', + category => 'Street lighting', }, changes => { name => 'Bob Jones', @@ -266,6 +276,7 @@ subtest "test report creation for a user who does not have an account" => sub { may_show_name => '1', email => 'test-1@example.com', phone => '07903 123 456', + category => 'Street lighting', } }, "submit good details" @@ -358,6 +369,7 @@ subtest "test report creation for a user who is logged in" => sub { name => 'Test User', phone => '01234 567 890', photo => '', + category => '-- Pick a category --', }, "user's details prefilled" ); @@ -375,6 +387,7 @@ subtest "test report creation for a user who is logged in" => sub { name => 'Joe Bloggs', may_show_name => '1', phone => '07903 123 456', + category => 'Street lighting', } }, "submit good details" -- cgit v1.2.3 From 2e4241ef11e600dcdf898ca1542f865c0972e4bc Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 1 Jun 2011 17:16:49 +0100 Subject: Tests for correct contacts chosen. --- t/app/controller/report_new.t | 204 ++++++++++++++++++++++++------------------ 1 file changed, 119 insertions(+), 85 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 160d1a156..760dfacc6 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -20,6 +20,36 @@ subtest "test that bare requests to /report/new get redirected" => sub { "pc correctly transferred"; }; +my %contact_params = ( + confirmed => 1, + deleted => 0, + editor => 'Test', + whenedited => \'current_timestamp', + note => 'Created for test', +); +# Let's make some contacts to send things to! +my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2651, # Edinburgh + category => 'Street lighting', + email => 'highways@example.com', +} ); +my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2226, # Gloucestershire + category => 'Potholes', + email => 'potholes@example.com', +} ); +my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2326, # Cheltenham + category => 'Trees', + email => 'trees@example.com', +} ); +ok $contact1, "created test contact 1"; +ok $contact2, "created test contact 2"; +ok $contact3, "created test contact 3"; + # test that the various bit of form get filled in and errors correctly # generated. foreach my $test ( @@ -259,7 +289,7 @@ subtest "test report creation for a user who does not have an account" => sub { # submit initial pc form $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); # click through to the report page @@ -298,6 +328,9 @@ subtest "test report creation for a user who does not have an account" => sub { is $report->state, 'unconfirmed', "report not confirmed"; is $mech->get( '/report/' . $report->id )->code, 404, "report not found"; + # Check the report has been assigned appropriately + is $report->council, 2651; + # receive token my $email = $mech->get_email; ok $email, "got an email"; @@ -312,10 +345,7 @@ subtest "test report creation for a user who does not have an account" => sub { is $report->state, 'confirmed', "Report is now confirmed"; is $report->state, 'confirmed', "report is now confirmed"; - TODO: { - local $TODO = "'/report/<>' not handled by catalyst yet"; - $mech->get_ok( '/report/' . $report->id ); - } + $mech->get_ok( '/report/' . $report->id ); # user is created and logged in $mech->logged_in_ok; @@ -332,92 +362,92 @@ subtest "test report creation for a user who does not have an account" => sub { # report is confirmed #### test report creation for user with account and logged in -subtest "test report creation for a user who is logged in" => sub { - - # check that the user does not exist - my $test_email = 'test-2@example.com'; - - $mech->clear_emails_ok; - my $user = $mech->log_in_ok($test_email); - - # setup the user. - ok $user->update( - { - name => 'Test User', - phone => '01234 567 890', - } - ), - "set users details"; - - # submit initial pc form - $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, - "submit location" ); - - # click through to the report page - $mech->follow_link_ok( { text => 'skip this step', }, - "follow 'skip this step' link" ); - - # check that the fields are correctly prefilled - is_deeply( - $mech->visible_form_values, - { - title => '', - detail => '', - may_show_name => '1', - email => $test_email, - name => 'Test User', - phone => '01234 567 890', - photo => '', - category => '-- Pick a category --', - }, - "user's details prefilled" - ); - - TODO: { - local $TODO = -"'/report/<>' not handled by catalyst yet - form creation redirects to there on success if logged in"; - eval { - $mech->submit_form_ok( - { - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo => '', - name => 'Joe Bloggs', - may_show_name => '1', - phone => '07903 123 456', - category => 'Street lighting', - } - }, - "submit good details" - ); - }; - } - - # find the report - my $report = $user->problems->first; - ok $report, "Found the report"; +foreach my $test ( + { category => 'Trees', council => 2326 }, + { category => 'Potholes', council => 2226 }, +) { + subtest "test report creation for a user who is logged in" => sub { + + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + $mech->clear_emails_ok; + my $user = $mech->log_in_ok($test_email); + + # setup the user. + ok $user->update( + { + name => 'Test User', + phone => '01234 567 890', + } + ), + "set users details"; - # check that we got redirected to /report/ - is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + # submit initial pc form + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, + "submit location" ); - # check that no emails have been sent - $mech->email_count_is(0); + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); - # check report is confirmed and available - is $report->state, 'confirmed', "report is now confirmed"; - TODO: { - local $TODO = "'/report/<>' not handled by catalyst yet"; + # check that the fields are correctly prefilled + is_deeply( + $mech->visible_form_values, + { + title => '', + detail => '', + may_show_name => '1', + email => $test_email, + name => 'Test User', + phone => '01234 567 890', + photo => '', + category => '-- Pick a category --', + }, + "user's details prefilled" + ); + + $mech->submit_form_ok( + { + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => $test->{category}, + } + }, + "submit good details" + ); + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # Check the report has been assigned appropriately + is $report->council, $test->{council}; + + # check that we got redirected to /report/ + is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + + # check that no emails have been sent + $mech->email_count_is(0); + + # check report is confirmed and available + is $report->state, 'confirmed', "report is now confirmed"; $mech->get_ok( '/report/' . $report->id ); - } - # user is still logged in - $mech->logged_in_ok; + # user is still logged in + $mech->logged_in_ok; - # cleanup - $mech->delete_user($user); -}; + # cleanup + $mech->delete_user($user); + }; + +} #### test uploading an image @@ -449,4 +479,8 @@ subtest "check that a lat/lon off coast leads to /around" => sub { }; +$contact1->delete; +$contact2->delete; +$contact3->delete; + done_testing(); -- cgit v1.2.3 From a2d9fe2659a1723824c58d7e3d663d1725bcab56 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 1 Jun 2011 17:28:37 +0100 Subject: mark new_updates alerts as confirmed when they are created --- t/app/controller/report_updates.t | 156 ++++++++++++++++++++++++-------------- 1 file changed, 100 insertions(+), 56 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 72a120b0e..4f7d1628d 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -270,73 +270,117 @@ for my $test ( }; } -subtest "submit an update for a non registered user" => sub { - $mech->log_out_ok(); - $mech->clear_emails_ok(); +for my $test ( + { + desc => 'submit an update for a non registered user', + initial_values => { + name => '', + rznvy => '', + may_show_name => undef, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + form_values => { + submit_update => 1, + rznvy => 'unregistered@example.com', + update => 'Update from an unregistered user', + add_alert => undef, + }, + changes => {}, + }, + { + desc => 'submit an update for a non registered user and sign up', + initial_values => { + name => '', + rznvy => '', + may_show_name => undef, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + form_values => { + submit_update => 1, + rznvy => 'unregistered@example.com', + update => 'update from an unregistered user', + add_alert => 1, + }, + changes => { + update => 'Update from an unregistered user', + }, + } +) { + subtest $test->{desc} => sub { + $mech->log_out_ok(); + $mech->clear_emails_ok(); - $mech->get_ok("/report/$report_id"); + $mech->get_ok("/report/$report_id"); - my $values = $mech->visible_form_values('updateForm'); - - is_deeply $values, - { - name => '', - rznvy => '', - may_show_name => undef, - add_alert => 1, - photo => '', - update => '', - fixed => undef, - }, - 'initial form values'; - - $mech->submit_form_ok( - { - with_fields => { - submit_update => 1, - rznvy => 'unregistered@example.com', - update => 'update from an unregistered user', - add_alert => undef, + my $values = $mech->visible_form_values('updateForm'); + + is_deeply $values, $test->{initial_values}, 'initial form values'; + + $mech->submit_form_ok( + { + with_fields => $test->{form_values} + }, + 'submit update' + ); + + $mech->content_contains('Nearly Done! Now check your email'); + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the update you/i, "Correct email text"; + + my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)}; + ok $url, "extracted confirm url '$url'"; + + my $token = FixMyStreet::App->model('DB::Token')->find( + { + token => $url_token, + scope => 'comment' } - }, - 'submit update' - ); + ); + ok $token, 'Token found in database'; - $mech->content_contains('Nearly Done! Now check your email'); + my $update_id = $token->data->{id}; + my $add_alerts = $token->data->{add_alert}; + my $update = + FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } ); - my $email = $mech->get_email; - ok $email, "got an email"; - like $email->body, qr/confirm the update you/i, "Correct email text"; + my $details = { + %{ $test->{form_values} }, + %{ $test->{changes} } + }; - my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)}; - ok $url, "extracted confirm url '$url'"; + ok $update, 'found update in database'; + is $update->state, 'unconfirmed', 'update unconfirmed'; + is $update->user->email, $details->{rznvy}, 'update email'; + is $update->text, $details->{update}, 'update text'; + is $add_alerts, $details->{add_alert} ? 1 : 0, 'do not sign up for alerts'; - my $token = FixMyStreet::App->model('DB::Token')->find( - { - token => $url_token, - scope => 'comment' - } - ); - ok $token, 'Token found in database'; + $mech->get_ok( $url . $url_token ); + $mech->content_contains("/report/$report_id#$update_id"); - my $update_id = $token->data->{id}; - my $add_alerts = $token->data->{add_alert}; - my $update = - FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } ); + my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } ); - ok $update, 'found update in database'; - is $update->state, 'unconfirmed', 'update unconfirmed'; - is $update->user->email, 'unregistered@example.com', 'update email'; - is $update->text, 'Update from an unregistered user', 'update text'; - is $add_alerts, 0, 'do not sign up for alerts'; + ok $unreg_user, 'found user'; - $mech->get_ok( $url . $url_token ); - $mech->content_contains("/report/$report_id#$update_id"); + my $alert = FixMyStreet::App->model( 'DB::Alert' )->find( + { user => $unreg_user, alert_type => 'new_updates', confirmed => 1, } + ); - $update->discard_changes; + ok $details->{add_alert} ? defined( $alert ) : !defined( $alert ), 'sign up for alerts'; - is $update->state, 'confirmed', 'update confirmed'; -}; + $update->discard_changes; + + is $update->state, 'confirmed', 'update confirmed'; + $mech->delete_user( $unreg_user ); + }; +} for my $test ( { @@ -519,7 +563,7 @@ for my $test ( my $alert = FixMyStreet::App->model('DB::Alert') - ->find( { user => $user, alert_type => 'new_updates' } ); + ->find( { user => $user, alert_type => 'new_updates', confirmed => 1 } ); ok $test->{alert} ? $alert : !$alert, 'not signed up for alerts'; }; -- cgit v1.2.3 From 9ac1bac73d0b12f313d6863832b4b5547fded756 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 2 Jun 2011 21:57:57 +0100 Subject: Move most of questionnaire cron to ResultSet so it can be called and tested from test. --- t/app/controller/questionnaire.t | 62 ++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 24 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index af14332d4..a245be343 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -45,29 +45,29 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( my $report_id = $report->id; ok $report, "created test report - $report_id"; -# FIXME Should call send-questionnaires here to test that is working okay. -# For now, just generate the questionnaire etc. manually. -# Call send-questionnaires (for normal non-EHA site) -# my $email = $mech->get_email; -# ok $email, "got an email"; -# like $email->body, qr/fill in our short questionnaire/i, "got questionnaire email"; -# my ($url) = $email->body =~ m{(http://\S+)}; -# ok $url, "extracted questionnaire url '$url'"; +# Call the questionaire sending function... +FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { + site => 'fixmystreet' +} ); +my $email = $mech->get_email; +ok $email, "got an email"; +like $email->body, qr/fill in our short questionnaire/i, "got questionnaire email"; +my ($token) = $email->body =~ m{http://.*?/Q/(\S+)}; +ok $token, "extracted questionnaire token '$token'"; +$mech->clear_emails_ok; -$report->send_questionnaire( 0 ); -$report->update; +$report->discard_changes; +is $report->send_questionnaire, 0; -my $questionnaire = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( - { - problem_id => $report->id, - whensent => '2011-04-01 12:00:00', - } -); -ok $questionnaire, 'added questionnaire'; -my $token = FixMyStreet::App->model("DB::Token")->create( - { scope => 'questionnaire', data => $questionnaire->id } -); -ok $token, 'added token for questionnaire'; +$token = FixMyStreet::App->model("DB::Token")->find( { + scope => 'questionnaire', token => $token +} ); +ok $token, 'found token for questionnaire'; + +my $questionnaire = FixMyStreet::App->model('DB::Questionnaire')->find( { + id => $token->data +} ); +ok $questionnaire, 'found questionnaire'; foreach my $test ( { @@ -251,7 +251,21 @@ foreach my $test ( # EHA extra checking ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; -$mech->get_ok("/Q/" . $token->token); + +# Reset, and all the questionaire sending function - FIXME should it detect site itself somehow? +$report->send_questionnaire( 1 ); +$report->update; +$questionnaire->delete; +FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { + site => 'emptyhomes' +} ); +$email = $mech->get_email; +ok $email, "got an email"; +like $email->body, qr/fill in this short questionnaire/i, "got questionnaire email"; +($token) = $email->body =~ m{http://.*?/Q/(\S+)}; +ok $token, "extracted questionnaire token '$token'"; + +$mech->get_ok("/Q/" . $token); $mech->content_contains( 'should have reported what they have done' ); # Test already answered the ever reported question, so not shown again @@ -264,14 +278,14 @@ my $questionnaire2 = FixMyStreet::App->model('DB::Questionnaire')->find_or_creat ); ok $questionnaire, 'added another questionnaire'; ok $mech->host("fixmystreet.com"), 'change host to fixmystreet'; -$mech->get_ok("/Q/" . $token->token); +$mech->get_ok("/Q/" . $token); $mech->title_like( qr/Questionnaire/ ); $mech->content_contains( 'Has this problem been fixed?' ); $mech->content_lacks( 'ever reported' ); # EHA extra checking ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; -$mech->get_ok("/Q/" . $token->token); +$mech->get_ok("/Q/" . $token); $mech->content_contains( 'made a lot of progress' ); $mech->delete_user('test@example.com'); -- cgit v1.2.3 From b712bbffbd70c06c53a1d185462c3419d65069b5 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 09:55:00 +0100 Subject: Some text updates from/for locale file. --- t/app/controller/about.t | 2 +- t/app/controller/alert.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/about.t b/t/app/controller/about.t index e1a1641fd..84eab005a 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -8,7 +8,7 @@ ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); # check that we can get the page $mech->get_ok('/about'); -$mech->content_like(qr{About Us ::\s+FixMyStreet.com}); +$mech->content_like(qr{About us ::\s+FixMyStreet.com}); $mech->content_contains('html lang="en-gb"'); SKIP: { diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index f32d0d6e9..45257b31b 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -22,7 +22,7 @@ $mech->content_contains('html lang="en-gb"'); $mech->get_ok('/alert/list?pc=EH99 1SP'); $mech->title_like(qr/^Local RSS feeds and email alerts/); -$mech->content_contains('Local RSS feeds and email alerts for EH99 1SP'); +$mech->content_contains('Local RSS feeds and email alerts for ‘EH99 1SP’'); $mech->content_contains('html lang="en-gb"'); $mech->content_contains('Problems within 8.5km'); $mech->content_contains('rss/pc/EH991SP/2'); -- cgit v1.2.3 From e8d2fd68b5a594e1f03fc4a4ca338fcd83f16bdf Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 3 Jun 2011 11:50:32 +0100 Subject: Match the old JSON urls --- t/app/controller/json.t | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/json.t b/t/app/controller/json.t index 2c9ff4a61..7c5dce786 100644 --- a/t/app/controller/json.t +++ b/t/app/controller/json.t @@ -13,23 +13,23 @@ subtest "check that a bad request produces the appropriate response" => sub { my $bad_type = "Invalid type supplied"; my %tests = ( - '' => $bad_date, - 'foo=bar' => $bad_date, - 'type=&start_date=&end_date=' => $bad_date, - 'type=&start_date=bad&end_date=2000-02-01' => $bad_date, - 'type=&start_date=2000-01-01&end_date=bad' => $bad_date, - 'type=&start_date=2000-02-31&end_date=2000-02-01' => $bad_date, - 'type=&start_date=2000-01-01&end_date=2000-02-31' => $bad_date, - - 'type=&start_date=2000-02-01&end_date=2000-01-01' => $mad_date, - - 'type=&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, - 'type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, + '?' => $bad_date, + '?foo=bar' => $bad_date, + '?start_date=&end_date=' => $bad_date, + '?start_date=bad&end_date=2000-02-01' => $bad_date, + '?start_date=2000-01-01&end_date=bad' => $bad_date, + '?start_date=2000-02-31&end_date=2000-02-01' => $bad_date, + '?start_date=2000-01-01&end_date=2000-02-31' => $bad_date, + + '?start_date=2000-02-01&end_date=2000-01-01' => $mad_date, + + '?start_date=2000-01-01&end_date=2000-02-01' => $bad_type, + '/foo?type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, ); foreach my $q ( sort keys %tests ) { is_deeply # - $mech->get_ok_json("/json?$q"), # + $mech->get_ok_json("/json/problems$q"), # { error => $tests{$q} }, # "correct error for query '$q'"; } @@ -38,7 +38,7 @@ subtest "check that a bad request produces the appropriate response" => sub { is_deeply # $mech->get_ok_json( - "/json?type=new_problems&start_date=2000-01-01&end_date=2000-02-01"), # + "/json/problems/new?start_date=2000-01-01&end_date=2000-02-01"), # [], # "correct response"; @@ -75,7 +75,7 @@ ok $anon_problem, "created anon test problem"; is_deeply # $mech->get_ok_json( - "/json?type=new_problems&start_date=2000-01-01&end_date=2000-02-01"), # + "/json/problems/new?start_date=2000-01-01&end_date=2000-02-01"), # [ { 'anonymous' => 0, -- cgit v1.2.3 From 7b405637a1ac3436cf90acc7d5ad46f1b80c8250 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 13:43:36 +0100 Subject: Fix broken contact form report handling, stop HTML injection, and remove old contact code. --- t/app/controller/contact.t | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 73660306d..9808ef762 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -10,6 +10,8 @@ $mech->get_ok('/contact'); $mech->title_like(qr/Contact Us/); $mech->content_contains("We'd love to hear what you think about this site"); +my $problem_main; + for my $test ( { name => 'A User', @@ -20,6 +22,7 @@ for my $test ( confirmed => '2011-05-04 10:44:28.145168', anonymous => 0, meta => 'Reported by A User at 10:44, Wednesday 4 May 2011', + main => 1, }, { name => 'A User', @@ -111,7 +114,11 @@ for my $test ( } $update->delete if $update; - $problem->delete; + if ($test->{main}) { + $problem_main = $problem; + } else { + $problem->delete; + } }; } @@ -193,7 +200,7 @@ for my $test ( field_errors => [ 'Please write a message', ] }, { - url => '/contact?id=1', + url => '/contact?id=' . $problem_main->id, fields => { em => 'test@example.com', name => 'A name', @@ -228,12 +235,25 @@ for my $test ( message => 'A message', }, }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + id => $problem_main->id, + }, + }, ) { subtest 'check email sent correctly' => sub { $mech->clear_emails_ok; - $mech->get_ok('/contact'); + if ($test->{fields}{id}) { + $mech->get_ok('/contact?id=' . $test->{fields}{id}); + } else { + $mech->get_ok('/contact'); + } $mech->submit_form_ok( { with_fields => $test->{fields} } ); $mech->content_contains('Thanks for your feedback'); $mech->email_count_is(1); @@ -243,7 +263,13 @@ for my $test ( is $email->header('Subject'), 'FMS message: ' . $test->{fields}->{subject}, 'subject'; is $email->header('From'), "\"$test->{fields}->{name}\" <$test->{fields}->{em}>", 'from'; like $email->body, qr/$test->{fields}->{message}/, 'body'; - like $email->body, qr/Sent by contact.cgi on \S+. IP address (?:\d{1,3}\.){3,}\d{1,3}/, 'body footer' + like $email->body, qr/Sent by contact.cgi on \S+. IP address (?:\d{1,3}\.){3,}\d{1,3}/, 'body footer'; + my $problem_id = $test->{fields}{id}; + like $email->body, qr/Complaint about report $problem_id/, 'reporting a report' + if $test->{fields}{id}; }; } + +$problem_main->delete; + done_testing(); -- cgit v1.2.3 From 34e78aa47e8cad5ba237705dd8a2fa1d1403ff20 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 15:20:39 +0100 Subject: Better alert page title handling. --- t/app/controller/alert.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 45257b31b..3e2dedd53 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -22,7 +22,7 @@ $mech->content_contains('html lang="en-gb"'); $mech->get_ok('/alert/list?pc=EH99 1SP'); $mech->title_like(qr/^Local RSS feeds and email alerts/); -$mech->content_contains('Local RSS feeds and email alerts for ‘EH99 1SP’'); +$mech->content_contains('Here are the types of local problem alerts for ‘EH99 1SP’'); $mech->content_contains('html lang="en-gb"'); $mech->content_contains('Problems within 8.5km'); $mech->content_contains('rss/pc/EH991SP/2'); -- cgit v1.2.3 From 4767d166eca6e8c34d5c7d99c829e36722530852 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 3 Jun 2011 16:09:14 +0100 Subject: some rudimentary tests and some removal of warnings. --- t/app/controller/admin.t | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 t/app/controller/admin.t (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t new file mode 100644 index 000000000..ea3e8a656 --- /dev/null +++ b/t/app/controller/admin.t @@ -0,0 +1,73 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +$mech->get_ok('/admin'); +$mech->title_like(qr/Summary/); + +$mech->get_ok('/admin/council_contacts/2650'); +$mech->content_contains('Aberdeen City Council'); +$mech->content_contains('AB15 8RN'); + +subtest 'check contact creation' => sub { + my $contact = FixMyStreet::App->model('DB::Contact')->find( + { area_id => 2650, category => 'test category' } + ); + + $contact->delete if $contact; + + my $history = FixMyStreet::App->model('DB::ContactsHistory')->search( + { area_id => 2650, category => 'test category' } + ); + + $history->delete_all; + + $mech->get_ok('/admin/council_contacts/2650'); + + $mech->submit_form_ok( { with_fields => { + category => 'test category', + email => 'test@example.com', + note => 'test note', + } } ); + + $mech->content_contains( 'test category' ); + $mech->content_contains( 'test@example.com' ); + $mech->content_contains( 'test note' ); +}; + +subtest 'check contact editing' => sub { + $mech->get_ok('/admin/council_edit/2650/test%20category'); + + $mech->submit_form_ok( { with_fields => { + email => 'test2@example.com', + note => 'test2 note', + } } ); + + $mech->content_contains( 'test category' ); + $mech->content_contains( 'test2@example.com' ); + $mech->content_contains( 'test2 note' ); + + $mech->get_ok('/admin/council_edit/2650/test%20category'); + $mech->content_contains( 'test2@example.com' ); +}; + +subtest 'check contact updating' => sub { + $mech->get_ok('/admin/council_edit/2650/test%20category'); + $mech->content_like(qr{test2\@example.com[^<]*[^<]*No}s); + + $mech->get_ok('/admin/council_contacts/2650'); + + $mech->form_number( 1 ); + $mech->tick( 'confirmed', 'test category' ); + $mech->submit_form_ok({form_number => 1}); + + $mech->content_like(qr'test2@example.com[^<]*Yes's); + $mech->get_ok('/admin/council_edit/2650/test%20category'); + $mech->content_like(qr{test2\@example.com[^<]*[^<]*Yes}s); +}; + +done_testing(); -- cgit v1.2.3 From 5d2261eb81e9e28bbaa1f52c668be164bb7a597d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 20:21:13 +0100 Subject: Sign up new report to email alert if logged in as well as when confirmed by email. Allow disabling rather than deleting of alerts. Revert quoting as it breaks timestamps and literal SQL. --- t/app/controller/report_new.t | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 760dfacc6..01c29ecf4 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -343,10 +343,17 @@ subtest "test report creation for a user who does not have an account" => sub { $mech->get_ok($url); $report->discard_changes; is $report->state, 'confirmed', "Report is now confirmed"; - is $report->state, 'confirmed', "report is now confirmed"; $mech->get_ok( '/report/' . $report->id ); + # check that the reporter has an alert + my $alert = FixMyStreet::App->model('DB::Alert')->find( { + user => $report->user, + alert_type => 'new_updates', + parameter => $report->id, + } ); + ok $alert, "created new alert"; + # user is created and logged in $mech->logged_in_ok; @@ -440,6 +447,14 @@ foreach my $test ( is $report->state, 'confirmed', "report is now confirmed"; $mech->get_ok( '/report/' . $report->id ); + # check that the reporter has an alert + my $alert = FixMyStreet::App->model('DB::Alert')->find( { + user => $report->user, + alert_type => 'new_updates', + parameter => $report->id, + } ); + ok $alert, "created new alert"; + # user is still logged in $mech->logged_in_ok; -- cgit v1.2.3 From b388fd0be5296426225089ed188b3c1cdd802415 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sat, 4 Jun 2011 00:52:02 +0100 Subject: Migrate alert sending script, add test for it, fix some small bugs and strings. --- t/app/controller/alert_new.t | 141 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 120 insertions(+), 21 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 91e86bd46..ff1acd480 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -43,8 +43,8 @@ foreach my $test ( email_text => 'confirm the alert', uri => '/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1', - param1 => 10.2, - param2 => 20.1, + param1 => 20.1, + param2 => 10.2, }, { email => 'test@example.com', @@ -66,7 +66,6 @@ foreach my $test ( ->find( { email => $test->{email} } ); # we don't want an alert - my $alert; if ($user) { $mech->delete_user($user); } @@ -80,7 +79,7 @@ foreach my $test ( ok $user, 'user created for alert'; - $alert = FixMyStreet::App->model('DB::Alert')->find( + my $alert = FixMyStreet::App->model('DB::Alert')->find( { user => $user, alert_type => $type, @@ -129,7 +128,7 @@ foreach my $test ( ); ok $token, 'new token found in database'; - ok $token->data->{id} == $existing_id, 'subscribed to exsiting alert'; + ok $token->data->{id} == $existing_id, 'subscribed to existing alert'; $mech->get_ok("/A/$url_token"); $mech->content_contains('successfully confirmed'); @@ -138,6 +137,7 @@ foreach my $test ( FixMyStreet::App->model('DB::Alert')->find( { id => $existing_id, } ); ok $alert->confirmed, 'alert set to confirmed'; + $mech->delete_user($user); }; } @@ -162,18 +162,14 @@ foreach my $test ( FixMyStreet::App->model('DB::User') ->find_or_create( { email => $test->{email} } ); - my $alert; - if ($user) { - $alert = FixMyStreet::App->model('DB::Alert')->find( - { - user => $user, - alert_type => $type - } - ); - - # clear existing data so we can be sure we're creating it - ok $alert->delete() if $alert; - } + my $alert = FixMyStreet::App->model('DB::Alert')->find( + { + user => $user, + alert_type => $type + } + ); + # clear existing data so we can be sure we're creating it + ok $alert->delete() if $alert; $mech->get_ok( $test->{uri} ); @@ -190,6 +186,7 @@ foreach my $test ( $mech->content_contains( 'Now check your email' ); ok $alert, 'New alert created with existing user'; + $mech->delete_user($user); }; } @@ -199,8 +196,6 @@ foreach my $test ( user => 'test-login@example.com', email => 'test-login@example.com', type => 'council', - content => 'your alert will not be activated', - email_text => 'confirm the alert', param1 => 2651, param2 => 2651, confirmed => 1, @@ -210,8 +205,6 @@ foreach my $test ( user => 'loggedin@example.com', email => 'test-login@example.com', type => 'council', - content => 'your alert will not be activated', - email_text => 'confirm the alert', param1 => 2651, param2 => 2651, confirmed => 0, @@ -350,6 +343,112 @@ for my $test ( ok !$alert->confirmed, 'alert not set to confirmed'; $abuse->delete; + $mech->delete_user($user); }; } + +subtest "Test normal alert signups and that alerts are sent" => sub { + my $user1 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } ); + ok $user1, "created test user"; + $user1->alerts->delete; + + my $user2 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } ); + ok $user2, "created test user"; + $user2->alerts->delete; + + for my $alert ( + { feed => 'local:55.951963:-3.189944', email_confirm => 1 }, + { feed => 'council:2651:City_of_Edinburgh', }, + ) { + $mech->get_ok( '/alert' ); + $mech->submit_form_ok( { with_fields => { pc => 'EH11BB' } } ); + $mech->submit_form_ok( { + button => 'alert', + with_fields => { + rznvy => $user2->email, + feed => $alert->{feed}, + } + } ); + if ( $alert->{email_confirm} ) { + my $email = $mech->get_email; + $mech->clear_emails_ok; + my ( $url, $url_token ) = $email->body =~ m{http://\S+(/A/(\S+))}; + my $token = FixMyStreet::App->model('DB::Token')->find( { token => $url_token, scope => 'alert' } ); + $mech->get_ok( $url ); + $mech->content_contains('successfully confirmed'); + } else { + $mech->content_contains('successfully created'); + } + } + + my $dt = DateTime->now()->add( days => 2); + + my $report_time = '2011-03-01 12:00:00'; + my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { + postcode => 'EH1 1BB', + council => '2651', + areas => ',11808,135007,14419,134935,2651,20728,', + category => 'Street lighting', + title => 'Testing', + detail => 'Testing Detail', + used_map => 1, + name => $user1->name, + anonymous => 0, + state => 'confirmed', + confirmed => $dt, + lastupdate => $dt, + whensent => $dt->clone->add( minutes => 5 ), + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 1, + latitude => '55.951963', + longitude => '-3.189944', + user_id => $user1->id, + } ); + my $report_id = $report->id; + ok $report, "created test report - $report_id"; + + my $alert = FixMyStreet::App->model('DB::Alert')->create( { + parameter => $report_id, + alert_type => 'new_updates', + user => $user1, + } )->confirm; + ok $alert, 'created alert for reporter'; + + my $update = FixMyStreet::App->model('DB::Comment')->create( { + problem_id => $report_id, + user_id => $user2->id, + name => 'Other User', + mark_fixed => 'false', + text => 'This is some update text', + state => 'confirmed', + confirmed => $dt->clone->add( hours => 7 ), + anonymous => 'f', + } ); + my $update_id = $update->id; + ok $update, "created test update - $update_id"; + + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + $mech->email_count_is(3); + my @emails = $mech->get_email; + my $count; + for (@emails) { + $count++ if $_->body =~ /The following updates have been left on this problem:/; + $count++ if $_->body =~ /The following new problems have been reported to City of\s*Edinburgh Council:/; + $count++ if $_->body =~ /The following nearby problems have been added:/; + } + is $count, 3, 'Three emails with the right things in them'; + + my ( $url, $url_token ) = $emails[0]->body =~ m{http://\S+(/A/(\S+))}; + $mech->get_ok( $url ); + $mech->content_contains('successfully deleted'); + + $mech->delete_user($user1); + $mech->delete_user($user2); +}; + done_testing(); -- cgit v1.2.3 From 1aa62d33e4e038e9edf994084603086eff26b6ac Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 6 Jun 2011 11:25:44 +0100 Subject: Tidy up some strings for translation, remove some migrated code. --- t/app/controller/auth.t | 2 +- t/app/controller/contact.t | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 9f08c8aa9..9a466832b 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -24,7 +24,7 @@ $mech->not_logged_in_ok; $mech->get_ok('/auth'); for my $test ( - [ '' => 'enter an email address' ], + [ '' => 'enter your email' ], [ 'not an email' => 'check your email address is correct' ], [ 'bob@foo' => 'check your email address is correct' ], [ 'bob@foonaoedudnueu.co.uk' => 'check your email address is correct' ], diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 9808ef762..bbb3a0f83 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -133,9 +133,9 @@ for my $test ( page_errors => [ 'There were problems with your report. Please see below.', ], field_errors => [ - 'Please give your name', - 'Please give your email', - 'Please give a subject', + 'Please enter your name', + 'Please enter your email', + 'Please enter a subject', 'Please write a message', ] }, @@ -149,9 +149,9 @@ for my $test ( page_errors => [ 'There were problems with your report. Please see below.', ], field_errors => [ - 'Please give your name', - 'Please give a valid email address', - 'Please give a subject', + 'Please enter your name', + 'Please enter a valid email address', + 'Please enter a subject', 'Please write a message', ] }, @@ -164,7 +164,7 @@ for my $test ( }, page_errors => [ 'There were problems with your report. Please see below.', ], - field_errors => [ 'Please give a subject', 'Please write a message', ] + field_errors => [ 'Please enter a subject', 'Please write a message', ] }, { fields => { @@ -186,7 +186,7 @@ for my $test ( }, page_errors => [ 'There were problems with your report. Please see below.', ], - field_errors => [ 'Please give a subject', 'Please write a message', ] + field_errors => [ 'Please enter a subject', 'Please write a message', ] }, { fields => { -- cgit v1.2.3 From 1825445a2763a9581bedab749f9c60bf03648313 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 6 Jun 2011 19:01:35 +0100 Subject: Fix alert subscribing bugs with two-tier councils and on ReportEmptyHomes. --- t/app/controller/alert.t | 16 ++++++++-------- t/app/controller/alert_new.t | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 3e2dedd53..b8e38ec92 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -51,16 +51,16 @@ $mech->content_contains('Please select the feed you want'); $mech->get_ok('/alert/subscribe?rss=1&feed=invalid:1000:A_Locationtype=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy='); $mech->content_contains('Illegal feed selection'); -$mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:A_Location'); -$mech->uri->path('/rss/area/A+Location'); +$mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:Birmingham'); +is $mech->uri->path, '/rss/reports/Birmingham'; -$mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:1001:A_Location:Diff_Location'); -$mech->uri->path('/rss/area/A+Location/Diff+Location'); +$mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:1001:Cheltenham:Lansdown'); +is $mech->uri->path, '/rss/area/Cheltenham/Lansdown'; -$mech->get_ok('/alert/subscribe?rss=1&feed=council:1000:A_Location'); -$mech->uri->path('/rss/reports/A+Location'); +$mech->get_ok('/alert/subscribe?rss=1&feed=council:1000:Gloucestershire'); +is $mech->uri->path, '/rss/reports/Gloucestershire'; -$mech->get_ok('/alert/subscribe?rss=1&feed=ward:1000:1001:A_Location:Diff_Location'); -$mech->uri->path('/rss/ward/A+Location/Diff+Location'); +$mech->get_ok('/alert/subscribe?rss=1&feed=ward:1000:1001:Cheltenham:Lansdown'); +is $mech->uri->path, '/rss/reports/Cheltenham/Lansdown'; done_testing(); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index ff1acd480..6fc32acbf 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -347,6 +347,33 @@ for my $test ( }; } +subtest "Test two-tier council alerts" => sub { + for my $alert ( + { feed => "local:51.896269:-2.093063", result => '/rss/l/51.896269,-2.093063' }, + { feed => "area:2326:Cheltenham", result => '/rss/area/Cheltenham' }, + { feed => "area:2326:4544:Cheltenham:Lansdown", result => '/rss/area/Cheltenham/Lansdown' }, + { feed => "area:2226:Gloucestershire", result => '/rss/area/Gloucestershire' }, + { feed => "area:2226:14949:Gloucestershire:Lansdown%2C_Park_and_Warden_Hill", + result => '/rss/area/Gloucestershire/Lansdown%2C+Park+and+Warden+Hill' + }, + { feed => "council:2326:Cheltenham", result => '/rss/reports/Cheltenham' }, + { feed => "ward:2326:4544:Cheltenham:Lansdown", result => '/rss/reports/Cheltenham/Lansdown' }, + { feed => "council:2226:Gloucestershire", result => '/rss/reports/Gloucestershire' }, + { feed => "ward:2226:14949:Gloucestershire:Lansdown%2C_Park_and_Warden_Hill", + result => '/rss/reports/Gloucestershire/Lansdown%2C+Park+and+Warden+Hill' + }, + ) { + $mech->get_ok( '/alert/list?pc=GL502PR' ); + $mech->submit_form_ok( { + button => 'rss', + with_fields => { + feed => $alert->{feed}, + } + } ); + is $mech->uri->path, $alert->{result}; + } +}; + subtest "Test normal alert signups and that alerts are sent" => sub { my $user1 = FixMyStreet::App->model('DB::User') ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } ); -- cgit v1.2.3 From 5493e3ad9623036f11bb458ee8abdd5c4250a8ed Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 8 Jun 2011 18:40:40 +0100 Subject: skip tests if no entry in secret table rather than failing --- t/app/controller/admin.t | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index ea3e8a656..5b7a3e83a 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -6,6 +6,14 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; +my $secret = FixMyStreet::App->model('DB::Secret')->search(); + +# don't explode if there's nothing in the secret table +if ( $secret == 0 ) { + diag "You need to put an entry in the secret table for the admin tests to run"; + plan skip_all => 'No entry in secret table'; +} + $mech->get_ok('/admin'); $mech->title_like(qr/Summary/); -- cgit v1.2.3 From 98ea266a724e6c38b383c58289556f512a6074d3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 9 Jun 2011 13:42:03 +0100 Subject: admin edit report tests --- t/app/controller/admin.t | 339 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 339 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 5b7a3e83a..a4b3f39dd 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -78,4 +78,343 @@ subtest 'check contact updating' => sub { $mech->content_like(qr{test2\@example.com[^<]*[^<]*Yes}s); }; +my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); +ok $user, "created test user"; + +my $user2 = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test2@example.com', name => 'Test User 2' } ); +ok $user2, "created second test user"; + + +my $user3 = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test3@example.com', name => 'Test User 2' } ); + +if ( $user3 ) { + $mech->delete_user( $user3 ); +} + +my $dt = DateTime->new( + year => 2011, + month => 04, + day => 16, + hour => 15, + minute => 47, + second => 23 +); + +my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'SW1A 1AA', + council => '2504', + areas => ',105255,11806,11828,2247,2504,', + category => 'Other', + title => 'Report to Edit', + detail => 'Detail for Report to Edit', + used_map => 't', + name => 'Test User', + anonymous => 'f', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '51.5016605453401', + longitude => '-0.142497580865087', + user_id => $user->id, + whensent => $dt->ymd . ' ' . $dt->hms, + } +); + +my $log_entries = FixMyStreet::App->model('DB::AdminLog')->search( + { + object_type => 'problem', + object_id => $report->id + }, + { + order_by => { -desc => 'id' }, + } +); + +is $log_entries->count, 0, 'no admin log entries'; + +my $report_id = $report->id; +ok $report, "created test report - $report_id"; + +foreach my $test ( + { + description => 'edit report title', + fields => { + title => 'Report to Edit', + detail => 'Detail for Report to Edit', + state => 'confirmed', + name => 'Test User', + email => $user->email, + anonymous => 0, + }, + changes => { + title => 'Edited Report', + }, + log_count => 1, + log_entries => [ qw/edit/ ], + resend => 0, + }, + { + description => 'edit report description', + fields => { + title => 'Edited Report', + detail => 'Detail for Report to Edit', + state => 'confirmed', + name => 'Test User', + email => $user->email, + anonymous => 0, + }, + changes => { + detail => 'Edited Detail', + }, + log_count => 2, + log_entries => [ qw/edit edit/ ], + resend => 0, + }, + { + description => 'edit report user name', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Test User', + email => $user->email, + anonymous => 0, + }, + changes => { + name => 'Edited User', + }, + log_count => 3, + log_entries => [ qw/edit edit edit/ ], + resend => 0, + user => $user, + }, + { + description => 'edit report user email', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user->email, + anonymous => 0, + }, + changes => { + email => $user2->email, + }, + log_count => 4, + log_entries => [ qw/edit edit edit edit/ ], + resend => 0, + user => $user2, + }, + { + description => 'change state to unconfirmed', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + }, + changes => { + state => 'unconfirmed' + }, + log_count => 5, + log_entries => [ qw/state_change edit edit edit edit/ ], + resend => 0, + }, + { + description => 'change state to confirmed', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'unconfirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + }, + changes => { + state => 'confirmed' + }, + log_count => 6, + log_entries => [ qw/state_change state_change edit edit edit edit/ ], + resend => 0, + }, + { + description => 'change state to fixed', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + }, + changes => { + state => 'fixed' + }, + log_count => 7, + log_entries => [ qw/state_change state_change state_change edit edit edit edit/ ], + resend => 0, + }, + { + description => 'change state to hidden', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'fixed', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + }, + changes => { + state => 'hidden' + }, + log_count => 8, + log_entries => [ qw/state_change state_change state_change state_change edit edit edit edit/ ], + resend => 0, + }, + { + description => 'edit and change state', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'hidden', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + }, + changes => { + state => 'confirmed', + anonymous => 1, + }, + log_count => 10, + log_entries => [ qw/edit state_change state_change state_change state_change state_change edit edit edit edit/ ], + resend => 0, + }, + { + description => 'resend', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 1, + }, + changes => { + }, + log_count => 11, + log_entries => [ qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit/ ], + resend => 1, + }, +) { + subtest $test->{description} => sub { + $log_entries->reset; + $mech->get_ok("/admin/report_edit/$report_id"); + + is_deeply( $mech->visible_form_values(), $test->{fields}, 'initial form values' ); + + my $new_fields = { + %{ $test->{fields} }, + %{ $test->{changes} }, + }; + + if ( $test->{resend} ) { + $mech->click_ok( 'resend' ); + } else { + $mech->submit_form_ok( { with_fields => $new_fields }, 'form_submitted' ); + } + + is_deeply( $mech->visible_form_values(), $new_fields, 'changed form values' ); + is $log_entries->count, $test->{log_count}, 'log entry count'; + is $log_entries->next->action, $_, 'log entry added' for @{ $test->{log_entries} }; + + $report->discard_changes; + + if ( $report->state eq 'confirmed' ) { + $mech->content_contains( 'type="submit" name="resend"', 'no resend button' ); + } else { + $mech->content_lacks( 'type="submit" name="resend"', 'no resend button' ); + } + + is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'email' } keys %{ $test->{changes} }; + + if ( $test->{user} ) { + is $report->user->id, $test->{user}->id, 'user changed'; + } + + if ( $test->{resend} ) { + $mech->content_contains( 'That problem will now be resent' ); + is $report->whensent, undef, 'mark report to resend'; + } + }; +} + +subtest 'change email to new user' => sub { + $log_entries->delete; + $mech->get_ok("/admin/report_edit/$report_id"); + my $fields = { + title => $report->title, + detail => $report->detail, + state => $report->state, + name => $report->name, + email => $report->user->email, + anonymous => 1, + }; + + is_deeply( $mech->visible_form_values(), $fields, 'initial form values' ); + + my $changes = { + email => 'test3@example.com' + }; + + $user3 = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test3@example.com', name => 'Test User 2' } ); + + ok !$user3, 'user not in database'; + + my $new_fields = { + %{ $fields }, + %{ $changes }, + }; + + $mech->submit_form_ok( + { + with_fields => $new_fields, + } + ); + + is $log_entries->count, 1, 'created admin log entries'; + is $log_entries->first->action, 'edit', 'log action'; + is_deeply( $mech->visible_form_values(), $new_fields, 'changed form values' ); + + $user3 = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test3@example.com', name => 'Test User 2' } ); + + $report->discard_changes; + + ok $user3, 'new user created'; + is $report->user_id, $user3->id, 'user changed to new user'; +}; + +$log_entries->delete; + +$mech->delete_user( $user ); +$mech->delete_user( $user2 ); +$mech->delete_user( $user3 ); + done_testing(); -- cgit v1.2.3 From 450f8656ef9487bf73b7ae5710a0935b53f424b2 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 9 Jun 2011 16:20:35 +0100 Subject: search report tests --- t/app/controller/admin.t | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index a4b3f39dd..b6ffa9d83 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -413,6 +413,32 @@ subtest 'change email to new user' => sub { $log_entries->delete; +subtest 'report search' => sub { + my $update = FixMyStreet::App->model('DB::Comment')->create( + { + text => 'this is an update', + user => $report->user, + state => 'confirmed', + problem => $report, + mark_fixed => 0, + anonymous => 1, + } + ); + + $mech->get_ok('/admin/search_reports'); + $mech->get_ok('/admin/search_reports?search=' . $report->id ); + + $mech->content_contains( $report->title ); + my $r_id = $report->id; + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id} ); + + $mech->get_ok('/admin/search_reports?search=' . $report->user->email); + + my $u_id = $update->id; + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id} ); + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/#update_$u_id">$u_id} ); +}; + $mech->delete_user( $user ); $mech->delete_user( $user2 ); $mech->delete_user( $user3 ); -- cgit v1.2.3 From fb26dda031a9409a1716c379d4a86327aa142dd7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 9 Jun 2011 17:11:11 +0100 Subject: Stop empty string warning, delete some test users, and use same n/a string as elsewhere. --- t/app/controller/alert_new.t | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 6fc32acbf..5bf7e31dd 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -208,6 +208,7 @@ foreach my $test ( param1 => 2651, param2 => 2651, confirmed => 0, + delete => 1, } ) { @@ -263,6 +264,10 @@ foreach my $test ( $mech->email_count_is( $test->{confirmed} ? 0 : 1 ); + if ( $test->{delete} ) { + $mech->delete_user($user); + $mech->delete_user($alert_user); + } }; } -- cgit v1.2.3 From 714ce37e538a611322667b0a1ce82329c35c94ef Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 9 Jun 2011 18:26:23 +0100 Subject: more admin tests for update editing and report searching --- t/app/controller/admin.t | 218 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 212 insertions(+), 6 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index b6ffa9d83..c5416832f 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -413,18 +413,211 @@ subtest 'change email to new user' => sub { $log_entries->delete; -subtest 'report search' => sub { - my $update = FixMyStreet::App->model('DB::Comment')->create( - { +my $update = FixMyStreet::App->model('DB::Comment')->create( + { + text => 'this is an update', + user => $user, + state => 'confirmed', + problem => $report, + mark_fixed => 0, + anonymous => 1, + } +); + +$log_entries = FixMyStreet::App->model('DB::AdminLog')->search( + { + object_type => 'update', + object_id => $update->id + }, + { + order_by => { -desc => 'id' }, + } +); + +is $log_entries->count, 0, 'no admin log entries'; + +for my $test ( + { + desc => 'edit update text', + fields => { text => 'this is an update', - user => $report->user, state => 'confirmed', - problem => $report, - mark_fixed => 0, + name => '', + anonymous => 1, + email => 'test@example.com', + }, + changes => { + text => 'this is a changed update', + }, + log_count => 1, + log_entries => [qw/edit/], + }, + { + desc => 'edit update name', + fields => { + text => 'this is a changed update', + state => 'confirmed', + name => '', + anonymous => 1, + email => 'test@example.com', + }, + changes => { + name => 'A User', + }, + log_count => 2, + log_entries => [qw/edit edit/], + }, + { + desc => 'edit update anonymous', + fields => { + text => 'this is a changed update', + state => 'confirmed', + name => 'A User', anonymous => 1, + email => 'test@example.com', + }, + changes => { + anonymous => 0, + }, + log_count => 3, + log_entries => [qw/edit edit edit/], + }, + { + desc => 'edit update user', + fields => { + text => 'this is a changed update', + state => 'confirmed', + name => 'A User', + anonymous => 0, + email => $update->user->email, + email => 'test@example.com', + }, + changes => { + email => 'test2@example.com', + }, + log_count => 4, + log_entries => [qw/edit edit edit edit/], + user => $user2, + }, + { + desc => 'edit update state', + fields => { + text => 'this is a changed update', + state => 'confirmed', + name => 'A User', + anonymous => 0, + email => 'test2@example.com', + }, + changes => { + state => 'unconfirmed', + }, + log_count => 5, + log_entries => [qw/state_change edit edit edit edit/], + }, + { + desc => 'edit update state and text', + fields => { + text => 'this is a changed update', + state => 'unconfirmed', + name => 'A User', + anonymous => 0, + email => 'test2@example.com', + }, + changes => { + text => 'this is a twice changed update', + state => 'hidden', + }, + log_count => 7, + log_entries => [qw/edit state_change state_change edit edit edit edit/], + }, +) { + subtest $test->{desc} => sub { + $log_entries->reset; + $mech->get_ok('/admin/update_edit/' . $update->id ); + + is_deeply $mech->visible_form_values, $test->{fields}, 'initial form values'; + + my $to_submit = { + %{ $test->{fields} }, + %{ $test->{changes} } + }; + + $mech->submit_form_ok( { with_fields => $to_submit } ); + + is_deeply $mech->visible_form_values, $to_submit, 'submitted form values'; + + is $log_entries->count, $test->{log_count}, 'number of log entries'; + is $log_entries->next->action, $_, 'log action' for @{ $test->{log_entries} }; + + $update->discard_changes; + + is $update->$_, $test->{changes}->{$_} for grep { $_ ne 'email' } keys %{ $test->{changes} }; + + if ( $test->{user} ) { + is $update->user->id, $test->{user}->id, 'update user'; } + }; +} + +subtest 'editing update email creates new user if required' => sub { + my $user = FixMyStreet::App->model('DB::User')->find( + { email => 'test4@example.com' } ); + $user->delete if $user; + + my $fields = { + text => 'this is a changed update', + state => 'hidden', + name => 'A User', + anonymous => 0, + email => 'test4@example.com', + }; + + $mech->submit_form_ok( { with_fields => $fields } ); + + $user = FixMyStreet::App->model('DB::User')->find( + { email => 'test4@example.com' } + ); + + is_deeply $mech->visible_form_values, $fields, 'submitted form values'; + + ok $user, 'new user created'; + + $update->discard_changes; + is $update->user->id, $user->id, 'update set to new user'; +}; + +subtest 'hiding comment marked as fixed reopens report' => sub { + $update->mark_fixed( 1 ); + $update->update; + + $report->state('fixed'); + $report->update; + + + my $fields = { + text => 'this is a changed update', + state => 'hidden', + name => 'A User', + anonymous => 0, + email => 'test2@example.com', + }; + + $mech->submit_form_ok( { with_fields => $fields } ); + + $report->discard_changes; + is $report->state, 'confirmed', 'report reopened'; + $mech->content_contains('Problem marked as open'); +}; + +$log_entries->delete; + +subtest 'report search' => sub { + $update->state('confirmed'); + $update->user($report->user); + $update->update; + $mech->get_ok('/admin/search_reports'); $mech->get_ok('/admin/search_reports?search=' . $report->id ); @@ -437,10 +630,23 @@ subtest 'report search' => sub { my $u_id = $update->id; $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id} ); $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/#update_$u_id">$u_id} ); + + $update->state('hidden'); + $update->update; + + $mech->get_ok('/admin/search_reports?search=' . $report->user->email); + $mech->content_like( qr{]*hidden[^>]*> \s* \s* $u_id \s* }xs ); + + $report->state('hidden'); + $report->update; + + $mech->get_ok('/admin/search_reports?search=' . $report->user->email); + $mech->content_like( qr{]*hidden[^>]*> \s* \s* $r_id \s* }xs ); }; $mech->delete_user( $user ); $mech->delete_user( $user2 ); $mech->delete_user( $user3 ); +$mech->delete_user( 'test4@example.com' ); done_testing(); -- cgit v1.2.3 From 21d576c363f9a37ef1c7b322169093084f4a5101 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 9 Jun 2011 22:26:45 +0100 Subject: Ordering so test doesn't sometimes randomly fail. --- t/app/controller/json.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/json.t b/t/app/controller/json.t index 7c5dce786..d6820e1be 100644 --- a/t/app/controller/json.t +++ b/t/app/controller/json.t @@ -68,7 +68,7 @@ my $problem_args = { longitude => '-0.23021896608596', }; my $problem = $user->add_to_problems( { %$problem_args, anonymous => 0 } ); -my $anon_problem = $user->add_to_problems( { %$problem_args, anonymous => 1 } ); +my $anon_problem = $user->add_to_problems( { %$problem_args, anonymous => 1, confirmed => '2000-01-01 12:02:00' } ); ok $problem, "created normal test problem"; ok $anon_problem, "created anon test problem"; @@ -92,7 +92,7 @@ is_deeply # { 'anonymous' => 1, 'category' => 'test category', - 'confirmed' => '2000-01-01 12:01:00', + 'confirmed' => '2000-01-01 12:02:00', 'council' => 'Wandsworth Borough Council', 'detail' => 'Test detail', 'id' => $anon_problem->id, -- cgit v1.2.3 From 7e844f25b99b1b2b76526a0490b5b9dea00b71df Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 9 Jun 2011 23:00:31 +0100 Subject: Fix session cookie test, and test based on contact_name that might change. --- t/app/controller/auth.t | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 9a466832b..a44716a1e 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -197,9 +197,10 @@ foreach my $remember_me ( '1', '0' ) { # check that the cookie has no expiry set my $expiry = $mech->session_cookie_expiry; - $remember_me - ? cmp_ok( $expiry, '>', 86400, "long expiry time" ) - : is( $expiry, 0, "no expiry time" ); + is( $expiry, 0, "no expiry time" ); + #$remember_me + # ? cmp_ok( $expiry, '>', 86400, "long expiry time" ) + # : is( $expiry, 0, "no expiry time" ); # logout $mech->log_out_ok; -- cgit v1.2.3 From 7513161747fb9bd48eb67cc7a43e711e2a1b45a1 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 10 Jun 2011 00:13:33 +0100 Subject: Simple cron wrapper to run in correct environment. --- t/app/controller/about.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/about.t b/t/app/controller/about.t index 84eab005a..a5fb215d3 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -8,7 +8,7 @@ ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); # check that we can get the page $mech->get_ok('/about'); -$mech->content_like(qr{About us ::\s+FixMyStreet.com}); +$mech->content_like(qr{About us ::\s+FixMyStreet}); $mech->content_contains('html lang="en-gb"'); SKIP: { -- cgit v1.2.3 From 3a81cb62a106adf77d226f3ab9a6c8d4381cb39c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 10 Jun 2011 11:56:15 +0100 Subject: Tidy up a couple of FIXMEs. --- t/app/controller/report_import.t | 68 ++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 38 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 4f225fc5a..154de13d8 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -129,25 +129,21 @@ subtest "Submit a correct entry" => sub { }, "check imported fields are shown"; - TODO: { - local $TODO = "'/report/123' urls not served by catalyst yet"; - - # change the details - $mech->submit_form_ok( # - { - with_fields => { - name => 'New Test User', - email => 'test@example.com', - title => 'New Test report', - detail => 'This is a test report', - phone => '01234 567 890', - may_show_name => '1', - category => 'Street lighting', - } - }, - "Update details and save" - ); - } + # change the details + $mech->submit_form_ok( # + { + with_fields => { + name => 'New Test User', + email => 'test@example.com', + title => 'New Test report', + detail => 'This is a test report', + phone => '01234 567 890', + may_show_name => '1', + category => 'Street lighting', + } + }, + "Update details and save" + ); # check that report has been created my $user = @@ -214,25 +210,21 @@ subtest "Submit a correct entry (with location)" => sub { }, "check imported fields are shown"; - TODO: { - local $TODO = "'/report/123' urls not served by catalyst yet"; - - # change the details - $mech->submit_form_ok( # - { - with_fields => { - name => 'New Test User ll', - email => 'test-ll@example.com', - title => 'New Test report ll', - detail => 'This is a test report ll', - phone => '01234 567 890', - may_show_name => '1', - category => 'Street lighting', - } - }, - "Update details and save" - ); - } + # change the details + $mech->submit_form_ok( # + { + with_fields => { + name => 'New Test User ll', + email => 'test-ll@example.com', + title => 'New Test report ll', + detail => 'This is a test report ll', + phone => '01234 567 890', + may_show_name => '1', + category => 'Street lighting', + } + }, + "Update details and save" + ); # check that report has been created my $user = -- cgit v1.2.3 From 40f13d3cc9dc903da5299901623677c205eff484 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 10 Jun 2011 14:40:30 +0100 Subject: Consolidate MaPit calls to call out to it less. --- t/app/controller/report_updates.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 4f7d1628d..4dd1db737 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -363,7 +363,7 @@ for my $test ( is $add_alerts, $details->{add_alert} ? 1 : 0, 'do not sign up for alerts'; $mech->get_ok( $url . $url_token ); - $mech->content_contains("/report/$report_id#$update_id"); + $mech->content_contains("/report/$report_id#update_$update_id"); my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } ); -- cgit v1.2.3