1Test::WWW::Mechanize::CUastearlyCsotn(t3r)ibuted Perl DoTceusmte:n:tWaWtWi:o:nMechanize::Catalyst(3)
2
3
4

NAME

6       Test::WWW::Mechanize::Catalyst - Test::WWW::Mechanize for Catalyst
7

SYNOPSIS

9         # We're in a t/*.t test script...
10         use Test::WWW::Mechanize::Catalyst;
11
12         # To test a Catalyst application named 'Catty':
13         my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'Catty');
14
15         $mech->get_ok("/"); # no hostname needed
16         is($mech->ct, "text/html");
17         $mech->title_is("Root", "On the root page");
18         $mech->content_contains("This is the root page", "Correct content");
19         $mech->follow_link_ok({text => 'Hello'}, "Click on Hello");
20         # ... and all other Test::WWW::Mechanize methods
21
22         # White label site testing
23         $mech->host("foo.com");
24         $mech->get_ok("/");
25

DESCRIPTION

27       Catalyst is an elegant MVC Web Application Framework.
28       Test::WWW::Mechanize is a subclass of WWW::Mechanize that incorporates
29       features for web application testing. The
30       Test::WWW::Mechanize::Catalyst module meshes the two to allow easy
31       testing of Catalyst applications without needing to start up a web
32       server.
33
34       Testing web applications has always been a bit tricky, normally
35       requiring starting a web server for your application and making real
36       HTTP requests to it. This module allows you to test Catalyst web
37       applications but does not require a server or issue HTTP requests.
38       Instead, it passes the HTTP request object directly to Catalyst. Thus
39       you do not need to use a real hostname: "http://localhost/" will do.
40       However, this is optional. The following two lines of code do exactly
41       the same thing:
42
43         $mech->get_ok('/action');
44         $mech->get_ok('http://localhost/action');
45
46       Links which do not begin with / or are not for localhost can be handled
47       as normal Web requests - this is handy if you have an external single
48       sign-on system. You must set allow_external to true for this:
49
50         $mech->allow_external(1);
51
52       You can also test a remote server by setting the environment variable
53       CATALYST_SERVER; for example:
54
55         $ CATALYST_SERVER=http://example.com/myapp prove -l t
56
57       will run the same tests on the application running at
58       http://example.com/myapp regardless of whether or not you specify
59       http:://localhost for Test::WWW::Mechanize::Catalyst.
60
61       Furthermore, if you set CATALYST_SERVER, the server will be regarded as
62       a remote server even if your links point to localhost. Thus, you can
63       use Test::WWW::Mechanize::Catalyst to test your live webserver running
64       on your local machine, if you need to test aspects of your deployment
65       environment (for example, configuration options in an http.conf file)
66       instead of just the Catalyst request handling.
67
68       This makes testing fast and easy. Test::WWW::Mechanize provides
69       functions for common web testing scenarios. For example:
70
71         $mech->get_ok( $page );
72         $mech->title_is( "Invoice Status", "Make sure we're on the invoice page" );
73         $mech->content_contains( "Andy Lester", "My name somewhere" );
74         $mech->content_like( qr/(cpan|perl)\.org/, "Link to perl.org or CPAN" );
75
76       This module supports cookies automatically.
77
78       To use this module you must pass it the name of the application. See
79       the SYNOPSIS above.
80
81       Note that Catalyst has a special development feature: the debug screen.
82       By default this module will treat responses which are the debug screen
83       as failures. If you actually want to test debug screens, please use:
84
85         $mech->{catalyst_debug} = 1;
86
87       An alternative to this module is Catalyst::Test.
88

CONSTRUCTOR

90   new
91       Behaves like, and calls, WWW::Mechanize's "new" method.  Any params
92       passed in get passed to WWW::Mechanize's constructor. Note that we need
93       to pass the name of the Catalyst application to the "use":
94
95         use Test::WWW::Mechanize::Catalyst 'Catty';
96         my $mech = Test::WWW::Mechanize::Catalyst->new;
97

METHODS

