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

NAME

Pinwheel::TestHelper

SYNOPSIS

    use Pinwheel::TestHelper;

    get('/radio4/schedule');
    is(get_template_name(), 'schedule/day.tmpl');

DESCRIPTION

This is a replacement for the Pinwheel::Controller module, it is invoked in tests and overrides the Pinwheel::Controller. See Pinwheel::Controller.

ROUTINES

($headers, $content) = get($path)

Invokes Pinwheel::Controller::dispatch to fetch the given page, and returns the headers and content.

Updates the $template, $headers, $content variables. Most of the rest of the routines in this module then examine those variables, so generally you'll want to always call get first.

$strings = content($selector, @selector_args)

Selects nodes from $content (so you probably want to call get first), and returns an array ref of their string_values.

See also is_content.

is_response($expect[, $name])

Tests the 'Status' header (from $headers, so you'll probably want to call get first) against $expect, and runs one test (via Test::More). The $name is passed in as the test name.

Allowed values for $expect:

  'success' (an alias for '200')
  'redirect' (tests that the status matches /^3\d\d$/)
  'missing' (an alias for '404')
  'error' (tests that the status matches /^5\d\d$/)
  otherwise: exact match (e.g. '406')
is_template($expect[, $name])

Tests that $template (as updated by get) equals $expect. Runs one Test::More test, using $name if supplied.

is_redirected_to

is_redirected_to checks the "Location" header:

   # Absolute URL
   is_redirected_to("http://....");

   # Anything else containing a slash is prefixed by "http://127.0.0.1"
   is_redirected_to("/some/url"); # anything else containing a 

   # Anything else calls url_for with only_path=0
   is_redirected_to('some_params', for => 'url_for')

is_redirected_to also checks that the "Status" header is some 3xx value. If you want more fine-grained checking than that, use is_response.

is_content
  is_content($selector, @selector_args, $text)
  # or
  is_content($selector, @selector_args, %opts)

Finds nodes matching $selector, @selector_args, then tests those nodes against %opts.

The first form is equivalent to the second where %opts = (text => $text).

Effectively there are two ways of using is_content: text matching, or node counting. Text matching does an implicit node count first, as it happens. The text is matched against the nodes' string_values.

  # Check that exactly one item is selected, and that its string value is "this text"
  is_content($selector, @selector_args, "this text")

  # Check that exactly two items are selected, and their string values (in order) are "One" and "Two"
  is_content($selector, @selector_args, ["One", "Two"])

  # Check that exactly two items are selected, and the first node's string
  # value matches the given regex, and the second node's string value is
  # "Exact".
  is_content($selector, @selector_args, [qr/first.pattern/, "Exact"])

  # Check that at least one item is selected
  is_content($selector, @selector_args)

  # Check that at least 2 items are selected
  is_content($selector, @selector_args, minimum => 2)

  # Check that at least 1 and at most 7 items are selected
  is_content($selector, @selector_args, minimum => 1, maximum => 7)

  # Check that exactly 5 items are selected
  is_content($selector, @selector_args, count => 5)

The text option can be <\@text> or $text. The latter case is equivalent to [$text]. In either case, a count option is implied, with its value as the number of items in @text.

If no %opts are given, minimum => 1 is assumed.

Tests are then run in the following order. The first failed test, if any, 'wins':

count

Tests the number of found nodes against count (exact match).

minimum

Tests the number of found nodes against minimum.

maximum

Tests the number of found nodes against maximum.

text

(If we get this far, we know that there are the same number of nodes as text items).

Each found node's string_value is tested against its corresponding text item. Each text item can be either a plain string or a Regexp.

is_generated

TODO, document me.

is_recognised

TODO, document me.

is_route

TODO, document me.

set_time(TIME)

Sets "now" to the time given by TIME (a Pinwheel::Model::Time object). Calls to Pinwheel::Model::Date::now and Pinwheel::Model::Time::now will use TIME instead of the system clock.

All that set_time does is store TIME in $Pinwheel::TestHelper::time_now. If you prefer, you can assign directly, perhaps using "local".

set_format

TODO, document me.

$template = get_template_name()

Returns the template name that is to be used to render the page in the framework.

AUTHOR

A&M Network Publishing <DLAMNetPub@bbc.co.uk>