View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
BBC (British Broadcasting Corporation) > Pinwheel > Pinwheel::TestHelper



Annotate this POD


New  2
Open  0
View/Report Bugs




    use Pinwheel::TestHelper;

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


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


($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 checks the "Location" header:

   # Absolute URL

   # Anything else containing a slash is prefixed by ""
   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($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':


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


Tests the number of found nodes against minimum.


Tests the number of found nodes against maximum.


(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.


TODO, document me.


TODO, document me.


TODO, document me.


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".


TODO, document me.

$template = get_template_name()

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


A&M Network Publishing <>

syntax highlighting: