CGI-Builder-CgiAppAPI
view release on metacpan or search on metacpan
t/01_cgiapp.t view on Meta::CPAN
chdir './t' ;
}
use lib 'test';
use TestApp ;
use TestApp2 ;
use TestApp3 ;
use TestApp4 ;
use TestApp5 ;
$ENV{CGI_APP_RETURN_ONLY} = 1;
{
my $ca_obj = CGI::Builder->new();
ok ((ref($ca_obj) && $ca_obj->isa('CGI::Builder')))
}
# Test 3: run() CGI::Application::Plus object. Expect header + output dump_html()
{
my $ca_obj = TestAppX->new();
$ca_obj->query(CGI->new(""));
my $t3_output = $ca_obj->run();
ok (($t3_output =~ /^Content\-Type\:\ text\/html/) && ($t3_output =~ /Query\ Environment\:/))
}
# Test 4: Instantiate CGI::Application::Plus sub-class.
{
my $ta_obj = TestApp->new(QUERY=>CGI->new(""));
ok ((ref($ta_obj) && $ta_obj->isa('CGI::Builder')))
}
# Test 5: run() CGI::Application::Plus sub-class. Expect HTTP header + 'Hello World: basic_test'.
{
my $ta_obj = TestApp->new(QUERY=>CGI->new(""));
my $t5_output = $ta_obj->run();
ok (($t5_output =~ /^Content\-Type\:\ text\/html/) && ($t5_output =~ /Hello\ World\:\ basic\_test/))
}
# Test 6: run() CGI::Application::Plus sub-class, in run-mode 'redirect_test'. Expect HTTP redirect header + 'Hello World: redirect_test'.
{
my $t6_ta_obj = TestApp->new();
$t6_ta_obj->query(CGI->new({'test_rm' => 'redirect_test'}));
my $t6_output = $t6_ta_obj->run();
ok (($t6_output =~ /^Status\:\ 302\ Moved/) && ($t6_output =~ /Hello\ World\:\ redirect\_test/))
}
# Test 7: run() CGI::Application::Plus sub-class, in run-mode 'cookie_test'. Expect HTTP header w/ cookie 'c_name' => 'c_value' + 'Hello World: cookie_test'.
{
my $t7_ta_obj = TestApp->new();
$t7_ta_obj->query(CGI->new({'test_rm' => 'cookie_test'}));
my $t7_output = $t7_ta_obj->run();
ok (($t7_output =~ /^Set-Cookie\:\ c\_name\=c\_value/) && ($t7_output =~ /Hello\ World\:\ cookie\_test/))
}
; SKIP:
{ skip("HTML::Template is not installed", 3 )
unless eval
{ require HTML::Template
} ;
# Test 8: run() CGI::Application::Plus sub-class, in run-mode 'tmpl_test'. Expect HTTP header + 'Hello World: tmpl_test'.
{
my $t8_ta_obj = TestApp->new(TMPL_PATH=>'test/templates/');
$t8_ta_obj->query(CGI->new({'test_rm' => 'tmpl_test'}));
my $t8_output = $t8_ta_obj->run();
ok (($t8_output =~ /^Content\-Type\:\ text\/html/) && ($t8_output =~ /\-\-\-\-\>Hello\ World\:\ tmpl\_test\<\-\-\-\-/))
}
# Test 9: run() CGI::Application::Plus sub-class, in run-mode 'tmpl_badparam_test'. Expect HTTP header + 'Hello World: tmpl_badparam_test'.
{
my $t9_ta_obj = TestApp->new(TMPL_PATH=>'test/templates/');
$t9_ta_obj->query(CGI->new({'test_rm' => 'tmpl_badparam_test'}));
my $t9_output = $t9_ta_obj->run();
ok (($t9_output =~ /^Content\-Type\:\ text\/html/) && ($t9_output =~ /\-\-\-\-\>Hello\ World\:\ tmpl\_badparam\_test\<\-\-\-\-/))
}
#
# Test 10: Instantiate and call run_mode 'eval_test'. Expect 'eval_test OK' in output.
{
my $t10_ta_obj = TestApp->new();
$t10_ta_obj->query(CGI->new({'test_rm' => 'eval_test'}));
my $t10_output = $t10_ta_obj->run();
ok (($t10_output =~ /^Content\-Type\:\ text\/html/) && ($t10_output =~ /Hello\ World\:\ eval\_test\ OK/))
}
}
# Test 11: Test to make sure cgiapp_init() was called in inherited class.
{
my $t11_ta_obj = TestApp2->new();
my $t11_cgiapp_init_state = $t11_ta_obj->param('CGIAPP_INIT');
ok (defined($t11_cgiapp_init_state) && ($t11_cgiapp_init_state eq 'true'))
}
# Test 12: Test to make sure mode_param() can contain subref
{
my $t12_ta_obj = TestApp3->new();
$t12_ta_obj->query(CGI->new({'go_to_mode' => 'subref_modeparam'}));
my $t12_output = $t12_ta_obj->run();
ok (($t12_output =~ /^Content\-Type\:\ text\/html/) && ($t12_output =~ /Hello\ World\:\ subref\_modeparam\ OK/))
}
# Test 13: Test to make sure that "false" run-modes are valid -- won't default to start_mode()
{
my $t13_ta_obj = TestApp3->new();
$t13_ta_obj->query(CGI->new({'go_to_mode' => '0'}));
my $t13_output = $t13_ta_obj->run();
ok (($t13_output =~ /^Content\-Type\:\ text\/html/) && ($t13_output =~ /Hello\ World\:\ blank\_mode\ OK/))
}
( run in 0.952 second using v1.01-cache-2.11-cpan-39bf76dae61 )