1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!perl -T
# This test suite has been contributed by Michael Graham
# who also suggested the is_auto_runmode function
#########################
use Test::More tests => 13;
BEGIN { use_ok('CGI::Application::Plugin::AutoRunmode') };
#########################
# Test CGI::App class
{
package MyTestApp;
use base 'CGI::Application';
use CGI::Application::Plugin::AutoRunmode
qw [ cgiapp_prerun ];
sub mode1 : Runmode {
'mode1';
}
sub not_a_runmode{
'not a runmode';
}
sub start_mode1 : StartRunmode {
'start_mode1';
}
}
$ENV{CGI_APP_RETURN_ONLY} = 1;
$ENV{REQUEST_METHOD} = 'GET';
$ENV{QUERY_STRING} = 'rm=mode1';
use CGI;
my $q = new CGI;
{
my $testname = "call with no runmode";
my $app = new MyTestApp(QUERY=>$q);
my $t = $app->run;
ok( CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'mode1'), "[$testname] mode1");
ok(!CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'not_a_runmode'), "[$testname] not_a_runode");
ok(!CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'non_existing'), "[$testname] non_existing");
ok( CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'start_mode1'), "[$testname] start_mode1");
}
{
my $testname = "call with mode1";
$q->param(rm => 'mode1');
my $app = new MyTestApp(QUERY=>$q);
my $t = $app->run;
ok( CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'mode1'), "[$testname] mode1");
ok(!CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'not_a_runmode'), "[$testname] not_a_runode");
ok(!CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'non_existing'), "[$testname] non_existing");
ok( CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'start_mode1'), "[$testname] start_mode1");
}
{
my $testname = "start_mode1";
$q->param(rm => 'start_mode1');
my $app = new MyTestApp(QUERY=>$q);
my $t = $app->run;
ok( CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'mode1'), "[$testname] mode1");
ok(!CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'not_a_runmode'), "[$testname] not_a_runode");
ok(!CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'non_existing'), "[$testname] non_existing");
ok( CGI::Application::Plugin::AutoRunmode::is_auto_runmode($app, 'start_mode1'), "[$testname] start_mode1");
}
1;
|