CGI-ExtDirect
view release on metacpan or search on metacpan
t/04_headers.t view on Meta::CPAN
use strict;
use warnings;
# This test is CGI::ExtDirect specific, hence it is not unified with the rest
# of the framework
use Test::More tests => 54;
use lib 't/lib';
use RPC::ExtDirect::Test::Util::CGI qw/ raw_post form_post form_upload /;
use CGI::ExtDirect;
use constant WINDOWS => eval { $^O =~ /Win32|cygwin/ };
my $tests = eval do { local $/; <DATA>; } ## no critic
or die "Can't eval DATA: '$@'";
# Testing API
my $ct = CGI::Test->new(
-base_url => 'http://localhost/cgi-bin',
-cgi_dir => 't/cgi-bin',
);
BAIL_OUT "Can't create CGI::Test object" unless $ct;
my @run_only = @ARGV;
TEST:
for my $test ( @$tests ) {
my $name = $test->{name};
my $cgi_url = $test->{url};
my $method = $test->{method};
my $input_content = $test->{input_content};
my $http_status_exp = $test->{http_status};
my $expected_headers = $test->{http_headers};
next TEST if @run_only && !grep { lc $name eq lc $_ } @run_only;
my $url = $ct->base_uri . $cgi_url . (WINDOWS ? '.bat' : '');
my $page = $ct->$method($url, $input_content);
if ( ok $page, "$name not empty" ) {
my $http_status = $page->is_ok() ? 200 : $page->error_code();
is $http_status, $http_status_exp, "$name HTTP status";
my $http_headers = $ct->http_headers;
for my $want_hdr ( keys %$expected_headers ) {
ok exists $http_headers->{ $want_hdr },
"$name $want_hdr exists";
my $want = $expected_headers->{ $want_hdr };
my $have = $http_headers->{ $want_hdr };
my $desc = "$name $want_hdr value";
if ( 'Regexp' eq ref $want ) {
like $have, $want, $desc or diag explain $page;
}
else {
is $have, $want, $desc or diag explain $page;
}
};
$page->delete();
};
};
__DATA__
[
( run in 1.400 second using v1.01-cache-2.11-cpan-b16cb0d3907 )