diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 5 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 111 |
2 files changed, 116 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ac462e293..003de943d 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -800,6 +800,11 @@ sub process_report : Private { if ( $contacts[0]->area_id == 2482 ) { for my $field ( qw/ fms_extra_title first_name last_name / ) { my $value = $c->request->param( $field ); + next if ( + $c->cobrand->moniker ne 'bromley' && + ( $field eq 'first_name' || $field eq 'last_name' ) + ); + if ( !$value ) { $c->stash->{field_errors}->{ $field } = _('This information is required'); } diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 0d9a45c40..9f4807284 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -48,6 +48,12 @@ 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', +} ); ok $contact1, "created test contact 1"; ok $contact2, "created test contact 2"; ok $contact3, "created test contact 3"; @@ -725,6 +731,111 @@ subtest "check that a lat/lon off coast leads to /around" => sub { }; +for my $test ( + { + desc => 'title shown for bromley problem on main site', + host => 'http://www.fixmystreet.com', + extra => [ + { + name => 'fms_extra_title', + value => 'Mr', + description => 'FMS_EXTRA_TITLE', + }, + ], + }, + { + desc => + 'title, first and last name shown for bromley problem on cobrand', + host => 'http://bromley.fixmystreet.com', + first_name => 'Test', + last_name => 'User', + 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', + }, + ], + }, + ) +{ + subtest $test->{desc} => sub { + $mech->host( $test->{host} ); + + $mech->log_out_ok; + + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'BR1 3UH', } }, + "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'); + ok exists( $fields->{fms_extra_title} ), 'user title field 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', + fms_extra_title => 'Mr', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + password_register => '', + }; + + 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 $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_deeply $extras, $test->{extra}, 'extra contains correct values'; + + use Data::Printer; + p $extras; + + $user->problems->delete; + $user->delete; + }; +} + $contact1->delete; $contact2->delete; $contact3->delete; |