X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=t%2F0_ex_00_base.t;fp=t%2F0_ex_00_base.t;h=5966a1588cc4ee845333c5a2c6ed483465bc2a5d;hp=387170a3051f4ef66e380e7186d927ce28d24d79;hb=b6e904ff7b346908d0662aae9a9c5f7d976dd85e;hpb=ba92ea5b36cbcd9c03016491dfb06dfc74baf409 diff --git a/t/0_ex_00_base.t b/t/0_ex_00_base.t index 387170a..5966a15 100644 --- a/t/0_ex_00_base.t +++ b/t/0_ex_00_base.t @@ -6,8 +6,15 @@ =cut +use vars qw($test_stdout @ISA); use strict; -use Test::More tests => 63; +use Test::More tests => 73; + +sub TIEHANDLE { bless [], __PACKAGE__ } +sub PRINT { + my $self = shift; + $test_stdout = join("", @_); +} use_ok('CGI::Ex'); @@ -46,6 +53,49 @@ ok($form->{'foo'} eq 'bar', "Could set form"); my $cookies = $cgix->cookies; ok($cookies->{'foo'} eq 'bar', "Could set form"); +### try print_content_type +if (eval { require Tie::Handle }) { + local @ISA = qw(Tie::Handle); + my $old_out = select STDOUT; + + foreach ([[] => "Content-Type: text/html\r\n\r\n"], + [['text/html'] => "Content-Type: text/html\r\n\r\n"], + [['text/html', ''] => "Content-Type: text/html\r\n\r\n"], + [['image/gif'] => "Content-Type: image/gif\r\n\r\n"], + [['text/html', 'utf-8'], => "Content-Type: text/html; charset=utf-8\r\n\r\n"], + [[$cgix, ] => "Content-Type: text/html\r\n\r\n"], + [[$cgix, 'text/html'] => "Content-Type: text/html\r\n\r\n"], + [[$cgix, 'text/html', ''] => "Content-Type: text/html\r\n\r\n"], + [[$cgix, 'image/gif'] => "Content-Type: image/gif\r\n\r\n"], + [[$cgix, 'text/html', 'utf-8'], => "Content-Type: text/html; charset=utf-8\r\n\r\n"], + ) { + local $ENV{'MOD_PERL'} = 0; + local $ENV{'CONTENT_TYPED'} = 0; + my ($args, $answer) = @$_; + + LOCAL: { + local *STDOUT; + tie *STDOUT, __PACKAGE__; + CGI::Ex::print_content_type(@$args); + }; + + select $old_out; + + (my $ans = $answer) =~ s/\s+$//; + if ($test_stdout eq $answer) { + ok(1, "(@$args) => $ans"); + } else { + ok(0, "(@$args) => $ans"); + print "#($test_stdout)\n"; + } + } + + select $old_out; +} else { + SKIP: { + skip("Can't test print_content_type", 10); + }; +} ### try out make_form my $str = $cgix->make_form($form);