diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-03-25 16:48:02 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-03-25 16:48:02 +0000 |
commit | 3aa202368e73f8ea76eb85dd5cc6f529604f26ba (patch) | |
tree | 8b278f89441fc6cf803fca7afe49e4379ab2ff03 /perllib/FixMyStreet/TestMech.pm | |
parent | 47bf5d345fca67912d5f061813f22e599b2bb1d5 (diff) |
Move login/out methods into TestMech
Diffstat (limited to 'perllib/FixMyStreet/TestMech.pm')
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index 94e87f50b..b9ae90772 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -1,11 +1,15 @@ package FixMyStreet::TestMech; -use base qw(Test::WWW::Mechanize::Catalyst); +use base qw(Test::WWW::Mechanize::Catalyst Test::Builder::Module); use strict; use warnings; -use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; +BEGIN { + use FixMyStreet; + FixMyStreet->test_mode(1); +} +use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; use Test::More; use Web::Scraper; use Carp; @@ -20,8 +24,47 @@ This module subclasses L<Test::WWW::Mechanize::Catalyst> and adds some FixMyStreet specific smarts - such as the ability to scrape the resulting page for form error messages. +Note - using this module puts L<FixMyStreet::App> into test mode - so for +example emails will not get sent. + =head1 METHODS +=head2 check_not_logged_in, check_logged_in + + $bool = $mech->check_not_logged_in(); + $bool = $mech->check_logged_in(); + +Check that the current mech is not logged or logged in as a user. Produces test output. +Returns true test passed, false otherwise. + +=cut + +sub not_logged_in_ok { + my $mech = shift; + $mech->builder->ok( $mech->get('/auth/check_auth')->code == 401, + "not logged in" ); +} + +sub logged_in_ok { + my $mech = shift; + $mech->builder->ok( $mech->get('/auth/check_auth')->code == 200, + "logged in" ); +} + +=head2 log_out_ok + + $bool = $mech->log_out_ok( ); + +Log out the current user + +=cut + +sub log_out_ok { + my $mech = shift; + $mech->get_ok('/auth/logout'); + $mech->not_logged_in_ok; +} + =head2 form_errors my $arrayref = $mech->form_errors; |