Why not adopt me?
NAME
Test::WWW::Mechanize::Maypole - Test::WWW::Mechanize for Maypole
SYNOPSIS
use Test::WWW::Mechanize::Maypole 'BeerDB';
$ENV{MAYPOLE_TEMPLATES} = 'path/to/templates';
my $mech = Test::WWW::Mechanize::Maypole->new;
#
# basic tests:
#
$mech->get_ok( "http://localhost/beerdb/" );
is( $mech->ct, "text/html" );
$mech->content_contains( 'This is the frontpage' );
#
# logging in and storing cookies:
#
$mech->get_ok("http://localhost/beerdb/customer");
$mech->content_contains( 'Login to BeerDB', 'got login page' );
# specify which form we're interested in
$mech->form_number(1); # the 1st form
# fill in credentials
$mech->field( 'username' => 'landlord' );
$mech->field( 'password' => 'handpump' );
# get a HTTP::Response back
my $response = $mech->click_button( name => 'submit' );
like( $response->content, qr/Shop for beer/ );
# check our cookies give access to other pages
$mech->get_ok( "http://localhost/beerdb/customer/edit" );
$mech->content_contains( 'Update your details', "got customer account edit page");
# ... see Test::WWW::Mechanize for many more test methods
DESCRIPTION
By inheriting from Test::WWW::Mechanize, this module provides two key benefits over using Maypole::CLI in test scripts. First, it inherits a plethora of methods for testing web content. Second, cookies are handled transparently, allowing you to test applications that use cookie-based sessions and authentication.
Testing web applications has always been a bit tricky, normally starting a web server for your application and making real HTTP requests to it. This module allows you to test Maypole web applications but does not start a server or issue HTTP requests. Instead, it passes the HTTP request parameters directly to Maypole. Thus you do not need to use a real hostname: "http://localhost/" will do.
This makes testing fast and easy. Test::WWW::Mechanize provides functions for common web testing scenarios. For example:
$mech->get_ok( $page );
$mech->title_is( "Invoice Status", "Make sure we're on the invoice page" );
$mech->content_contains( "David Baird", "My name somewhere" );
$mech->content_like( qr/(cpan|perl)\.org/, "Link to perl.org or CPAN" );
This module supports cookies automatically.
To use this module you must pass it the name of the application. See the SYNOPSIS above.
CONSTRUCTOR
new
Behaves like, and calls, WWW::Mechanize's new
method. Any parameters passed in get passed to WWW::Mechanize's constructor. Note that we need to pass the name of the Maypole application to the "use":
use Test::WWW::Mechanize::Maypole 'BeerDB';
my $mech = Test::WWW::Mechanize::Maypole->new;
ENVIRONMENT
Set $ENV{MAYPOLE_TEMPLATES}
to the path where the templates for the application can be found. Defaults to '.'
.
METHODS
Please see the documentation for Test::WWW::Mechanize.
Exported methods
These methods are exported into the application's namespace, and override methods that would otherwise be inherited from Maypole or the Maypole frontend.
You will not normally need to use these methods in your test scripts.
If you need to replace these methods with custom versions, let me know, and I'll make exporting more flexible.
- send_output
- parse_location
- parse_args
- get_template_root
AUTHOR
David Baird, <cpan@riverside-cms.co.uk>
BUGS
Please report any bugs or feature requests to bug-test-www-mechanize-maypole@rt.cpan.org
, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SEE ALSO
Test::WWW::Mechanize, WWW::Mechanize.
ACKNOWLEDGEMENTS
Pieced together from bits of from Test::WWW::Mechanize::Catalyst, by Leon Brocard, Maypole::CLI, by Simon Cozens, Catalyst::Request, by Sebastian Riedel and Marcus Ramberg, and Catalyst::Engine::HTTP::Base, by Sebastian Riedel and Christian Hansen.
COPYRIGHT & LICENSE
Copyright 2004 David Baird, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.