diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 15 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 47 |
2 files changed, 55 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 43ce0e876..3247ad0a1 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -708,22 +708,23 @@ sub process_user : Private { my $report = $c->stash->{report}; + # Extract all the params to a hash to make them easier to work with + my %params = map { $_ => scalar $c->req->param($_) } + ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' ); + + my $user_title = Utils::trim_text( $params{fms_extra_title} ); + # The user is already signed in if ( $c->user_exists ) { my $user = $c->user->obj; - my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone', 'fms_extra_title' ); $user->name( Utils::trim_text( $params{name} ) ) if $params{name}; $user->phone( Utils::trim_text( $params{phone} ) ); - $user->title( Utils::trim_text( $params{fms_extra_title} ) ); + $user->title( $user_title ) if $user_title; $report->user( $user ); $report->name( $user->name ); return 1; } - # Extract all the params to a hash to make them easier to work with - my %params = map { $_ => scalar $c->req->param($_) } - ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' ); - # cleanup the email address my $email = $params{email} ? lc $params{email} : ''; $email =~ s{\s+}{}g; @@ -751,7 +752,7 @@ sub process_user : Private { $report->user->phone( Utils::trim_text( $params{phone} ) ); $report->user->password( Utils::trim_text( $params{password_register} ) ) if $params{password_register}; - $report->user->title( Utils::trim_text( $params{fms_extra_title} ) ); + $report->user->title( $user_title ) if $user_title; $report->name( Utils::trim_text( $params{name} ) ); return 1; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 2e7e60f75..77afb071c 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -1028,6 +1028,53 @@ for my $test ( }; } +subtest 'user title not reset if no user title in submission' => sub { + $mech->log_out_ok; + $mech->host( 'http://fixmystreet.com' ); + + my $user = $mech->log_in_ok( 'userwithtitle@example.com' ); + + ok $user->update( + { + name => 'Has Title', + phone => '0789 654321', + title => 'MR', + } + ), + "set users details"; + + + my $submission_fields = { + title => "Test Report", + detail => 'Test report details.', + photo => '', + name => 'Has Title', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + }; + + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP', } }, + "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 not displayed'; + + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + + $user->discard_changes; + my $report = $user->problems->first; + ok $report, "Found report"; + is $report->title, "Test Report", "Report title correct"; + is $user->title, 'MR', 'User title unchanged'; +}; + SKIP: { skip( "Need 'lichfielddc' in ALLOWED_COBRANDS config", 100 ) unless FixMyStreet::Cobrand->exists('lichfielddc'); |