The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Contentment::Test - Helpers for testing Contentment

SYNOPSIS

  use Contentment::Test;

  my $response = GET('/foo.txt');
  my $content  = GET_BODY('/index.html');

DESCRIPTION

Provides a bunch of Apache::Test-like helpers without the Apache::Test dependencies.

This class probably has little or no use to end-users and is intended for developers wishing to test Contentment. This documentation is only written with that audience in mind.

METHODS

$parser = parse_html($text)

Parses the given text using HTML::TokeParser. This parser argument is used to evaluate the given text with some of the other test methods.

tag_with_attrs($parser, $tag, $expected_attrs, $put_back_when)

This is a helper used by has_tag_with_attrs() and no_tag_with_attrs(), so those are probably the methods you really want.

The $parser is the argument returned by the parse_html() method. The $tag is the name of the tag to look for. The $expected_attrs is a hash of expected attributes names and values. If the values are regular expressions, then they are used to match attribute values. The $put_back_when argument determines under which situation, if any, the token should be put back into the parser. This option can be set to one of the imported constants PUT_BACK_NEVER, PUT_BACK_ON_MISS, PUT_BACK_ON_FIND, or PUT_BACK_ALWAYS.

Returns a true value naming the found token on success or dies with a list of errors on a failure to match.

tag_with_content($parser, $tag, $expected_content, $put_back_when)

This is a helper used by has_tag_with_content() and no_tag_with_content(), so those are probably the methods you really want.

The $parser is the argument returned by the parse_html() method. The $tag is the name of the tag to look for. The $expected_content is a scalar or regular expression used to match an attribute's content. The $put_back_when argument determines under which situation, if any, the token should be put back into the parser. This option can be set to one of the imported constants PUT_BACK_NEVER, PUT_BACK_ON_MISS, PUT_BACK_ON_FIND, or PUT_BACK_ALWAYS.

Returns a true value naming the found token on success or dies with a list of errors on a failure to match.

failed_test_at()

This method is used internally by the tests to note the filename and line number of the failure.

has_tag_with_attrs($parser, $tag, $expected_attrs, $name)

This is a test that calls tag_with_attrs() and succeeds when a matching tag is found.

no_tag_with_attrs($parser, $tag, $expected_attrs, $name)

This is a test that calls tag_with_attrs() and succeeds when no matching tag is found.

has_tag_with_content($parser, $tag, $expected_content, $name)

This is a test that calls tag_with_content() and succeeds when a matching tag is found.

$ua = user_agent()

Return the singleton reference to the LWP::UserAgent used by the various HTTP methods of this module.

$uri = make_url($rel)

Returns an absolute URI object using the current host:port information and the given relative address, $rel.

$response = GET($url, %headers)

Returns an HTTP::Response object for the request at the given relative URL.

$response = POST($url, $form_ref, %headers)
$response = POST($url, %headers)

Returns an HTTP::Response object for the request at the given relative URL.

AUTHOR

Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>

LICENSE AND COPYRIGHT

Copyright 2005 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.