1Test::WWW::Mechanize::CUGsIeArppC(o3n)tributed Perl DocuTmeesntt:a:tWiWoWn::Mechanize::CGIApp(3)
2
3
4

NAME

6       Test::WWW::Mechanize::CGIApp - Test::WWW::Mechanize for
7       CGI::Application
8

SYNOPSIS

10         # We're in a t/*.t test script...
11         use Test::WWW::Mechanize::CGIApp;
12
13         my $mech = Test::WWW::Mechanize::CGIApp->new;
14
15         # test a class that uses CGI::Application calling semantics.
16         # (in this case we'll new up an instance of the app and call
17         # its ->run() method)
18         #
19         $mech->app("My::WebApp");
20         $mech->get_ok("?rm=my_run_mode&arg1=1&arg2=42");
21
22         # test a class that uses CGI::Application::Dispatch
23         # to locate the run_mode
24         # (in this case we'll just call the ->dispatch() class method).
25         #
26         my $dispatched_mech = Test::WWW::Mechanize::CGIApp->new;
27         $dispatched_mech->app("My::DispatchApp");
28         $mech->get_ok("/WebApp/my_run_mode?arg1=1&arg2=42");
29
30         # create an anonymous sub that this class will use to
31         # handle the request.
32         #
33         # this could be useful if you need to do something novel
34         # after creating an instance of your class (e.g. the
35         # fiddle_with_stuff() below) or maybe you have a unique
36         # way to get the app to run.
37         #
38         my $custom_mech = Test::WWW::Mechanize::CGIApp->new;
39         $custom_mech->app(
40            sub {
41              require "My::WebApp";
42              my $app = My::WebApp->new();
43              $app->fiddle_with_stuff();
44              $app->run();
45            });
46         $mech->get_ok("?rm=my_run_mode&arg1=1&arg2=42");
47
48         # at this point you can play with all kinds of cool
49         # Test::WWW::Mechanize testing methods.
50         is($mech->ct, "text/html");
51         $mech->title_is("Root", "On the root page");
52         $mech->content_contains("This is the root page", "Correct content");
53         $mech->follow_link_ok({text => 'Hello'}, "Click on Hello");
54         # ... and all other Test::WWW::Mechanize methods
55

DESCRIPTION

57       This package makes testing CGIApp based modules fast and easy.  It
58       takes advantage of Test::WWW::Mechanize to provide functions for common
59       web testing scenarios. For example:
60
61         $mech->get_ok( $page );
62         $mech->title_is( "Invoice Status",
63                          "Make sure we're on the invoice page" );
64         $mech->content_contains( "Andy Lester", "My name somewhere" );
65         $mech->content_like( qr/(cpan|perl)\.org/,
66                             "Link to perl.org or CPAN" );
67
68       For applications that inherit from CGI::Application it will handle
69       requests by creating a new instance of the class and calling its "run"
70       method.  For applications that use CGI::Application::Dispatch it will
71       call the "dispatch" class method.  If neither of these options are the
72       right thing, you can set a reference to a sub that will be used to
73       handle the request.
74
75       This module supports cookies automatically.
76
77       Check out Test::WWW::Mechanize for more information about all of the
78       cool things you can test!
79

CONSTRUCTOR

81   new
82       Behaves like, and calls, Test::WWW::Mechanize's "new" method.  It
83       optionally uses an "app" parameter (see below), any other parameters
84       get passed to Test::WWW::Mechanize's constructor. Note that you can
85       either pass the name of the CGI::Application into the constructor using
86       the "app" parameter or set it later using the "app" method.
87
88         use Test::WWW::Mechanize::CGIApp;
89         my $mech = Test::WWW::Mechanize::CGIApp->new;
90
91         # or
92
93         my $mech = Test::WWW::Mechanize::CGIApp->new(app => 'TestApp');
94

METHODS

96   $mech->app($app_handler)
97       This method provides a mechanism for informing
98       Test::WWW::Mechanize::CGIApp how it should go about executing your
99       run_mode.  If you set it to the name of a class, then it will load the
100       class and either create an instance and ->run() it (if it's
101       CGI::Application based), invoke the ->dispatch() method if it's
102       CGI::Application::Dispatch based, or call the supplied anonymous
103       subroutine and let it do all of the heavy lifting.
104

SEE ALSO

106       Related modules which may be of interest: Test::WWW::Mechanize,
107       WWW::Mechanize.
108
109       Various implementation tricks came from Test::WWW::Mechanize::Catalyst.
110

AUTHOR

112       George Hartzell, "<hartzell@alerce.com>"
113
114       based on Test::WWW::Mechanize::Catalyst by Leon Brocard,
115       "<acme@astray.com>".
116
118       Copyright (C) 2007, George Hartzell
119
120       This module is free software; you can redistribute it or modify it
121       under the same terms as Perl itself.
122
123
124
125perl v5.32.0                      2020-07-28   Test::WWW::Mechanize::CGIApp(3)
Impressum