diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/admin.t | 178 | ||||
-rw-r--r-- | t/app/controller/auth.t | 160 | ||||
-rw-r--r-- | t/app/controller/auth_phone.t | 94 | ||||
-rw-r--r-- | t/app/controller/auth_profile.t | 262 | ||||
-rw-r--r-- | t/app/controller/auth_social.t | 12 | ||||
-rw-r--r-- | t/app/controller/dashboard.t | 4 | ||||
-rw-r--r-- | t/app/controller/report_as_other.t | 8 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 2 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 6 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 50 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 5 | ||||
-rw-r--r-- | t/app/controller/report_new_text.t | 371 | ||||
-rw-r--r-- | t/app/controller/report_update_text.t | 307 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 50 |
14 files changed, 1253 insertions, 256 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index bd0f9e408..9f1b0cfb9 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -316,7 +316,7 @@ foreach my $test ( detail => 'Detail for Report to Edit', state => 'confirmed', name => 'Test User', - email => $user->email, + username => $user->email, anonymous => 0, flagged => undef, non_public => undef, @@ -332,7 +332,7 @@ foreach my $test ( detail => 'Detail for Report to Edit', state => 'confirmed', name => 'Test User', - email => $user->email, + username => $user->email, anonymous => 0, flagged => undef, non_public => undef, @@ -348,7 +348,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'confirmed', name => 'Test User', - email => $user->email, + username => $user->email, anonymous => 0, flagged => undef, non_public => undef, @@ -365,7 +365,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'confirmed', name => 'Edited User', - email => $user->email, + username => $user->email, anonymous => 0, flagged => undef, non_public => undef, @@ -384,12 +384,12 @@ foreach my $test ( detail => 'Edited Detail', state => 'confirmed', name => 'Edited User', - email => $user->email, + username => $user->email, anonymous => 0, flagged => 'on', non_public => undef, }, - changes => { email => $user2->email, }, + changes => { username => $user2->email, }, log_entries => [qw/edit edit edit edit edit/], resend => 0, user => $user2, @@ -401,7 +401,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'confirmed', name => 'Edited User', - email => $user2->email, + username => $user2->email, anonymous => 0, flagged => 'on', non_public => undef, @@ -417,7 +417,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'unconfirmed', name => 'Edited User', - email => $user2->email, + username => $user2->email, anonymous => 0, flagged => 'on', non_public => undef, @@ -433,7 +433,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'confirmed', name => 'Edited User', - email => $user2->email, + username => $user2->email, anonymous => 0, flagged => 'on', non_public => undef, @@ -450,7 +450,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'fixed', name => 'Edited User', - email => $user2->email, + username => $user2->email, anonymous => 0, flagged => 'on', non_public => undef, @@ -468,7 +468,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'hidden', name => 'Edited User', - email => $user2->email, + username => $user2->email, anonymous => 0, flagged => 'on', non_public => undef, @@ -489,7 +489,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'confirmed', name => 'Edited User', - email => $user2->email, + username => $user2->email, anonymous => 1, flagged => 'on', non_public => undef, @@ -507,7 +507,7 @@ foreach my $test ( detail => 'Edited Detail', state => 'confirmed', name => 'Edited User', - email => $user2->email, + username => $user2->email, anonymous => 1, flagged => 'on', non_public => undef, @@ -555,7 +555,7 @@ foreach my $test ( $test->{changes}->{flagged} = 1 if $test->{changes}->{flagged}; $test->{changes}->{non_public} = 1 if $test->{changes}->{non_public}; - is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'email' } keys %{ $test->{changes} }; + is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'username' } keys %{ $test->{changes} }; if ( $test->{user} ) { is $report->user->id, $test->{user}->id, 'user changed'; @@ -603,7 +603,7 @@ subtest 'change email to new user' => sub { detail => $report->detail, state => $report->state, name => $report->name, - email => $report->user->email, + username => $report->user->email, category => 'Other', anonymous => 1, flagged => 'on', @@ -616,12 +616,10 @@ subtest 'change email to new user' => sub { is_deeply( $mech->visible_form_values(), $fields, 'initial form values' ); my $changes = { - email => 'test3@example.com' + username => 'test3@example.com' }; - $user3 = - FixMyStreet::App->model('DB::User') - ->find( { email => 'test3@example.com', name => 'Test User 2' } ); + $user3 = FixMyStreet::App->model('DB::User')->find( { email => 'test3@example.com' } ); ok !$user3, 'user not in database'; @@ -640,9 +638,7 @@ subtest 'change email to new user' => sub { 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' } ); + $user3 = FixMyStreet::App->model('DB::User')->find( { email => 'test3@example.com' } ); $report->discard_changes; @@ -657,18 +653,18 @@ subtest 'adding email to abuse list from report page' => sub { $abuse->delete if $abuse; $mech->get_ok( '/admin/report_edit/' . $report->id ); - $mech->content_contains('Ban email address'); + $mech->content_contains('Ban user'); $mech->click_ok('banuser'); - $mech->content_contains('Email added to abuse list'); - $mech->content_contains('<small>(Email in abuse table)</small>'); + $mech->content_contains('User added to abuse list'); + $mech->content_contains('<small>(User in abuse table)</small>'); $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } ); ok $abuse, 'entry created in abuse table'; $mech->get_ok( '/admin/report_edit/' . $report->id ); - $mech->content_contains('<small>(Email in abuse table)</small>'); + $mech->content_contains('<small>(User in abuse table)</small>'); }; subtest 'flagging user from report page' => sub { @@ -742,7 +738,7 @@ for my $test ( state => 'confirmed', name => '', anonymous => 1, - email => 'test@example.com', + username => 'test@example.com', }, changes => { text => 'this is a changed update', @@ -757,7 +753,7 @@ for my $test ( state => 'confirmed', name => '', anonymous => 1, - email => 'test@example.com', + username => 'test@example.com', }, changes => { name => 'A User', @@ -772,7 +768,7 @@ for my $test ( state => 'confirmed', name => 'A User', anonymous => 1, - email => 'test@example.com', + username => 'test@example.com', }, changes => { anonymous => 0, @@ -787,11 +783,10 @@ for my $test ( state => 'confirmed', name => 'A User', anonymous => 0, - email => $update->user->email, - email => 'test@example.com', + username => 'test@example.com', }, changes => { - email => 'test2@example.com', + username => 'test2@example.com', }, log_count => 4, log_entries => [qw/edit edit edit edit/], @@ -804,7 +799,7 @@ for my $test ( state => 'confirmed', name => 'A User', anonymous => 0, - email => 'test2@example.com', + username => 'test2@example.com', }, changes => { state => 'unconfirmed', @@ -819,7 +814,7 @@ for my $test ( state => 'unconfirmed', name => 'A User', anonymous => 0, - email => 'test2@example.com', + username => 'test2@example.com', }, changes => { text => 'this is a twice changed update', @@ -849,7 +844,7 @@ for my $test ( $update->discard_changes; - is $update->$_, $test->{changes}->{$_} for grep { $_ ne 'email' } keys %{ $test->{changes} }; + is $update->$_, $test->{changes}->{$_} for grep { $_ ne 'username' } keys %{ $test->{changes} }; if ( $test->{changes}{state} && $test->{changes}{state} eq 'confirmed' ) { isnt $update->confirmed, undef; } @@ -935,9 +930,7 @@ for my $test ( } subtest 'editing update email creates new user if required' => sub { - my $user = FixMyStreet::App->model('DB::User')->find( - { email => 'test4@example.com' } - ); + my $user = FixMyStreet::App->model('DB::User')->find( { email => 'test4@example.com' } ); $user->delete if $user; @@ -946,14 +939,12 @@ subtest 'editing update email creates new user if required' => sub { state => 'hidden', name => 'A User', anonymous => 0, - email => 'test4@example.com', + username => 'test4@example.com', }; $mech->submit_form_ok( { with_fields => $fields } ); - $user = FixMyStreet::App->model('DB::User')->find( - { email => 'test4@example.com' } - ); + $user = FixMyStreet::App->model('DB::User')->find( { email => 'test4@example.com' } ); is_deeply $mech->visible_form_values, $fields, 'submitted form values'; @@ -970,18 +961,18 @@ subtest 'adding email to abuse list from update page' => sub { $abuse->delete if $abuse; $mech->get_ok( '/admin/update_edit/' . $update->id ); - $mech->content_contains('Ban email address'); + $mech->content_contains('Ban user'); $mech->click_ok('banuser'); - $mech->content_contains('Email added to abuse list'); - $mech->content_contains('<small>(Email in abuse table)</small>'); + $mech->content_contains('User added to abuse list'); + $mech->content_contains('<small>(User in abuse table)</small>'); $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } ); ok $abuse, 'entry created in abuse table'; $mech->get_ok( '/admin/update_edit/' . $update->id ); - $mech->content_contains('<small>(Email in abuse table)</small>'); + $mech->content_contains('<small>(User in abuse table)</small>'); }; subtest 'flagging user from update page' => sub { @@ -1029,13 +1020,12 @@ subtest 'hiding comment marked as fixed reopens report' => sub { $report->state('fixed - user'); $report->update; - my $fields = { text => 'this is a changed update', state => 'hidden', name => 'A User', anonymous => 0, - email => 'test2@example.com', + username => 'test2@example.com', }; $mech->submit_form_ok( { with_fields => $fields } ); @@ -1092,7 +1082,7 @@ subtest 'report search' => sub { subtest 'search abuse' => sub { $mech->get_ok( '/admin/users?search=example' ); - $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>\(Email in abuse table}s); + $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>\(User in abuse table}s); }; subtest 'show flagged entries' => sub { @@ -1168,6 +1158,69 @@ $user->update; my $southend = $mech->create_body_ok(2607, 'Southend-on-Sea Borough Council'); +for my $test ( + { + desc => 'add user - blank form', + fields => { + email => '', email_verified => 0, + phone => '', phone_verified => 0, + }, + error => ['Please verify at least one of email/phone', 'Please enter a name'], + }, + { + desc => 'add user - blank, verify phone', + fields => { + email => '', email_verified => 0, + phone => '', phone_verified => 1, + }, + error => ['Please enter a valid email or phone number', 'Please enter a name'], + }, + { + desc => 'add user - bad email', + fields => { + name => 'Norman', + email => 'bademail', email_verified => 0, + phone => '', phone_verified => 0, + }, + error => ['Please enter a valid email'], + }, + { + desc => 'add user - bad phone', + fields => { + name => 'Norman', + phone => '01214960000000', phone_verified => 1, + }, + error => ['Please check your phone number is correct'], + }, + { + desc => 'add user - landline', + fields => { + name => 'Norman Name', + phone => '+441214960000', + phone_verified => 1, + }, + error => ['Please enter a mobile number'], + }, + { + desc => 'add user - good details', + fields => { + name => 'Norman Name', + phone => '+61491570156', + phone_verified => 1, + }, + }, +) { + subtest $test->{desc} => sub { + $mech->get_ok('/admin/users'); + $mech->submit_form_ok( { with_fields => $test->{fields} } ); + if ($test->{error}) { + $mech->content_contains($_) for @{$test->{error}}; + } else { + $mech->content_contains('Updated'); + } + }; +} + my %default_perms = ( "permissions[moderate]" => undef, "permissions[planned_reports]" => undef, @@ -1358,6 +1411,32 @@ FixMyStreet::override_config { } }; +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + SMS_AUTHENTICATION => 1, +}, sub { + subtest "Test edit user add verified phone" => sub { + $mech->get_ok( '/admin/user_edit/' . $user->id ); + $mech->submit_form_ok( { with_fields => { + phone => '+61491570157', + phone_verified => 1, + } } ); + $mech->content_contains( 'Updated!' ); + }; + + subtest "Test changing user to an existing one" => sub { + my $existing_user = $mech->create_user_ok('existing@example.com', name => 'Existing User'); + $mech->create_problems_for_body(2, 2514, 'Title', { user => $existing_user }); + my $count = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->count; + $mech->get_ok( '/admin/user_edit/' . $user->id ); + $mech->submit_form_ok( { with_fields => { email => 'existing@example.com' } }, 'submit email change' ); + is $mech->uri->path, '/admin/user_edit/' . $existing_user->id, 'redirected'; + my $p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $existing_user->id })->count; + is $p, $count + 2, 'reports merged'; + }; + +}; + subtest "Test setting a report from unconfirmed to something else doesn't cause a front end error" => sub { $report->update( { confirmed => undef, state => 'unconfirmed', non_public => 0 } ); $mech->get_ok("/admin/report_edit/$report_id"); @@ -1380,6 +1459,7 @@ subtest "Check admin_base_url" => sub { $mech->log_out_ok; subtest "Users without from_body can't access admin" => sub { + $user = FixMyStreet::App->model('DB::User')->find( { email => 'existing@example.com' } ); $user->from_body( undef ); $user->update; diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index cb7d16969..661f99412 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -4,7 +4,6 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; my $test_email = 'test@example.com'; -my $test_email2 = 'test@example.net'; my $test_email3 = 'newuser@example.org'; my $test_password = 'foobar'; @@ -41,8 +40,8 @@ for my $test ( $mech->submit_form_ok( { form_name => 'general_auth', - fields => { email => $email, }, - button => 'email_sign_in', + fields => { username => $email, }, + button => 'sign_in_by_code', }, "try to create an account with email '$email'" ); @@ -60,8 +59,8 @@ $mech->get_ok('/auth'); $mech->submit_form_ok( { form_name => 'general_auth', - fields => { email => $test_email, }, - button => 'email_sign_in', + fields => { username => $test_email, password_register => $test_password }, + button => 'sign_in_by_code', }, "create an account for '$test_email'" ); @@ -101,125 +100,6 @@ $mech->not_logged_in_ok; $mech->log_out_ok; } -# get a sign in email and change password -{ - $mech->clear_emails_ok; - $mech->get_ok('/auth'); - $mech->submit_form_ok( - { - form_name => 'general_auth', - fields => { - email => "$test_email", - r => 'faq', # Just as a test - }, - button => 'email_sign_in', - }, - "email_sign_in with '$test_email'" - ); - - # rest is as before so no need to test - - # follow link and change password - check not prompted for old password - $mech->not_logged_in_ok; - - my $link = $mech->get_link_from_email; - $mech->get_ok($link); - is $mech->uri->path, '/faq', "redirected to the Help page"; - - $mech->get_ok('/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', 'token' ], - "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"; - - $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" ); - - $user->discard_changes(); - ok $user->password, "user now has a password"; -} - -subtest "Test change email page" => sub { - # Still signed in from the above test - $mech->get_ok('/my'); - $mech->follow_link_ok({url => '/auth/change_email'}); - $mech->submit_form_ok( - { with_fields => { email => "" } }, - "submit blank change email form" - ); - $mech->content_contains( 'Please enter your email', "found expected error" ); - $mech->submit_form_ok({ with_fields => { email => $test_email2 } }, "change_email to $test_email2"); - is $mech->uri->path, '/auth/change_email', "still on change email page"; - $mech->content_contains( 'Now check your email', "found check your email" ); - my $link = $mech->get_link_from_email; - $mech->get_ok($link); - is $mech->uri->path, '/auth/change_email/success', "redirected to the change_email page"; - $mech->content_contains('successfully confirmed'); - ok(FixMyStreet::App->model('DB::User')->find( { email => $test_email2 } ), "got a user"); - - ok(FixMyStreet::App->model('DB::User')->create( { email => $test_email } ), "created old user"); - $mech->submit_form_ok({ with_fields => { email => $test_email } }, - "change_email back to $test_email" - ); - is $mech->uri->path, '/auth/change_email', "still on change email page"; - $mech->content_contains( 'Now check your email', "found check your email" ); - $link = $mech->get_link_from_email; - $mech->get_ok($link); - is $mech->uri->path, '/auth/change_email/success', "redirected to the change_email page"; - $mech->content_contains('successfully confirmed'); - - # Test you can't click the link if logged out - $mech->submit_form_ok({ with_fields => { email => $test_email } }, - "change_email back to $test_email" - ); - is $mech->uri->path, '/auth/change_email', "still on change email page"; - $mech->content_contains( 'Now check your email', "found check your email" ); - $link = $mech->get_link_from_email; - $mech->log_out_ok; - $mech->get_ok($link); - isnt $mech->uri->path, '/auth/change_email/success', "not redirected to the change_email page"; - $mech->content_contains('Sorry'); -}; - foreach my $remember_me ( '1', '0' ) { subtest "sign in using valid details (remember_me => '$remember_me')" => sub { $mech->get_ok('/auth'); @@ -227,11 +107,11 @@ foreach my $remember_me ( '1', '0' ) { { form_name => 'general_auth', fields => { - email => $test_email, + username => $test_email, password_sign_in => $test_password, remember_me => ( $remember_me ? 1 : undef ), }, - button => 'sign_in', + button => 'sign_in_by_password', }, "sign in with '$test_email' & '$test_password'" ); @@ -253,15 +133,15 @@ $mech->submit_form_ok( { form_name => 'general_auth', fields => { - email => $test_email, + username => $test_email, password_sign_in => 'not the password', }, - button => 'sign_in', + button => 'sign_in_by_password', }, "sign in with '$test_email' & 'not the password'" ); is $mech->uri->path, '/auth', "redirected to correct page"; -$mech->content_contains( 'problem with your email/password combination', 'found error message' ); +$mech->content_contains( 'problem with your login information', 'found error message' ); subtest "sign in but have email form autofilled" => sub { $mech->get_ok('/auth'); @@ -269,11 +149,11 @@ subtest "sign in but have email form autofilled" => sub { { form_name => 'general_auth', fields => { - email => $test_email, + username => $test_email, password_sign_in => $test_password, name => 'Auto-completed from elsewhere', }, - button => 'sign_in', + button => 'sign_in_by_password', }, "sign in with '$test_email' and auto-completed name" ); @@ -289,10 +169,10 @@ subtest "sign in with uppercase email" => sub { { form_name => 'general_auth', fields => { - email => $uc_test_email, + username => $uc_test_email, password_sign_in => $test_password, }, - button => 'sign_in', + button => 'sign_in_by_password', }, "sign in with '$uc_test_email' and auto-completed name" ); @@ -317,8 +197,8 @@ FixMyStreet::override_config { $mech->submit_form_ok( { form_name => 'general_auth', - fields => { email => $test_email3, }, - button => 'email_sign_in', + fields => { username => $test_email3, }, + button => 'sign_in_by_code', }, "create a new account" ); @@ -338,13 +218,13 @@ FixMyStreet::override_config { { form_name => 'general_auth', fields => { - email => "$test_email", + username => "$test_email", password_register => $new_password, r => 'faq', # Just as a test }, - button => 'email_sign_in', + button => 'sign_in_by_code', }, - "email_sign_in with '$test_email'" + "sign_in_by_code with '$test_email'" ); $mech->not_logged_in_ok; @@ -361,10 +241,10 @@ FixMyStreet::override_config { { form_name => 'general_auth', fields => { - email => $test_email, + username => $test_email, password_sign_in => $new_password, }, - button => 'sign_in', + button => 'sign_in_by_password', }, "sign in with '$test_email' and new password" ); diff --git a/t/app/controller/auth_phone.t b/t/app/controller/auth_phone.t new file mode 100644 index 000000000..8673f5c62 --- /dev/null +++ b/t/app/controller/auth_phone.t @@ -0,0 +1,94 @@ +use FixMyStreet::TestMech; + +use t::Mock::Twilio; + +my $twilio = t::Mock::Twilio->new; +LWP::Protocol::PSGI->register($twilio->to_psgi_app, host => 'api.twilio.com'); + +my $mech = FixMyStreet::TestMech->new; + +subtest 'Log in with invalid number, fail' => sub { + FixMyStreet::override_config { + SMS_AUTHENTICATION => 1, + PHONE_COUNTRY => 'GB', + TWILIO_ACCOUNT_SID => 'AC123', + }, sub { + $mech->get_ok('/auth'); + $mech->submit_form_ok({ + form_name => 'general_auth', + fields => { username => '01214960000000' }, + button => 'sign_in_by_code', + }, "sign in using bad number"); + $mech->content_contains('Please check your phone number is correct'); + }; +}; + +subtest 'Log in using landline, fail' => sub { + FixMyStreet::override_config { + SMS_AUTHENTICATION => 1, + PHONE_COUNTRY => 'GB', + TWILIO_ACCOUNT_SID => 'AC123', + }, sub { + $mech->get_ok('/auth'); + $mech->submit_form_ok({ + form_name => 'general_auth', + fields => { username => '01214960000' }, + button => 'sign_in_by_code', + }, "sign in using landline"); + $mech->content_contains('Please enter a mobile number'); + }; +}; + +subtest 'Log in using mobile, by text' => sub { + FixMyStreet::override_config { + SMS_AUTHENTICATION => 1, + PHONE_COUNTRY => 'GB', + TWILIO_ACCOUNT_SID => 'AC123', + }, sub { + $mech->submit_form_ok({ + form_name => 'general_auth', + fields => { username => '+61491570156', password_register => 'secret' }, + button => 'sign_in_by_code', + }, "sign in using mobile"); + + $mech->submit_form_ok({ + with_fields => { code => '00000' } + }, 'submit incorrect code'); + $mech->content_contains('Try again'); + + my $code = $twilio->get_text_code; + $mech->submit_form_ok({ + with_fields => { code => $code } + }, 'submit correct code'); + + my $user = FixMyStreet::App->model('DB::User')->find( { phone => '+61491570156' } ); + ok $user, "user created"; + is $mech->uri->path, '/my', "redirected to the 'my' section of site"; + $mech->logged_in_ok; + $mech->log_out_ok; + }; +}; + +subtest 'Log in using mobile, by password' => sub { + FixMyStreet::override_config { + SMS_AUTHENTICATION => 1, + }, sub { + $mech->get_ok('/auth'); + $mech->submit_form_ok({ + form_name => 'general_auth', + fields => { username => '+61491570156', password_sign_in => 'incorrect' }, + button => 'sign_in_by_password', + }, "sign in using wrong password"); + $mech->content_contains('There was a problem'); + $mech->submit_form_ok({ + form_name => 'general_auth', + fields => { username => '+61491570156', password_sign_in => 'secret' }, + button => 'sign_in_by_password', + }, "sign in using password"); + + is $mech->uri->path, '/my', "redirected to the 'my' section of site"; + $mech->logged_in_ok; + }; +}; + +done_testing(); diff --git a/t/app/controller/auth_profile.t b/t/app/controller/auth_profile.t new file mode 100644 index 000000000..519086ff5 --- /dev/null +++ b/t/app/controller/auth_profile.t @@ -0,0 +1,262 @@ +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +use t::Mock::Twilio; + +my $twilio = t::Mock::Twilio->new; +LWP::Protocol::PSGI->register($twilio->to_psgi_app, host => 'api.twilio.com'); + +my $test_email = 'test@example.com'; +my $test_email2 = 'test@example.net'; +my $test_password = 'foobar'; + +END { + done_testing(); +} + +# get a sign in email and change password +subtest "Test change password page" => sub { + $mech->clear_emails_ok; + $mech->get_ok('/auth'); + $mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { + username => $test_email, + r => 'faq', # Just as a test + }, + button => 'sign_in_by_code', + }, + "sign_in_by_code with '$test_email'" + ); + + # follow link and change password - check not prompted for old password + $mech->not_logged_in_ok; + + my $link = $mech->get_link_from_email; + $mech->get_ok($link); + is $mech->uri->path, '/faq', "redirected to the Help page"; + + $mech->get_ok('/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', 'token' ], + "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"; + + $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" ); + + $user->discard_changes(); + ok $user->password, "user now has a password"; +}; + +subtest "Test change email page" => sub { + $mech->create_problems_for_body(1, 2514, 'Title1', { user => FixMyStreet::DB->resultset('User')->find( { email => $test_email } ) } ); + + # Still signed in from the above test + $mech->get_ok('/my'); + $mech->follow_link_ok({url => '/auth/change_email'}); + $mech->submit_form_ok( + { with_fields => { email => "" } }, + "submit blank change email form" + ); + $mech->content_contains( 'Please enter your email', "found expected error" ); + $mech->submit_form_ok({ with_fields => { email => $test_email2 } }, "change_email to $test_email2"); + is $mech->uri->path, '/auth/change_email', "still on change email page"; + $mech->content_contains( 'Now check your email', "found check your email" ); + my $link = $mech->get_link_from_email; + $mech->get_ok($link); + is $mech->uri->path, '/my', "redirected to /my page"; + $mech->content_contains('successfully confirmed'); + ok(FixMyStreet::App->model('DB::User')->find( { email => $test_email2 } ), "got a user"); + + my $p = FixMyStreet::DB->resultset("Problem")->first; + is $p->user->email, $test_email2, 'problem user updated'; + + my $user1 = FixMyStreet::App->model('DB::User')->create( { email => $test_email, email_verified => 1 } ); + ok($user1, "created old user"); + $mech->create_problems_for_body(1, 2514, 'Title1', { user => $user1 } ); + + $mech->follow_link_ok({url => '/auth/change_email'}); + $mech->submit_form_ok({ with_fields => { email => $test_email } }, + "change_email back to $test_email" + ); + is $mech->uri->path, '/auth/change_email', "still on change email page"; + $mech->content_contains( 'Now check your email', "found check your email" ); + $link = $mech->get_link_from_email; + $mech->get_ok($link); + is $mech->uri->path, '/my', "redirected to /my page"; + $mech->content_contains('successfully confirmed'); + + for (FixMyStreet::DB->resultset("Problem")->all) { + is $_->user->email, $test_email; + } + + # Test you can't click the link if logged out + $mech->follow_link_ok({url => '/auth/change_email'}); + $mech->submit_form_ok({ with_fields => { email => $test_email } }, + "change_email back to $test_email" + ); + is $mech->uri->path, '/auth/change_email', "still on change email page"; + $mech->content_contains( 'Now check your email', "found check your email" ); + $link = $mech->get_link_from_email; + $mech->log_out_ok; + $mech->get_ok($link); + isnt $mech->uri->path, '/auth/change_email/success', "not redirected to the change_email page"; + $mech->content_contains('Sorry'); +}; + +my $test_phone_bad = '01214960000000'; +my $test_landline = '01214960000'; +my $test_mobile = '+61491570156'; +my $test_mobile2 = '+61491570157'; + +my $user_mob2 = FixMyStreet::App->model('DB::User')->create( { + phone => $test_mobile, + phone_verified => 1, + name => 'Aus Mobile user', +} ); +$mech->create_problems_for_body(1, 2514, 'Title1', { user => $user_mob2 } ); + +subtest "Test add/verify/change phone page" => sub { + $mech->get_ok('/auth'); + $mech->submit_form_ok({ + with_fields => { + username => $test_email, + password_sign_in => $test_password, + }, + }); + + $mech->follow_link_ok({url => '/auth/change_phone'}); + $mech->submit_form_ok( { with_fields => { username => "" } }, "submit blank change phone form" ); + is $mech->uri->path, '/my', 'redirected'; + $mech->content_contains('successfully removed'); + + $mech->follow_link_ok({url => '/auth/change_phone'}); + $mech->submit_form_ok({ with_fields => { username => $test_phone_bad } }); + $mech->content_contains( 'Please check your phone number is correct', "found expected error" ); + + FixMyStreet::override_config({ + SMS_AUTHENTICATION => 1, + PHONE_COUNTRY => 'GB', + }, sub { + $mech->submit_form_ok({ with_fields => { username => $test_landline } }); + }); + is $mech->uri->path, '/my', 'redirected'; + $mech->content_contains('successfully added'); + + FixMyStreet::override_config({ + SMS_AUTHENTICATION => 1, + PHONE_COUNTRY => 'GB', + }, sub { + $mech->follow_link_ok({url => '/auth/verify/phone'}); + $mech->submit_form_ok({ with_fields => { username => $test_landline } }); + }); + $mech->content_contains( 'Please enter a mobile number', "found expected error" ); + + FixMyStreet::override_config({ + SMS_AUTHENTICATION => 1, + TWILIO_ACCOUNT_SID => 'AC123', + }, sub { + $mech->submit_form_ok({ with_fields => { username => $test_mobile } }); + }); + is $mech->uri->path, '/auth/verify/phone', "still on change phone page"; + $mech->content_contains( 'Now check your phone', "found check your phone" ); + + $mech->submit_form_ok({ + with_fields => { code => '00000' } + }, 'submit incorrect code'); + $mech->content_contains('Try again'); + + my $code = $twilio->get_text_code; + $mech->submit_form_ok({ + with_fields => { code => $code } + }, 'submit correct code'); + + my $user = FixMyStreet::App->model('DB::User')->find( { phone => $test_mobile } ); + ok $user, "user exists"; + is $user->email_verified, 1; + is $user->email, $test_email, 'email still same'; + is $mech->uri->path, '/my', "redirected to /my page"; + $mech->content_contains('successfully verified'); + $mech->logged_in_ok; +}; + +subtest "Test change phone to existing account" => sub { + $mech->get_ok('/auth'); + FixMyStreet::override_config({ + SMS_AUTHENTICATION => 1, + }, sub { + $mech->submit_form_ok({ + with_fields => { + username => $test_mobile, + password_sign_in => $test_password, + }, + }); + }); + + $mech->follow_link_ok({url => '/auth/change_phone'}); + + FixMyStreet::override_config({ + SMS_AUTHENTICATION => 1, + TWILIO_ACCOUNT_SID => 'AC123', + }, sub { + $mech->submit_form_ok({ with_fields => { username => $test_mobile2 } }); + }); + is $mech->uri->path, '/auth/change_phone', "still on change phone page"; + $mech->content_contains( 'Now check your phone', "found check your phone" ); + + my $code = $twilio->get_text_code; + $mech->submit_form_ok({ with_fields => { code => $code } }, 'submit correct code'); + + my $user = FixMyStreet::App->model('DB::User')->find( { phone => $test_mobile } ); + ok !$user, 'old user does not exist'; + $user = FixMyStreet::App->model('DB::User')->find( { phone => $test_mobile2 } ); + ok $user, "new mobile user exists"; + is $user->email_verified, 1; + is $user->email, $test_email, 'email still same'; + is $mech->uri->path, '/my', "redirected to /my page"; + $mech->content_contains('successfully verified'); + + for (FixMyStreet::DB->resultset("Problem")->all) { + is $_->user->email, $test_email; + } +}; diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t index 726d264bd..031fb8d9e 100644 --- a/t/app/controller/auth_social.t +++ b/t/app/controller/auth_social.t @@ -102,11 +102,7 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) { $mech->content_contains('We need your email address, please give it below.'); # We don't have an email, so check that we can still submit it, # and the ID carries through the confirmation - if ($page eq 'update') { - $fields->{rznvy} = $fb_email; - } else { - $fields->{email} = $fb_email; - } + $fields->{username} = $fb_email; $fields->{name} = 'Ffion Tester'; $mech->submit_form(with_fields => $fields); $mech->content_contains('Nearly done! Now check your email'); @@ -214,11 +210,7 @@ for my $tw_state ( 'refused', 'existing UID', 'no email' ) { $mech->content_contains('We need your email address, please give it below.'); # We don't have an email, so check that we can still submit it, # and the ID carries through the confirmation - if ($page eq 'update') { - $fields->{rznvy} = $tw_email; - } else { - $fields->{email} = $tw_email; - } + $fields->{username} = $tw_email; $fields->{name} = 'Ffion Tester'; $mech->submit_form(with_fields => $fields); $mech->content_contains('Nearly done! Now check your email'); diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 457eceade..14bd76c41 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -31,7 +31,7 @@ FixMyStreet::override_config { $mech->content_contains( 'sign in' ); $mech->submit_form( - with_fields => { email => $test_user, password_sign_in => $test_pass } + with_fields => { username => $test_user, password_sign_in => $test_pass } ); is $mech->status, '404', 'If not council user get 404'; @@ -42,7 +42,7 @@ FixMyStreet::override_config { $mech->log_out_ok; $mech->get_ok('/dashboard'); $mech->submit_form_ok( { - with_fields => { email => $test_user, password_sign_in => $test_pass } + with_fields => { username => $test_user, password_sign_in => $test_pass } } ); $mech->content_contains( 'Area 2651' ); diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index daa213e8c..91644e8ce 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -47,7 +47,7 @@ subtest "Body user, has permission to add report as another user" => sub { detail => 'Test report details.', category => 'Potholes', name => 'Another User', - email => 'another@example.net', + username => 'another@example.net', ); is $report->name, 'Another User', 'report name is given name'; is $report->user->name, 'Another User', 'user name matches'; @@ -66,7 +66,7 @@ subtest "Body user, has permission to add report as another (existing) user" => detail => 'Test report details.', category => 'Potholes', name => 'Existing Yooser', - email => 'existing@example.net', + username => 'existing@example.net', ); is $report->name, 'Existing Yooser', 'report name is given name'; is $report->user->name, 'Existing User', 'user name remains same'; @@ -108,7 +108,7 @@ subtest "Body user, has permission to add update as another user" => sub { form_as => 'another_user', update => 'Test Update', name => 'Another User', - rznvy => 'another2@example.net', + username => 'another2@example.net', ); is $update->name, 'Another User', 'update name is given name'; is $update->user->name, 'Another User', 'user name matches'; @@ -124,7 +124,7 @@ subtest "Body user, has permission to add update as another (existing) user" => form_as => 'another_user', update => 'Test Update', name => 'Existing Yooser', - rznvy => 'existing@example.net', + username => 'existing@example.net', ); is $update->name, 'Existing Yooser', 'update name is given name'; is $update->user->name, 'Existing User', 'user name remains same'; diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 4d73a5204..f0913fbd2 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -128,7 +128,7 @@ subtest "test a good report" => sub { my %fields = ( name => '', - rznvy => '', + username => '', update => '', add_alert => 1, # defaults to true fixed => undef diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 47113198e..e4a202db7 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -362,14 +362,12 @@ subtest "Submit a correct entry (with location) to cobrand" => sub { photo2 => '', photo3 => '', phone => '', - email => 'test-ll@example.com', + username => 'test-ll@example.com', }, "check imported fields are shown" or diag Dumper( $mech->visible_form_values ); use Data::Dumper; - my $user = - FixMyStreet::App->model('DB::User') - ->find( { email => 'test-ll@example.com' } ); + my $user = FixMyStreet::App->model('DB::User')->find( { email => 'test-ll@example.com' } ); ok $user, "Found a user"; my $report = $user->problems->first; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index ab6b5d78e..efe392eab 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -101,6 +101,7 @@ foreach my $test ( photo3 => '', name => '', may_show_name => '1', + username => '', email => '', phone => '', password_sign_in => '', @@ -127,6 +128,7 @@ foreach my $test ( photo3 => '', name => '', may_show_name => '1', + username => '', email => '', phone => '', category => 'Something bad', @@ -156,6 +158,7 @@ foreach my $test ( photo3 => '', name => '', may_show_name => '1', + username => '', email => '', phone => '', category => 'Street lighting', @@ -182,6 +185,7 @@ foreach my $test ( photo3 => '', name => '', may_show_name => undef, + username => '', email => '', phone => '', category => 'Street lighting', @@ -208,6 +212,7 @@ foreach my $test ( photo3 => '', name => 'Bob Jones', may_show_name => undef, + username => '', email => '', phone => '', category => 'Street lighting', @@ -233,6 +238,7 @@ foreach my $test ( photo3 => '', name => 'Bob Jones', may_show_name => '1', + username => '', email => '', phone => '', category => 'Street lighting', @@ -258,6 +264,7 @@ foreach my $test ( photo3 => '', name => 'Bob Jones', may_show_name => '1', + username => '', email => '', phone => '', category => 'Street lighting', @@ -283,6 +290,7 @@ foreach my $test ( photo3 => '', name => 'DUDE', may_show_name => '1', + username => '', email => '', phone => '', category => 'Street lighting', @@ -307,6 +315,7 @@ foreach my $test ( photo3 => '', name => 'anonymous', may_show_name => '1', + username => '', email => '', phone => '', category => 'Street lighting', @@ -331,14 +340,15 @@ foreach my $test ( photo3 => '', name => 'Joe Smith', may_show_name => '1', - email => 'not an email', + username => 'not an email', + email => '', phone => '', category => 'Street lighting', password_sign_in => '', password_register => '', remember_me => undef, }, - changes => { email => 'notanemail', }, + changes => { username => 'notanemail', email => 'notanemail' }, errors => [ 'Please enter a valid email', ], }, { @@ -352,6 +362,7 @@ foreach my $test ( photo3 => '', name => '', may_show_name => '1', + username => '', email => '', phone => '', category => 'Street lighting', @@ -379,7 +390,8 @@ foreach my $test ( photo3 => '', name => ' Bob Jones ', may_show_name => '1', - email => ' BOB @ExAmplE.COM ', + username => ' BOB @ExAmplE.COM ', + email => '', phone => '', category => 'Street lighting', password_sign_in => '', @@ -388,6 +400,7 @@ foreach my $test ( }, changes => { name => 'Bob Jones', + username => 'bob@example.com', email => 'bob@example.com', }, errors => [ 'Please enter a subject', 'Please enter some details', ], @@ -403,6 +416,7 @@ foreach my $test ( photo3 => '', name => 'Bob Jones', may_show_name => '1', + username => 'bob@example.com', email => 'bob@example.com', phone => '', category => 'Street lighting', @@ -426,6 +440,7 @@ foreach my $test ( photo3 => '', name => 'Bob Jones', may_show_name => '1', + username => 'bob@example.com', email => 'bob@example.com', phone => '', category => 'Street lighting', @@ -449,6 +464,7 @@ foreach my $test ( photo3 => '', name => 'Bob Jones', may_show_name => '1', + username => 'bob@example.com', email => 'bob@example.com', phone => '', category => 'Street lighting', @@ -560,7 +576,7 @@ foreach my $test ( photo1 => '', name => 'Joe Bloggs', may_show_name => '1', - email => 'test-1@example.com', + username => 'test-1@example.com', phone => '07903 123 456', category => 'Street lighting', password_register => $test->{password} ? 'secret' : '', @@ -674,7 +690,7 @@ subtest "test password errors for a user who is signing in as they report" => su title => 'Test Report', detail => 'Test report details.', photo1 => '', - email => 'test-2@example.com', + username => 'test-2@example.com', password_sign_in => 'secret1', category => 'Street lighting', } @@ -685,7 +701,7 @@ subtest "test password errors for a user who is signing in as they report" => su # check that we got the errors expected is_deeply $mech->page_errors, [ - "There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the \x{2018}sign in by email\x{2019} section of the form.", + "There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the \x{2018}No\x{2019} section of the form.", ], "check there were errors"; }; @@ -726,7 +742,7 @@ subtest "test report creation for a user who is signing in as they report" => su title => 'Test Report', detail => 'Test report details.', photo1 => '', - email => 'test-2@example.com', + username => 'test-2@example.com', password_sign_in => 'secret2', category => 'Street lighting', } @@ -947,7 +963,7 @@ subtest "test report creation for a category that is non public" => sub { title => 'Test Report', detail => 'Test report details.', photo1 => '', - email => 'test-2@example.com', + username => 'test-2@example.com', name => 'Joe Bloggs', category => 'Street lighting', } @@ -1135,7 +1151,7 @@ for my $test ( title => "Test Report", detail => 'Test report details.', photo1 => '', - email => 'firstlast@example.com', + username => 'firstlast@example.com', may_show_name => '1', phone => '07903 123 456', category => 'Trees', @@ -1167,9 +1183,7 @@ for my $test ( # 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 $user = FixMyStreet::App->model('DB::User')->find( { email => 'firstlast@example.com' } ); my $report = $user->problems->first; ok $report, "Found the report"; @@ -1284,7 +1298,7 @@ subtest "test Hart" => sub { $mech->submit_form_ok( { with_fields => { pc => 'GU51 4AE' } }, "submit location" ); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); my %optional_fields = $test->{confirm} ? () : - ( email => $test_email, phone => '07903 123 456' ); + ( username => $test_email, phone => '07903 123 456' ); # we do this as otherwise test::www::mechanize::catalyst # goes to the value set in ->host above irregardless and @@ -1424,7 +1438,7 @@ subtest "unresponsive body handling works" => sub { detail => 'Test report details.', photo1 => '', name => 'Joe Bloggs', - email => $test_email, + username => $test_email, may_show_name => '1', phone => '07903 123 456', category => 'Trees', @@ -1497,7 +1511,7 @@ subtest "unresponsive body handling works" => sub { detail => 'Test report details.', photo1 => '', name => 'Joe Bloggs', - email => $test_email, + username => $test_email, may_show_name => '1', phone => '07903 123 456', category => 'Trees', @@ -1618,7 +1632,7 @@ subtest "extra google analytics code displayed on email confirmation problem cre title => "Test Report", detail => 'Test report details.', photo1 => '', - email => 'firstlast@example.com', + username => 'firstlast@example.com', name => 'Test User', may_show_name => '1', phone => '07903 123 456', @@ -1639,9 +1653,7 @@ subtest "extra google analytics code displayed on email confirmation problem cre $mech->get_ok($url); # find the report - my $user = - FixMyStreet::App->model('DB::User') - ->find( { email => 'firstlast@example.com' } ); + my $user = FixMyStreet::App->model('DB::User')->find( { email => 'firstlast@example.com' } ); my $report = $user->problems->first; ok $report, "Found the report"; diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index 9a4a81182..0224e7e47 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -54,6 +54,7 @@ foreach my $test ( photo3 => '', name => '', may_show_name => '1', + username => '', email => '', phone => '', category => 'Street lighting', @@ -76,7 +77,7 @@ foreach my $test ( title => 'test', detail => 'test detail', name => 'Test User', - email => 'testopen311@example.com', + username => 'testopen311@example.com', category => 'Street lighting', number => 27, }, @@ -100,7 +101,7 @@ foreach my $test ( $mech->clear_emails_ok; # check that the user does not exist - my $test_email = $test->{submit_with}->{email}; + my $test_email = $test->{submit_with}->{username}; my $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); if ( $user ) { $user->problems->delete; diff --git a/t/app/controller/report_new_text.t b/t/app/controller/report_new_text.t new file mode 100644 index 000000000..94f350eba --- /dev/null +++ b/t/app/controller/report_new_text.t @@ -0,0 +1,371 @@ +use FixMyStreet::TestMech; +use t::Mock::Twilio; + +my $twilio = t::Mock::Twilio->new; +LWP::Protocol::PSGI->register($twilio->to_psgi_app, host => 'api.twilio.com'); + +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +my $mech = FixMyStreet::TestMech->new; + +my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council'); +$mech->create_contact_ok( body_id => $body->id, category => 'Street lighting', email => 'highways@example.com' ); +$mech->create_contact_ok( body_id => $body->id, category => 'Trees', email => 'trees@example.com' ); + +# test that phone number validation works okay +foreach my $test ( + { + msg => 'invalid number', + pc => 'EH1 1BB', + fields => { + username => '0121 4960000000', email => '', phone => '', + title => 'Title', detail => 'Detail', name => 'Bob Jones', + category => 'Street lighting', + may_show_name => '1', remember_me => undef, + photo1 => '', photo2 => '', photo3 => '', + password_register => '', password_sign_in => '', + }, + changes => { + username => '01214960000000', + phone => '01214960000000', + }, + errors => [ 'Please check your phone number is correct' ], + }, + { + msg => 'landline number', + pc => 'EH1 1BB', + fields => { + username => '0121 4960000', email => '', phone => '', + title => 'Title', detail => 'Detail', name => 'Bob Jones', + category => 'Street lighting', + may_show_name => '1', remember_me => undef, + photo1 => '', photo2 => '', photo3 => '', + password_register => '', password_sign_in => '', + }, + changes => { + username => '+44 121 496 0000', + phone => '+44 121 496 0000', + }, + errors => [ 'Please enter a mobile number', ], + }, + ) +{ + subtest "check form errors where $test->{msg}" => sub { + $mech->get_ok('/around'); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + SMS_AUTHENTICATION => 1, + PHONE_COUNTRY => 'GB', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "submit location" ); + is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + # submit the main form + $mech->submit_form_ok( { with_fields => $test->{fields} }, "submit form" ); + }; + + # check that we got the errors expected + is_deeply [ sort @{$mech->page_errors} ], [ sort @{$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"; + }; +} + +my $test_phone = '+61491570156'; +my $first_user; +foreach my $test ( + { + desc => 'does not have an account, does not set a password', + user => 0, password => 0, + }, + { + desc => 'does not have an account, sets a password', + user => 0, password => 1, + }, + { + desc => 'does have an account and is not signed in; does not sign in, does not set a password', + user => 1, password => 0, + }, + { + desc => 'does have an account and is not signed in; does not sign in, sets a password', + user => 1, password => 1, + }, +) { + subtest "test report creation for a user who " . $test->{desc} => sub { + $mech->log_out_ok; + + if ($test->{user}) { + my $user = FixMyStreet::App->model('DB::User')->find( { phone => $test_phone } ); + ok $user, "test user does exist"; + $user->problems->delete; + $user->name( 'Old Name' ); + $user->password( 'old_password' ); + $user->update; + } elsif (!$first_user) { + ok !FixMyStreet::App->model('DB::User')->find( { phone => $test_phone } ), + "test user does not exist"; + $first_user = 1; + } else { + # Not first pass, so will exist, but want no user to start, so delete it. + $mech->delete_user($test_phone); + } + + $mech->get_ok('/around'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + SMS_AUTHENTICATION => 1, + PHONE_COUNTRY => 'GB', + TWILIO_ACCOUNT_SID => 'AC123', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $mech->submit_form_ok( + { + button => 'submit_register', + with_fields => { + title => 'Test Report', detail => 'Test report details.', + photo1 => '', + name => 'Joe Bloggs', may_show_name => '1', + username => $test_phone, + category => 'Street lighting', + password_register => $test->{password} ? 'secret' : '', + } + }, + "submit good details" + ); + }; + + is_deeply $mech->page_errors, [], "check there were no errors"; + + my $user = FixMyStreet::App->model('DB::User')->find( { phone => $test_phone } ); + ok $user, "user found"; + if ($test->{user}) { + is $user->name, 'Old Name', 'name unchanged'; + ok $user->check_password('old_password'), 'password unchanged'; + } else { + is $user->name, undef, 'name not yet set'; + is $user->password, '', 'password not yet set for new user'; + } + + my $report = $user->problems->first; + ok $report, "Found the report"; + is $report->state, 'unconfirmed', "report not confirmed"; + is $report->bodies_str, $body->id; + + $mech->submit_form_ok({ with_fields => { code => '00000' } }); + $mech->content_contains('Try again'); + + my $code = $twilio->get_text_code; + $mech->submit_form_ok({ with_fields => { code => $code } }); + + $report->discard_changes; + is $report->state, 'confirmed', "Report is now confirmed"; + + $mech->get_ok( '/report/' . $report->id ); + + is $report->name, 'Joe Bloggs', 'name updated correctly'; + if ($test->{password}) { + ok $report->user->check_password('secret'), 'password updated correctly'; + } elsif ($test->{user}) { + ok $report->user->check_password('old_password'), 'password unchanged, as no new one given'; + } else { + is $report->user->password, '', 'password still not set, as none given'; + } + + # 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; + + # cleanup + $mech->delete_user($user) + if $test->{user} && $test->{password}; + }; +} + +# this test to make sure that we don't see spurious error messages about +# the name being blank when there is a sign in error +subtest "test password errors for a user who is signing in as they report" => sub { + $mech->log_out_ok; + + my $user = $mech->create_user_ok($test_phone); + ok $user->update( { + name => 'Joe Bloggs', + email => 'joe@example.net', + password => 'secret2', + } ), "set user details"; + + $mech->get_ok('/around'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + SMS_AUTHENTICATION => 1, + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $mech->submit_form_ok( + { + button => 'submit_sign_in', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo1 => '', + username => $test_phone, + password_sign_in => 'secret1', + category => 'Street lighting', + } + }, + "submit with wrong password" + ); + }; + + # check that we got the errors expected + is_deeply $mech->page_errors, [ + "There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the \x{2018}No\x{2019} section of the form.", + ], "check there were errors"; +}; + +subtest "test report creation for a user who is signing in as they report" => sub { + $mech->log_out_ok; + $mech->cookie_jar({}); + + my $user = $mech->create_user_ok($test_phone); + + $mech->get_ok('/around'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + SMS_AUTHENTICATION => 1, + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $mech->submit_form_ok( + { + button => 'submit_sign_in', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo1 => '', + username => $test_phone, + password_sign_in => 'secret2', + category => 'Street lighting', + } + }, + "submit good details" + ); + + # check that we got the message expected + $mech->content_contains( 'You have successfully signed in; please check and confirm your details are accurate:' ); + + # Now submit with a name + $mech->submit_form_ok( + { + with_fields => { + name => 'Joe Bloggs', + } + }, + "submit good details" + ); + }; + + my $report = $user->problems->first; + ok $report, "Found the report"; + $mech->content_contains('Thank you for reporting this issue'); + is $report->bodies_str, $body->id; + is $report->state, 'confirmed', "report is now confirmed"; + $mech->get_ok( '/report/' . $report->id ); + my $alert = FixMyStreet::App->model('DB::Alert')->find( { + user => $report->user, + alert_type => 'new_updates', + parameter => $report->id, + } ); + ok $alert, "created new alert"; + + $mech->logged_in_ok; +}; + +subtest "test report creation for a user who is logged in" => sub { + my $user = $mech->create_user_ok($test_phone); + $mech->get_ok('/around'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + is_deeply( + $mech->visible_form_values, + { + title => '', + detail => '', + may_show_name => '1', + name => 'Joe Bloggs', + email => 'joe@example.net', + photo1 => '', + photo2 => '', + photo3 => '', + category => '-- Pick a category --', + }, + "user's details prefilled" + ); + + $mech->submit_form_ok( + { + with_fields => { + title => "Test Report at café", + detail => 'Test report details.', + photo1 => '', + name => 'Joe Bloggs', + may_show_name => '1', + category => 'Street lighting', + } + }, + "submit good details" + ); + }; + + my $report = $user->problems->first; + ok $report, "Found the report"; + is $report->bodies_str, $body->id; + $mech->content_contains('Thank you for reporting this issue'); + is $report->state, 'confirmed', "report is now confirmed"; + $mech->get_ok( '/report/' . $report->id ); + my $alert = FixMyStreet::App->model('DB::Alert')->find( { + user => $report->user, + alert_type => 'new_updates', + parameter => $report->id, + } ); + ok $alert, "created new alert"; + + $mech->logged_in_ok; + + $mech->get_ok( + '/ajax?bbox=' . ($report->longitude - 0.01) . ',' . ($report->latitude - 0.01) + . ',' . ($report->longitude + 0.01) . ',' . ($report->latitude + 0.01) + ); + $mech->content_contains( "Test Report at caf\xc3\xa9" ); +}; + +done_testing(); diff --git a/t/app/controller/report_update_text.t b/t/app/controller/report_update_text.t new file mode 100644 index 000000000..45b4e78c2 --- /dev/null +++ b/t/app/controller/report_update_text.t @@ -0,0 +1,307 @@ +use FixMyStreet::TestMech; +use t::Mock::Twilio; + +my $twilio = t::Mock::Twilio->new; +LWP::Protocol::PSGI->register($twilio->to_psgi_app, host => 'api.twilio.com'); + +my $mech = FixMyStreet::TestMech->new; +my $user = $mech->create_user_ok('test@example.com', name => 'Test User'); +my $user2 = $mech->create_user_ok('commenter@example.com', name => 'Commenter'); +my $body = $mech->create_body_ok(2504, 'Westminster City Council'); + +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', + bodies_str => $body->id, + 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, + user_id => $user2->id, + name => 'Other User', + mark_fixed => 'false', + text => 'This is some update text', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, + anonymous => 'f', +}); + +my $comment_id = $comment->id; +ok $comment, "created test update - $comment_id"; + +for my $test ( + { + desc => 'Invalid phone', + fields => { + username => '01214960000000', + update => 'Update', + name => 'Name', + photo1 => '', + photo2 => '', + photo3 => '', + fixed => undef, + add_alert => 1, + may_show_name => undef, + remember_me => undef, + password_sign_in => '', + password_register => '', + }, + changes => {}, + field_errors => [ 'Please check your phone number is correct' ] + }, + { + desc => 'landline number', + fields => { + username => '01214960000', + update => 'Update', + name => 'Name', + photo1 => '', + photo2 => '', + photo3 => '', + fixed => undef, + add_alert => 1, + may_show_name => undef, + remember_me => undef, + password_register => '', + password_sign_in => '', + }, + changes => { + username => '+44 121 496 0000', + }, + field_errors => [ 'Please enter a mobile number' ] + }, + ) +{ + subtest "submit an update - $test->{desc}" => sub { + $mech->get_ok("/report/$report_id"); + + FixMyStreet::override_config { + SMS_AUTHENTICATION => 1, + PHONE_COUNTRY => 'GB', + }, sub { + $mech->submit_form_ok( { with_fields => $test->{fields} }, 'submit update' ); + }; + + is_deeply $mech->page_errors, $test->{field_errors}, 'field errors'; + + my $values = { + %{ $test->{fields} }, + %{ $test->{changes} }, + }; + + is_deeply $mech->visible_form_values('updateForm'), $values, 'form changes'; + }; +} + +my $test_phone = '+61491570156'; +for my $test ( + { + desc => 'submit an update, unregistered, logged out', + form_values => { + submit_update => 1, + username => $test_phone, + update => 'Update from an unregistered user', + add_alert => undef, + name => 'Unreg User', + may_show_name => undef, + }, + }, + { + desc => 'submit an update, unregistered, logged out, sign up for alerts', + form_values => { + submit_update => 1, + username => $test_phone, + update => 'Update from an unregistered user', + add_alert => 1, + name => 'Unreg User', + may_show_name => undef, + }, + }, + { + desc => 'submit an update, registered, logged out, confirming by text', + registered => 1, + form_values => { + submit_update => 1, + username => $test_phone, + update => 'Update from a registered user', + add_alert => undef, + name => 'Reg User', + password_register => 'new_secret', + }, + }, +) { + subtest $test->{desc} => sub { + $mech->log_out_ok(); + my $user; + if ($test->{registered}) { + $user = $mech->create_user_ok( $test_phone ); + $user->update( { name => 'Mr Reg', password => 'secret2' } ); + } + + $mech->get_ok("/report/$report_id"); + FixMyStreet::override_config { + SMS_AUTHENTICATION => 1, + TWILIO_ACCOUNT_SID => 'AC123', + }, sub { + $mech->submit_form_ok( { with_fields => $test->{form_values} }, 'submit update'); + }; + $mech->content_contains('Nearly done! Now check your phone'); + + if ($user) { + $user->discard_changes; + ok $user->check_password( 'secret2' ), 'password unchanged'; + is $user->name, 'Mr Reg', 'name unchanged'; + } + + my ($token) = $mech->content =~ /name="token" value="([^"]*)"/; + $token = FixMyStreet::App->model('DB::Token')->find({ + token => $token, + scope => 'comment' + }); + ok $token, 'Token found in database'; + + my $update_id = $token->data->{id}; + my $add_alerts = $token->data->{add_alert}; + my $update = FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } ); + + ok $update, 'found update in database'; + is $update->state, 'unconfirmed', 'update unconfirmed'; + my $details = $test->{form_values}; + is $update->user->phone, $details->{username}, 'update phone'; + is $update->user->phone_verified, 1; + is $update->text, $details->{update}, 'update text'; + is $add_alerts, $details->{add_alert} ? 1 : 0, 'do not sign up for alerts'; + + my $code = $twilio->get_text_code; + $mech->submit_form_ok( { with_fields => { code => '00000' } }); + $mech->content_contains('Try again'); + $mech->submit_form_ok( { with_fields => { code => $code } }); + + $mech->content_contains("/report/$report_id#update_$update_id"); + + if ($user) { + $user->discard_changes; + ok $user->check_password( 'new_secret' ), 'password changed'; + is $user->name, 'Reg User', 'name changed'; + } else { + $user = FixMyStreet::App->model( 'DB::User' )->find( { phone => $details->{username} } ); + ok $user, 'found user'; + } + + my $alert = FixMyStreet::App->model( 'DB::Alert' )->find( + { user => $user, alert_type => 'new_updates', confirmed => 1, } + ); + + ok $details->{add_alert} ? defined( $alert ) : !defined( $alert ), 'sign up for alerts'; + + $update->discard_changes; + is $update->state, 'confirmed', 'update confirmed'; + $mech->delete_user( $user ); + }; +} + +for my $test ( + { + desc => 'submit an update for a registered user, signing in with wrong password', + form_values => { + submit_update => 1, + username => $test_phone, + update => 'Update from a user', + add_alert => undef, + password_sign_in => 'secret', + }, + field_errors => [ + "There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the \x{2018}No\x{2019} section of the form.", + 'Please enter your name', # FIXME Not really necessary error + ], + }, + { + desc => 'submit an update for a registered user and sign in', + form_values => { + submit_update => 1, + username => $test_phone, + update => 'Update from a user', + add_alert => undef, + password_sign_in => 'secret2', + }, + message => 'You have successfully signed in; please check and confirm your details are accurate:', + } +) { + subtest $test->{desc} => sub { + # Set things up + my $user = $mech->create_user_ok( $test->{form_values}->{username} ); + my $pw = 'secret2'; + $user->update( { name => 'Mr Reg', password => $pw } ); + $report->comments->delete; + + $mech->log_out_ok(); + $mech->clear_emails_ok(); + $mech->get_ok("/report/$report_id"); + FixMyStreet::override_config { + SMS_AUTHENTICATION => 1, + }, sub { + $mech->submit_form_ok( + { + button => 'submit_sign_in', + with_fields => $test->{form_values} + }, + 'submit update' + ); + }; + + $mech->content_contains($test->{message}) if $test->{message}; + + is_deeply $mech->page_errors, $test->{field_errors}, 'check there were errors' + if $test->{field_errors}; + + SKIP: { + skip( "Incorrect password", 4 ) unless $test->{form_values}{password_sign_in} eq $pw; + + # Now submit with a name + $mech->submit_form_ok( + { with_fields => { name => 'Joe Bloggs', } }, + "submit good details" + ); + + $mech->content_contains('Thank you for updating this issue'); + + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, $test->{form_values}->{update}, 'update text'; + is $update->user->phone, $test->{form_values}->{username}, 'update user'; + is $update->state, 'confirmed', 'update confirmed'; + $mech->delete_user( $update->user ); + } + }; +} + +done_testing(); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 0526b2fd7..7cb547081 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -196,7 +196,7 @@ for my $test ( { desc => 'No email, no message', fields => { - rznvy => '', + username => '', update => '', name => '', photo1 => '', @@ -215,7 +215,7 @@ for my $test ( { desc => 'Invalid email, no message', fields => { - rznvy => 'test', + username => 'test', update => '', name => '', photo1 => '', @@ -234,7 +234,7 @@ for my $test ( { desc => 'email with spaces, no message', fields => { - rznvy => 'test @ example. com', + username => 'test @ example. com', update => '', name => '', photo1 => '', @@ -248,14 +248,14 @@ for my $test ( password_sign_in => '', }, changes => { - rznvy => 'test@example.com', + username => 'test@example.com', }, field_errors => [ 'Please enter a message', 'Please enter your name' ] }, { desc => 'email with uppercase, no message', fields => { - rznvy => 'test@EXAMPLE.COM', + username => 'test@EXAMPLE.COM', update => '', name => '', photo1 => '', @@ -269,7 +269,7 @@ for my $test ( password_sign_in => '', }, changes => { - rznvy => 'test@example.com', + username => 'test@example.com', }, field_errors => [ 'Please enter a message', 'Please enter your name' ] }, @@ -297,7 +297,7 @@ for my $test ( desc => 'submit an update for a non registered user', initial_values => { name => '', - rznvy => '', + username => '', may_show_name => 1, add_alert => 1, photo1 => '', @@ -311,7 +311,7 @@ for my $test ( }, form_values => { submit_update => 1, - rznvy => 'unregistered@example.com', + username => 'unregistered@example.com', update => 'Update from an unregistered user', add_alert => undef, name => 'Unreg User', @@ -323,7 +323,7 @@ for my $test ( desc => 'submit an update for a non registered user and sign up', initial_values => { name => '', - rznvy => '', + username => '', may_show_name => 1, add_alert => 1, photo1 => '', @@ -337,7 +337,7 @@ for my $test ( }, form_values => { submit_update => 1, - rznvy => 'unregistered@example.com', + username => 'unregistered@example.com', update => "update from an\r\n\r\nunregistered user", add_alert => 1, name => 'Unreg User', @@ -395,14 +395,14 @@ for my $test ( ok $update, 'found update in database'; is $update->state, 'unconfirmed', 'update unconfirmed'; - is $update->user->email, $details->{rznvy}, 'update email'; + is $update->user->email, $details->{username}, 'update email'; is $update->text, $details->{update}, 'update text'; is $add_alerts, $details->{add_alert} ? 1 : 0, 'do not sign up for alerts'; $mech->get_ok( $url ); $mech->content_contains("/report/$report_id#update_$update_id"); - my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } ); + my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{username} } ); ok $unreg_user, 'found user'; @@ -427,7 +427,7 @@ for my $test ( desc => 'overriding email confirmation allows report confirmation with no email sent', initial_values => { name => '', - rznvy => '', + username => '', may_show_name => 1, add_alert => 1, photo1 => '', @@ -441,7 +441,7 @@ for my $test ( }, form_values => { submit_update => 1, - rznvy => 'unregistered@example.com', + username => 'unregistered@example.com', update => "update no email confirm", add_alert => 1, name => 'Unreg User', @@ -493,10 +493,10 @@ for my $test ( ok $update, 'found update in database'; is $update->state, 'confirmed', 'update confirmed'; - is $update->user->email, $details->{rznvy}, 'update email'; + is $update->user->email, $details->{username}, 'update email'; is $update->text, $details->{update}, 'update text'; - my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } ); + my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{username} } ); ok $unreg_user, 'found user'; @@ -972,13 +972,13 @@ for my $test ( desc => 'submit an update for a registered user, signing in with wrong password', form_values => { submit_update => 1, - rznvy => 'registered@example.com', + username => 'registered@example.com', update => 'Update from a user', add_alert => undef, password_sign_in => 'secret', }, field_errors => [ - "There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the \x{2018}sign in by email\x{2019} section of the form.", + "There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the \x{2018}No\x{2019} section of the form.", 'Please enter your name', # FIXME Not really necessary error ], }, @@ -986,7 +986,7 @@ for my $test ( desc => 'submit an update for a registered user and sign in', form_values => { submit_update => 1, - rznvy => 'registered@example.com', + username => 'registered@example.com', update => 'Update from a user', add_alert => undef, password_sign_in => 'secret2', @@ -996,7 +996,7 @@ for my $test ( ) { subtest $test->{desc} => sub { # Set things up - my $user = $mech->create_user_ok( $test->{form_values}->{rznvy} ); + my $user = $mech->create_user_ok( $test->{form_values}->{username} ); my $pw = 'secret2'; $user->update( { name => 'Mr Reg', password => $pw } ); $report->comments->delete; @@ -1036,7 +1036,7 @@ for my $test ( my $update = $report->comments->first; ok $update, 'found update'; is $update->text, $test->{form_values}->{update}, 'update text'; - is $update->user->email, $test->{form_values}->{rznvy}, 'update user'; + is $update->user->email, $test->{form_values}->{username}, 'update user'; is $update->state, 'confirmed', 'update confirmed'; $mech->delete_user( $update->user ); } @@ -1053,7 +1053,7 @@ subtest 'submit an update for a registered user, creating update by email' => su $mech->submit_form_ok( { with_fields => { submit_update => 1, - rznvy => 'registered@example.com', + username => 'registered@example.com', update => 'Update from a user', add_alert => undef, name => 'New Name', @@ -1502,7 +1502,7 @@ for my $test ( fields => { submit_update => 1, name => 'Test User', - rznvy => 'test@example.com', + username => 'test@example.com', may_show_name => 1, update => 'update from owner', add_alert => undef, @@ -1524,7 +1524,7 @@ for my $test ( submit_update => 1, name => 'Test User', may_show_name => 1, - rznvy => 'test@example.com', + username => 'test@example.com', update => 'update from owner', add_alert => undef, fixed => 1, @@ -1589,7 +1589,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->{fields}->{rznvy}, 'update user'; + is $update->user->email, $test->{fields}->{username}, 'update user'; is $update->state, 'unconfirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; |