Apache-Precompress

 view release on metacpan or  search on metacpan

t/01-gzip.t  view on Meta::CPAN

$log_obj->mock('error',
	sub
	{
		my $self = shift;
		my $error = shift;
	}
);

$request->set_always('log', $log_obj);

$request->mock('print',
	sub
	{
		my $self = shift;
		$data .= shift;
	}
);

$request->mock('content_encoding',
	sub
	{
		my $self = shift;
	}
);

$request->mock('header_in',
	sub
	{
		my $self = shift;
		my $name = shift;
		
		my $opts = {
			'Accept-Encoding'	=>	"gzip"
		};
		return	$opts->{$name};
	}
);

sub Apache::Constants::OK
{
	return 200;
}

sub Apache::Constants::SERVER_ERROR
{
	return 500;
}

sub Apache::Constants::NOT_FOUND
{
	return 404;
}

Apache::Precompress::handler($request);

# We now have compressed content. Check that it matches the
# file. Decompress here and check that it matches the 
# baseline.

open($fh, '>', $filename);
binmode($fh);
print $fh $data;
close($fh);

# Open the temp file
my $contents = "";
my $buffer;
my $gz = gzopen($filename, "rb") 
            or die(".gz: $gzerrno\n");
while($gz->gzread($buffer,4096) > 0)
{
	$contents .= $buffer;
}

# Compare the file to the data below
my $base = "";
open (FH,'<',$dir . '/baseline.html');
{
	local $/ = undef;
	$base = <FH>;
}
close FH;

ok($contents eq $data, "The compressed content matches the baseline");



( run in 2.072 seconds using v1.01-cache-2.11-cpan-d8267643d1d )