| 1 | use Test::More tests => 10; |
| 2 | |
| 3 | # Need CGI.pm for tests |
| 4 | use CGI; |
| 5 | |
| 6 | # Include the test hierarchy |
| 7 | use lib 't/lib'; |
| 8 | |
| 9 | # Can we even use this module? |
| 10 | use_ok('TestApp6'); |
| 11 | |
| 12 | # Prevent output to STDOUT |
| 13 | $ENV{CGI_APP_RETURN_ONLY} = 1; |
| 14 | |
| 15 | # Test basic cgiapp_prerun() and get_current_runmode() |
| 16 | { |
| 17 | my $ta_obj = TestApp6->new(QUERY=>CGI->new("")); |
| 18 | my $output = $ta_obj->run(); |
| 19 | |
| 20 | # Did the run mode work? |
| 21 | like($output, qr/^Content\-Type\:\ text\/html/); |
| 22 | like($output, qr/Hello\ World\:\ prerun\_test\ OK/); |
| 23 | |
| 24 | # Did the cgiapp_prerun work? |
| 25 | is($ta_obj->param('PRERUN_RUNMODE'), 'prerun_test'); |
| 26 | |
| 27 | # get_current_runmode() working? |
| 28 | is($ta_obj->get_current_runmode(), 'prerun_test'); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | # Test basic prerun_mode() |
| 33 | { |
| 34 | local($^W) = undef; # Temporarily disable warnings |
| 35 | |
| 36 | my $ta_obj = TestApp6->new(QUERY=>CGI->new('rm=prerun_mode_test')); |
| 37 | my $output = $ta_obj->run(); |
| 38 | |
| 39 | # Did the run mode work? |
| 40 | like($output, qr/^Content\-Type\:\ text\/html/); |
| 41 | |
| 42 | # We will be in mode 'new_prerun_mode_test' if everything is working |
| 43 | like($output, qr/Hello\ World\:\ new\_prerun\_mode\_test\ OK/); |
| 44 | |
| 45 | # get_current_runmode() working? |
| 46 | is($ta_obj->get_current_runmode(), 'new_prerun_mode_test'); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | # Test fail-case for prerun_mode() |
| 51 | { |
| 52 | my $ta_obj = TestApp6->new(QUERY=>CGI->new('rm=illegal_prerun_mode')); |
| 53 | |
| 54 | eval { |
| 55 | my $output = $ta_obj->run(); |
| 56 | }; |
| 57 | |
| 58 | my $eval_error = $@; |
| 59 | |
| 60 | # Should result in an error |
| 61 | like($eval_error, qr/prerun\_mode\(\) can only be called within cgiapp\_prerun\(\)/); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | # Test fail-case for prerun_mode() called from setup() |
| 66 | { |
| 67 | $ENV{PRERUN_IN_SETUP} = 1; |
| 68 | |
| 69 | eval { |
| 70 | my $ta_obj = TestApp6->new(QUERY=>CGI->new("")); |
| 71 | }; |
| 72 | |
| 73 | my $eval_error = $@; |
| 74 | |
| 75 | # Should result in an error |
| 76 | like($eval_error, qr/prerun\_mode\(\) can only be called within cgiapp\_prerun\(\)/); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | ############### |
| 81 | #### EOF #### |
| 82 | ############### |