aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/report_new.t
diff options
context:
space:
mode:
authorDave Whiteland <dave@mysociety.org>2012-05-29 15:57:41 +0100
committerDave Whiteland <dave@mysociety.org>2012-05-29 15:57:41 +0100
commit67da8efc720d2d0bd22bd9fe8655b7e983b35bb4 (patch)
tree38b8570647124df06c637d4b923f6010211ef328 /t/app/controller/report_new.t
parent40b3a51d33caefa8f5fb97ce9be18ef936c7e260 (diff)
parent131ff6e9bf3626d6a8fff6ae54669d250148a63a (diff)
Merge remote branch 'origin/master' into fmb-read-only
Conflicts: bin/send-reports perllib/FixMyStreet/Cobrand/Default.pm perllib/FixMyStreet/Cobrand/FixMyStreet.pm templates/web/fixmystreet/alert/index.html templates/web/fixmystreet/around/display_location.html web/cobrands/fixmystreet/_layout.scss web/js/map-OpenLayers.js
Diffstat (limited to 't/app/controller/report_new.t')
-rw-r--r--t/app/controller/report_new.t228
1 files changed, 223 insertions, 5 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 625c7531f..29fb650e5 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -6,10 +6,14 @@ use utf8;
use FixMyStreet::TestMech;
use Web::Scraper;
+use Path::Class;
my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/report/new');
+my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify;
+ok -e $sample_file, "sample file $sample_file exists";
+
subtest "test that bare requests to /report/new get redirected" => sub {
$mech->get_ok('/report/new');
@@ -48,9 +52,23 @@ my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
category => 'Trees',
email => 'trees@example.com',
} );
+my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2482, # Bromley
+ category => 'Trees',
+ email => 'trees@example.com',
+} );
+my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2651, # Edinburgh
+ category => 'Trees',
+ email => 'trees@example.com',
+} );
ok $contact1, "created test contact 1";
ok $contact2, "created test contact 2";
ok $contact3, "created test contact 3";
+ok $contact4, "created test contact 4";
+ok $contact5, "created test contact 5";
# test that the various bit of form get filled in and errors correctly
# generated.
@@ -282,6 +300,69 @@ foreach my $test (
},
errors => [ 'Please enter a subject', 'Please enter some details', ],
},
+ {
+ msg => 'non-photo upload gives error',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Title',
+ detail => 'Detail',
+ photo => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ],
+ name => 'Bob Jones',
+ may_show_name => '1',
+ email => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {
+ photo => '',
+ },
+ errors => [ "Please upload a JPEG image only" ],
+ },
+ {
+ msg => 'bad photo upload gives error',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Title',
+ detail => 'Detail',
+ photo => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ],
+ name => 'Bob Jones',
+ may_show_name => '1',
+ email => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {
+ photo => '',
+ },
+ errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ],
+ },
+ {
+ msg => 'photo with octet-stream gets through okay',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => '',
+ detail => 'Detail',
+ photo => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ],
+ name => 'Bob Jones',
+ may_show_name => '1',
+ email => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {
+ photo => '',
+ },
+ errors => [ "Please enter a subject" ],
+ },
)
{
subtest "check form errors where $test->{msg}" => sub {
@@ -293,7 +374,7 @@ foreach my $test (
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', },
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
"follow 'skip this step' link" );
# submit the main form
@@ -473,7 +554,7 @@ subtest "test password errors for a user who is signing in as they report" => su
"submit location" );
# click through to the report page
- $mech->follow_link_ok( { text => 'Skip this step', },
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
"follow 'skip this step' link" );
$mech->submit_form_ok(
@@ -520,7 +601,7 @@ subtest "test report creation for a user who is signing in as they report" => su
"submit location" );
# click through to the report page
- $mech->follow_link_ok( { text => 'Skip this step', },
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
"follow 'skip this step' link" );
$mech->submit_form_ok(
@@ -614,7 +695,7 @@ foreach my $test (
"submit location" );
# click through to the report page
- $mech->follow_link_ok( { text => 'Skip this step', },
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
"follow 'skip this step' link" );
# check that the fields are correctly prefilled
@@ -717,7 +798,7 @@ subtest "check that a lat/lon off coast leads to /around" => sub {
is $mech->uri->path, '/around', "redirected to '/around'";
is_deeply #
- $mech->page_errors,
+ $mech->form_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.' ], #
@@ -725,8 +806,145 @@ subtest "check that a lat/lon off coast leads to /around" => sub {
};
+for my $test (
+ {
+ desc => 'user title not set if not bromley problem',
+ host => 'http://www.fixmystreet.com',
+ postcode => 'EH99 1SP',
+ fms_extra_title => '',
+ extra => undef,
+ user_title => undef,
+ },
+ {
+ desc => 'title shown for bromley problem on main site',
+ host => 'http://www.fixmystreet.com',
+ postcode => 'BR1 3UH',
+ fms_extra_title => 'MR',
+ extra => [
+ {
+ name => 'fms_extra_title',
+ value => 'MR',
+ description => 'FMS_EXTRA_TITLE',
+ },
+ ],
+ user_title => 'MR',
+ },
+ {
+ desc =>
+ 'title, first and last name shown for bromley problem on cobrand',
+ host => 'http://bromley.fixmystreet.com',
+ postcode => 'BR1 3UH',
+ first_name => 'Test',
+ last_name => 'User',
+ fms_extra_title => 'MR',
+ extra => [
+ {
+ name => 'fms_extra_title',
+ value => 'MR',
+ description => 'FMS_EXTRA_TITLE',
+ },
+ {
+ name => 'first_name',
+ value => 'Test',
+ description => 'FIRST_NAME',
+ },
+ {
+ name => 'last_name',
+ value => 'User',
+ description => 'LAST_NAME',
+ },
+ ],
+ user_title => 'MR',
+ },
+ )
+{
+ subtest $test->{desc} => sub {
+ $mech->host( $test->{host} );
+
+ $mech->log_out_ok;
+ $mech->clear_emails_ok;
+
+ $mech->get_ok('/');
+ $mech->submit_form_ok( { with_fields => { pc => $test->{postcode}, } },
+ "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');
+ if ( $test->{fms_extra_title} ) {
+ ok exists( $fields->{fms_extra_title} ), 'user title field displayed';
+ } else {
+ ok !exists( $fields->{fms_extra_title} ), 'user title field not displayed';
+ }
+ if ( $test->{first_name} ) {
+ ok exists( $fields->{first_name} ), 'first name field displayed';
+ ok exists( $fields->{last_name} ), 'last name field displayed';
+ ok !exists( $fields->{name} ), 'no name field displayed';
+ }
+ else {
+ ok !exists( $fields->{first_name} ),
+ 'first name field not displayed';
+ ok !exists( $fields->{last_name} ), 'last name field not displayed';
+ ok exists( $fields->{name} ), 'name field displayed';
+ }
+
+ my $submission_fields = {
+ title => "Test Report",
+ detail => 'Test report details.',
+ photo => '',
+ email => 'firstlast@example.com',
+ may_show_name => '1',
+ phone => '07903 123 456',
+ category => 'Trees',
+ password_register => '',
+ };
+
+ $submission_fields->{fms_extra_title} = $test->{fms_extra_title}
+ if $test->{fms_extra_title};
+
+ if ( $test->{first_name} ) {
+ $submission_fields->{first_name} = $test->{first_name};
+ $submission_fields->{last_name} = $test->{last_name};
+ }
+ else {
+ $submission_fields->{name} = 'Test User';
+ }
+
+ $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);
+
+ my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find( { email => 'firstlast@example.com' } );
+
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+ my $extras = $report->extra;
+ is $user->title, $test->{'user_title'}, 'user title correct';
+ is_deeply $extras, $test->{extra}, 'extra contains correct values';
+
+ $user->problems->delete;
+ $user->alerts->delete;
+ $user->delete;
+ };
+}
+
$contact1->delete;
$contact2->delete;
$contact3->delete;
+$contact4->delete;
+$contact5->delete;
done_testing();