diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-03-28 16:34:18 +0100 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-03-28 16:34:18 +0100 |
commit | 6a201b1ed1aa4b6efb9f1f3801afc05ebfa7ef84 (patch) | |
tree | 7bbe60795e666a9b65b1f168dc8946cf1eae7187 /perllib/FixMyStreet/TestMech.pm | |
parent | f5b10293c317e5025f47e6cb332659723684d0f6 (diff) |
Test report creation for user who is logged in
also added methods to testmech
Diffstat (limited to 'perllib/FixMyStreet/TestMech.pm')
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index 6d0d3aeda..750a78305 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -14,6 +14,7 @@ use Test::More; use Web::Scraper; use Carp; use Email::Send::Test; +use Digest::SHA1 'sha1_hex'; =head1 NAME @@ -52,6 +53,40 @@ sub logged_in_ok { "logged in" ); } +=head2 log_in_ok + + $user = $mech->log_in_ok( $email_address ); + +Log in with the email given. If email does not match an account then create one. + +=cut + +sub log_in_ok { + my $mech = shift; + my $email = shift; + + my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => $email } ); + ok $user, "found/created user for $email"; + + # store the old password and then change it + my $old_password_sha1 = $user->password; + $user->update( { password => sha1_hex('secret') } ); + + # log in + $mech->get_ok('/auth'); + $mech->submit_form_ok( + { with_fields => { email => $email, password => 'secret' } }, + "login using form" ); + $mech->logged_in_ok; + + # restore the password (if there was one) + $user->update( { password => $old_password_sha1 } ) if $old_password_sha1; + + return $user; +} + =head2 log_out_ok $bool = $mech->log_out_ok( ); @@ -66,6 +101,18 @@ sub log_out_ok { $mech->not_logged_in_ok; } +sub delete_user { + my $mech = shift; + my $user = shift; + + $mech->log_out_ok; + ok( $_->delete, "delete problem " . $_->title ) # + for $user->problems; + ok $user->delete, "delete test user " . $user->email; + + return 1; +} + =head2 clear_emails_ok $bool = $mech->clear_emails_ok(); |