CGI-Application-Plugin-Stream
view release on metacpan or search on metacpan
t/01-basic.t view on Meta::CPAN
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
#########################
use Test::More tests => 17;
BEGIN {
use_ok('CGI::Application::Plugin::Stream');
unshift @INC, 't/lib';
}
use strict;
use TieOut;
# Useless here, since the point is to test streaming directly.
#$ENV{CGI_APP_RETURN_ONLY} = 1;
#####
my $stdout = tie *STDOUT, 'TieOut' or die;
my ($content_sent, $test_name);
##############
# Testing with a file handle
my $app = StreamTest->new();
$app->with_fh();
$content_sent = $stdout->read;
$test_name = "with fh: Content-Disposition and filename headers are correct";
like($content_sent, qr/Content-Disposition: attachment; filename="FILE"/i,$test_name);
$test_name = 'with fh: Content-type detected correctly by File::MMagic';
like($content_sent, qr!Content-Type: text/plain!i, $test_name);
$test_name = 'with fh: correct Content-Length header found';
like($content_sent, qr/Content-Length: 29/i,$test_name);
# Testing with a file
$app = StreamTest->new();
$app->run();
$content_sent = $stdout->read;
$test_name = "Content-Disposition and filename headers are correct";
like($content_sent, qr/Content-Disposition: attachment; filename="test_file_to_stream.txt"/i,$test_name);
$test_name = 'Content-type detected correctly by File::MMagic';
like($content_sent, qr!Content-Type: text/plain!i, $test_name);
$test_name = 'correct Content-Length header found';
like($content_sent, qr/Content-Length: 29/i,$test_name);
###
$test_name = 'Setting a custom Content-Length';
$app = StreamTest->new();
$app->header_props(-Content_Length => 1 );
$app->with_fh();
$content_sent = $stdout->read;
like($content_sent, qr/Content-Length: 1/i,$test_name);
###
$test_name = 'Setting a custom -Content-Length';
$app = StreamTest->new();
$app->header_props(-Content_Length => 4 );
$app->with_fh();
$content_sent = $stdout->read;
like($content_sent, qr/Content-Length: 4/i,$test_name);
###
( run in 0.832 second using v1.01-cache-2.11-cpan-39bf76dae61 )