Krang::Test::Web - Test::WWW::Mechanize subclass with Krang specific helper methods
This class is a very simple wrapper around Test::WWW::Mechanize that provides some simple constructs that are useful when writing Krang web tests.
use Krang::Test::Web;
my $mech = Krang::Test::Web->new();
...
$mech->contains_message('email_missing', pkg('User'));
$mech->lacks_message('email_missing', pkg('User'));
$mech->login(username => $name, password => $password);
new([ %args ])
Returns a new Krang::Test::Mech object with the following values values set in the Test::WWW::Mechanize constructor:
Any additional arguments will be passed on directly to the Test::WWW::Mechanize constructor.
get($url, [...])
This method extends the one from Test::WWW::Mechanize so that it will do the right thing with krang urls.
For instance, given a url of 'my_pref.pl' it will look at which ever instance is active and change that url to 'http://hostname.org/instance_name/my_pref.pl'
contains_message($key, $class [, %args ])
Prints an OK test message if the current page contains the matching message from
Krang::Message given the $key and the $class. Else print NOT OK.
If the message requires variable substitution, they can be provided
by passing in extra %args.
In the case where you don't know what the actual value of a message variable will be, you can pass a regular expression instead.
$mech->contains_message('reverted_story', 'Krang::CGI::Story',
version => qr/\d+/);
contains_messages()
Prints an OK test message if the current page contains any Krang messages.
lacks_message($key, $class [, %args ])
Prints an OK test message if the current page lacks the matching message from
data/messages.conf given the $key and the $class. Else print NOT OK
If the message requires variable substitution, they can be provided
by passing in extra %args.
lacks_messages()
Prints an OK test message if the current page lacks any Krang messages.
login($username, $password)
Attempts to login with the given the username and password.
If a username and password are not provided then we will use the KRANG_USERNAME
and KRANG_PASSWORD environment variables. If those don't exist then it
will use 'admin' and 'whale' respectively.
login_ok($username, $password, $description)
Test method that attempts to login with the given the username and password.
If a username and password are not provided then we will use the KRANG_USERNAME
and KRANG_PASSWORD environment variables. If those don't exist then it
will use 'admin' and 'whale' respectively.
login_not_ok($username, $password, $description)
Works the same as login_ok but the test has it's logic reversed.
change_hiddens()
WWW::Mechanize will not allow you to change hidden field values by default. If we need to test hidden values in our forms, we can use this function to set all hidden value read only attributes to 0, permitting the changing of its value in our mech tests.
script_url($script_name)
Returns the full URL to access the given script taking into account
the current KRANG_INSTANCE.
my $url = Krang::Test::Mech->script_url('login.pl');