| 1 | |
| 2 | use strict; |
| 3 | use Test::More tests => 9; |
| 4 | |
| 5 | BEGIN{use_ok('CGI::Application');} |
| 6 | |
| 7 | $ENV{CGI_APP_RETURN_ONLY} = 1; |
| 8 | |
| 9 | { |
| 10 | my $app = CGI::Application->new; |
| 11 | |
| 12 | $app->header_type('none'); |
| 13 | |
| 14 | my $warn = ''; |
| 15 | local $SIG{__WARN__} = sub { |
| 16 | $warn = shift; |
| 17 | }; |
| 18 | $app->header_props(-type => 'banana/ripe'); |
| 19 | |
| 20 | like( |
| 21 | $warn, |
| 22 | qr/header_type set to 'none'/, |
| 23 | "warn if we set header while header type is none", |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | { |
| 28 | my $app = CGI::Application->new; |
| 29 | |
| 30 | eval { $app->header_props(123); }; |
| 31 | |
| 32 | like( |
| 33 | $@, |
| 34 | qr/odd number/i, |
| 35 | "croak on odd number of non-ref args to header_props", |
| 36 | ); |
| 37 | |
| 38 | eval { $app->header_add(123); }; |
| 39 | |
| 40 | like( |
| 41 | $@, |
| 42 | qr/odd number/i, |
| 43 | "croak on odd number of non-ref args to header_add", |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | { |
| 48 | my $app = CGI::Application->new; |
| 49 | |
| 50 | $app->header_props({ -type => 'banana/ripe' }); |
| 51 | $app->header_add({ -expires => '1d' }); |
| 52 | |
| 53 | like( |
| 54 | $app->run, |
| 55 | qr{Content-type: banana/ripe}i, |
| 56 | "headed added via hashref arg to header_props", |
| 57 | ); |
| 58 | |
| 59 | like( |
| 60 | $app->run, |
| 61 | qr{^Expires: }im, |
| 62 | "headed added via hashref arg to header_add", |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | { |
| 67 | my $app = CGI::Application->new; |
| 68 | |
| 69 | $app->header_props({ -type => 'banana/ripe' }); |
| 70 | |
| 71 | like( |
| 72 | $app->run, |
| 73 | qr{Content-type: banana/ripe}i, |
| 74 | "headed added via hashref arg to header_props", |
| 75 | ); |
| 76 | |
| 77 | $app->header_props(); |
| 78 | |
| 79 | like( |
| 80 | $app->run, |
| 81 | qr{Content-type: banana/ripe}i, |
| 82 | "Calling with no args is safe", |
| 83 | ); |
| 84 | |
| 85 | $app->header_props({}); |
| 86 | |
| 87 | unlike( |
| 88 | $app->run, |
| 89 | qr{Content-type: banana/ripe}i, |
| 90 | "Calling with an empty hashref clobbers existing data", |
| 91 | ); |
| 92 | |
| 93 | } |
| 94 |