Pinwheel::TestHelper
use Pinwheel::TestHelper; get('/radio4/schedule'); 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.
Invokes Pinwheel::Controller::dispatch to fetch the given page, and returns the headers and content.
Pinwheel::Controller::dispatch
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.
$template, $headers, $content
get
Selects nodes from $content (so you probably want to call get first), and returns an array ref of their string_values.
$content
string_value
See also is_content.
is_content
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.
$headers
$expect
$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')
Tests that $template (as updated by get) equals $expect. Runs one Test::More test, using $name if supplied.
$template
is_redirected_to checks the "Location" header:
is_redirected_to
# 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_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.
$selector, @selector_args
%opts
The first form is equivalent to the second where %opts = (text => $text).
%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.
text
$text
[$text]
count
@text
If no %opts are given, minimum => 1 is assumed.
minimum => 1
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.
minimum
Tests the number of found nodes against maximum.
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.
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.
Pinwheel::Model::Date::now
Pinwheel::Model::Time::now
All that set_time does is store TIME in $Pinwheel::TestHelper::time_now. If you prefer, you can assign directly, perhaps using "local".
set_time
$Pinwheel::TestHelper::time_now
Returns the template name that is to be used to render the page in the framework.
A&M Network Publishing <DLAMNetPub@bbc.co.uk>
To install Pinwheel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pinwheel
CPAN shell
perl -MCPAN -e shell install Pinwheel
For more information on module installation, please visit the detailed CPAN module installation guide.