From 565c6498aefea0fd39ec7453019bbf86b52672dd Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 9 Apr 2014 17:09:14 +0100 Subject: Add a who are you trying to contact option to contact form In order to try and cut down on people mistakingly using this form to try and contact their council all some 'who are you trying to contact' options to the form that display appropriate messaged unless the 'FMS team option is selected. Add the validation code for this in the cobrand module. Fixes #41 --- t/app/controller/contact.t | 111 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 11e0d30cf..89a1db5b2 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -8,7 +8,7 @@ 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->content_contains("It's often quickest to "); my $problem_main; @@ -282,6 +282,115 @@ for my $test ( }; } +for my $test ( + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => undef, + }, + page_errors => + [ 'There were problems with your report. Please see below.', + 'Please enter who your message is for', + ] + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'council', + }, + page_errors => + [ 'There were problems with your report. Please see below.', + 'You can only contact the team behind FixMyStreet using our contact form', + ] + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'update', + }, + page_errors => + [ 'There were problems with your report. Please see below.', + 'You can only contact the team behind FixMyStreet using our contact form', + ] + }, + ) +{ + subtest 'check submit page incorrect destination handling' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + }, sub { + $mech->host('www.fixmystreet.com'); + $mech->get_ok( $test->{url} ? $test->{url} : '/contact' ); + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + is_deeply $mech->page_errors, $test->{page_errors}, 'page 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}, 'form values'; + + if ( $test->{fields}->{dest} and $test->{fields}->{dest} eq 'update' ) { + $mech->content_contains( 'www.writetothem.com', 'includes link to WTT if trying to update report' ); + } elsif ( $test->{fields}->{dest} and $test->{fields}->{dest} eq 'council' ) { + $mech->content_lacks( 'www.writetothem.com', 'does not include link to WTT if trying to contact council' ); + $mech->content_contains( 'should find contact details', 'mentions checking council website for contact details' ); + } + } + }; +} + +for my $test ( + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'help', + }, + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'feedback', + }, + }, + { + fields => { + em => 'test@example.com', + name => 'A name', + subject => 'A subject', + message => 'A message', + dest => 'from_council', + }, + }, + ) +{ + subtest 'check email sent correctly with dest field set to us' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + }, 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); + } + }; +} + $problem_main->delete; done_testing(); -- cgit v1.2.3 From 4734b4c74e203928c599828d9a4fff6dbd57c38c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 16 Apr 2014 13:18:53 +0100 Subject: create westminster council so report_new test can run standalone The test relies on a body for westminster council existing which is crated in an earlier test if you run the whole test suite. However it's not present if you run only this test against an empty database so add it to the list of created bodies. --- t/app/controller/report_new.t | 1 + 1 file changed, 1 insertion(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 84258f338..b1b82954f 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -46,6 +46,7 @@ for my $body ( { id => 2482, name => 'Bromley Council' }, { id => 2240, name => 'Staffordshire County Council' }, { id => 2434, name => 'Lichfield District Council' }, + { id => 2504, name => 'Westminster City Council' }, ) { $mech->create_body_ok($body->{id}, $body->{name}); } -- cgit v1.2.3 From 0625dbe113dc88fe707ca1fb036bf0a580781e15 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 16 Apr 2014 14:36:54 +0100 Subject: alter pave url sent to analytics on report completion In order to allow us to do funnel analysis in google analytics we need to send a differnt page url when a user completes a report. To do this we add a report_created=1 to the query string on either the report page or the report confirmation page for logged in and confirm by email users respectively. There's a bit of complication as we don't want to set a session cookie everywhere as that will break caching so we set a stash variable, although if the user is logged in this is controlled by a variable in the flash as there is already a session cookie at this point. also, removes the code that sends an event upon report completion as this was no use for funnel analysis. --- t/app/controller/report_new.t | 116 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 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 b1b82954f..98b0175f8 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -826,7 +826,7 @@ foreach my $test ( $mech->submit_form_ok( { with_fields => { - title => "Test Report at café", + title => "Test Report at café", detail => 'Test report details.', photo => '', name => 'Joe Bloggs', @@ -1482,6 +1482,120 @@ subtest "categories from deleted bodies shouldn't be visible for new reports" => }; }; +subtest "extra google analytics code displayed on logged in problem creation" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }, 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 => 'GL50 2PR', } }, + "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + $mech->submit_form_ok( + { + with_fields => { + title => "Test Report at café", + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + } + }, + "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"; + + $mech->content_contains( "extra = '?created_report", 'extra google code present' ); + + # cleanup + $mech->delete_user($user); + }; +}; + +subtest "extra google analytics code displayed on email confirmation problem creation" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->log_out_ok; + $mech->clear_emails_ok; + + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR' } }, + "submit location" ); + $mech->follow_link_ok( + { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" + ); + + my $fields = $mech->visible_form_values('mapSkippedForm'); + my $submission_fields = { + title => "Test Report", + detail => 'Test report details.', + photo => '', + email => 'firstlast@example.com', + name => 'Test User', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + password_register => '', + }; + + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + + 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{(https?://\S+)}; + ok $url, "extracted confirm url '$url'"; + + # confirm token in order to update the user details + $mech->get_ok($url); + + $mech->content_contains( "extra = '?created_report", 'extra google code present' ); + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'firstlast@example.com' } ); + + $user->problems->delete; + $user->alerts->delete; + $user->delete; + }; +}; + $contact1->delete; $contact2->delete; $contact3->delete; -- cgit v1.2.3 From 39d3a68fe3e4bbc34193b2903a3a933d162678fe Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Wed, 30 Apr 2014 10:42:33 +0100 Subject: Test dashboard CSV export more thoroughly Instead of counting the number of lines output by dashboard CSV export, the content is parsed as CSV and the number of rows present is checked. Also includes a problem report that's split across multiple lines, testing the fix for mysociety/FixMyStreet-Commercial#494 introduced in d75e161c151c4f1e6dced24eae3170e01f9b7ba6. Closes #780. --- t/app/controller/dashboard.t | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index a87232e9b..4e62028b5 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -609,9 +609,19 @@ FixMyStreet::override_config { } subtest 'export as csv' => sub { + make_problem( { + detail => "this report\nis split across\nseveral lines", + state => "confirmed", + conf_dt => DateTime->now(), + } ); $mech->get_ok('/dashboard?export=1'); - my @lines = split /\n/, $mech->content; - is scalar @lines, 6, '1 (header) + 5 (reports) = 6 lines'; + open my $data_handle, '<', \$mech->content; + my $csv = Text::CSV->new( { binary => 1 } ); + my @rows; + while ( my $row = $csv->getline( $data_handle ) ) { + push @rows, $row; + } + is scalar @rows, 7, '1 (header) + 6 (reports) = 7 lines'; }; }; restore_time; @@ -623,7 +633,7 @@ sub make_problem { title => 'a problem', name => 'a user', anonymous => 1, - detail => 'some detail', + detail => $args->{detail} || 'some detail', state => $args->{state}, confirmed => $args->{conf_dt}, whensent => $args->{conf_dt}, -- cgit v1.2.3