| 1 | use Test::More tests=>14; |
| 2 | |
| 3 | # Include the test hierarchy |
| 4 | use lib 't/lib'; |
| 5 | |
| 6 | BEGIN { use_ok('TestApp5'); }; |
| 7 | BEGIN { use_ok('CGI'); }; |
| 8 | |
| 9 | # Prevent output to STDOUT |
| 10 | $ENV{CGI_APP_RETURN_ONLY} = 1; |
| 11 | |
| 12 | ### |
| 13 | |
| 14 | my $test_name = "mode_param( path_info => 1 ) with PATH_INFO set."; |
| 15 | |
| 16 | $ENV{PATH_INFO} = '/basic_test1'; |
| 17 | my $app = TestApp5->new; |
| 18 | $app->mode_param( path_info => 1 ); |
| 19 | my $out; |
| 20 | eval { $out = $app->run() }; |
| 21 | is($@, '', 'avoided eval() death'); |
| 22 | like($out,qr/Hello World/, $test_name); |
| 23 | |
| 24 | ### |
| 25 | |
| 26 | $test_name = "mode_param( path_info => 1 ) without PATH_INFO set, but with rm."; |
| 27 | $ENV{PATH_INFO} = '' ; |
| 28 | my $q = CGI->new({ rm => 'basic_test1' }); |
| 29 | $app = TestApp5->new( QUERY => $q ); |
| 30 | $app->mode_param( path_info => 1 ); |
| 31 | eval { $out = $app->run() }; |
| 32 | is($@, '', 'avoided eval() death'); |
| 33 | like($out,qr/Hello World/, $test_name); |
| 34 | |
| 35 | #### |
| 36 | |
| 37 | $test_name = "mode_param( param => 'alt_rm' ) "; |
| 38 | $ENV{PATH_INFO} = ''; |
| 39 | $q = CGI->new({ alt_rm => 'basic_test1' }); |
| 40 | $app = TestApp5->new( QUERY => $q ); |
| 41 | $app->mode_param( param => 'alt_rm' ); |
| 42 | eval { $out = $app->run() }; |
| 43 | is($@, '', 'avoided eval() death'); |
| 44 | like($out,qr/Hello World/, $test_name); |
| 45 | |
| 46 | ### |
| 47 | |
| 48 | $test_name = "mode_param( path_info => 2 ), expecting success "; |
| 49 | $ENV{PATH_INFO} = '/my_ses_id/basic_test1/foo'; |
| 50 | $app = TestApp5->new( QUERY => $q ); |
| 51 | $app->mode_param( path_info => 2, ); |
| 52 | eval { $out = $app->run() }; |
| 53 | is($@, '', 'avoided eval() death'); |
| 54 | like($out,qr/Hello World/, $test_name); |
| 55 | |
| 56 | #### |
| 57 | |
| 58 | $test_name = "mode_param( path_info => 2, param => 'alt_rm' ), with path_info undef "; |
| 59 | $ENV{PATH_INFO} = '' ; |
| 60 | $app = TestApp5->new( QUERY => $q ); |
| 61 | $app->mode_param( path_info => 2, param => 'alt_rm' ); |
| 62 | eval { $out = $app->run() }; |
| 63 | is($@, '', 'avoided eval() death'); |
| 64 | like($out,qr/Hello World/, $test_name); |
| 65 | |
| 66 | #### |
| 67 | |
| 68 | $test_name = "mode_param( path_info => -2 ), expecting success "; |
| 69 | $ENV{PATH_INFO} = '/my_ses_id/basic_test1/foo'; |
| 70 | $app = TestApp5->new( QUERY => $q ); |
| 71 | $app->mode_param( path_info => -2, ); |
| 72 | eval { $out = $app->run() }; |
| 73 | is($@, '', 'avoided eval() death'); |
| 74 | like($out,qr/Hello World/, $test_name); |
| 75 | |
| 76 | #### |