99   allow_external
100       Links which do not begin with / or are not for localhost can be handled
101       as normal Web requests - this is handy if you have an external single
102       sign-on system. You must set allow_external to true for this:
103
104         $mech->allow_external(1);
105
106       head2 catalyst_app
107
108       The name of the Catalyst app which we are testing against. Read-only.
109
110   host
111       The host value to set the "Host:" HTTP header to, if none is present
112       already in the request. If not set (default) then Catalyst::Test will
113       set this to localhost:80
114
115   clear_host
116       Unset the host attribute.
117
118   has_host
119       Do we have a value set for the host attribute
120
121   $mech->get_ok($url, [ \%LWP_options ,] $desc)
122       A wrapper around WWW::Mechanize's get(), with similar options, except
123       the second argument needs to be a hash reference, not a hash. Returns
124       true or false.
125
126   $mech->title_is( $str [, $desc ] )
127       Tells if the title of the page is the given string.
128
129           $mech->title_is( "Invoice Summary" );
130
131   $mech->title_like( $regex [, $desc ] )
132       Tells if the title of the page matches the given regex.
133
134           $mech->title_like( qr/Invoices for (.+)/
135
136   $mech->title_unlike( $regex [, $desc ] )
137       Tells if the title of the page does NOT match the given regex.
138
139           $mech->title_unlike( qr/Invoices for (.+)/
140
141   $mech->content_is( $str [, $desc ] )
142       Tells if the content of the page matches the given string.
143
144   $mech->content_contains( $str [, $desc ] )
145       Tells if the content of the page contains $str.
146
147   $mech->content_lacks( $str [, $desc ] )
148       Tells if the content of the page lacks $str.
149
150   $mech->content_like( $regex [, $desc ] )
151       Tells if the content of the page matches $regex.
152
153   $mech->content_unlike( $regex [, $desc ] )
154       Tells if the content of the page does NOT match $regex.
155
156   $mech->page_links_ok( [ $desc ] )
157       Follow all links on the current page and test for HTTP status 200
158
159           $mech->page_links_ok('Check all links');
160
161   $mech->page_links_content_like( $regex,[ $desc ] )
162       Follow all links on the current page and test their contents for
163       $regex.
164
165           $mech->page_links_content_like( qr/foo/,
166             'Check all links contain "foo"' );
167
168   $mech->page_links_content_unlike( $regex,[ $desc ] )
169       Follow all links on the current page and test their contents do not
170       contain the specified regex.
171
172           $mech->page_links_content_unlike(qr/Restricted/,
173             'Check all links do not contain Restricted');
174
175   $mech->links_ok( $links [, $desc ] )
176       Check the current page for specified links and test for HTTP status
177       200.  The links may be specified as a reference to an array containing
178       WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name.
179
180           my @links = $mech->find_all_links( url_regex => qr/cnn\.com$/ );
181           $mech->links_ok( \@links, 'Check all links for cnn.com' );
182
183           my @links = qw( index.html search.html about.html );
184           $mech->links_ok( \@links, 'Check main links' );
185
186           $mech->links_ok( 'index.html', 'Check link to index' );
187
188   $mech->link_status_is( $links, $status [, $desc ] )
189       Check the current page for specified links and test for HTTP status
190       passed.  The links may be specified as a reference to an array
191       containing WWW::Mechanize::Link objects, an array of URLs, or a scalar
192       URL name.
193
194           my @links = $mech->links();
195           $mech->link_status_is( \@links, 403,
196             'Check all links are restricted' );
197
198   $mech->link_status_isnt( $links, $status [, $desc ] )
199       Check the current page for specified links and test for HTTP status
200       passed.  The links may be specified as a reference to an array
201       containing WWW::Mechanize::Link objects, an array of URLs, or a scalar
202       URL name.
203
204           my @links = $mech->links();
205           $mech->link_status_isnt( \@links, 404,
206             'Check all links are not 404' );
207
208   $mech->link_content_like( $links, $regex [, $desc ] )
209       Check the current page for specified links and test the content of each
210       against $regex.  The links may be specified as a reference to an array
211       containing WWW::Mechanize::Link objects, an array of URLs, or a scalar
212       URL name.
213
214           my @links = $mech->links();
215           $mech->link_content_like( \@links, qr/Restricted/,
216               'Check all links are restricted' );
217
218   $mech->link_content_unlike( $links, $regex [, $desc ] )
219       Check the current page for specified links and test that the content of
220       each does not match $regex.  The links may be specified as a reference
221       to an array containing WWW::Mechanize::Link objects, an array of URLs,
222       or a scalar URL name.
223
224           my @links = $mech->links();
225           $mech->link_content_like( \@links, qr/Restricted/,
226             'Check all links are restricted' );
227
228   follow_link_ok( \%parms [, $comment] )
229       Makes a "follow_link()" call and executes tests on the results.  The
230       link must be found, and then followed successfully.  Otherwise, this
231       test fails.
232
233       %parms is a hashref containing the params to pass to "follow_link()".
234       Note that the params to "follow_link()" are a hash whereas the parms to
235       this function are a hashref.  You have to call this function like:
236
237           $agent->follow_link_ok( {n=>3}, "looking for 3rd link" );
238
239       As with other test functions, $comment is optional.  If it is supplied
240       then it will display when running the test harness in verbose mode.
241
242       Returns true value if the specified link was found and followed
243       successfully.  The HTTP::Response object returned by follow_link() is
244       not available.
245

CAVEATS

247   External Redirects and allow_external
248       If you use non-fully qualified urls in your test scripts (i.e. anything
249       without a host, such as "->get_ok( "/foo")" ) and your app redirects to
250       an external URL, expect to be bitten once you come back to your
251       application's urls (it will try to request them on the remote server).
252       This is due to a limitation in WWW::Mechanize.
253
254       One workaround for this is that if you are expecting to redirect to an
255       external site, clone the TWMC object and use the cloned object for the
256       external redirect.
257

SEE ALSO

259       Related modules which may be of interest: Catalyst,
260       Test::WWW::Mechanize, WWW::Mechanize.
261

AUTHOR

263       Ash Berlin "<ash@cpan.org>" (current maintainer)
264
265       Original Author: Leon Brocard, "<acme@astray.com>"
266
268       Copyright (C) 2005-9, Leon Brocard
269

LICENSE

271       This module is free software; you can redistribute it or modify it
272       under the same terms as Perl itself.
273
274
275
276perl v5.32.1                      2021-01-27 Test::WWW::Mechanize::Catalyst(3)
Impressum