use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestUtil; use Apache::TestRequest qw/GET_BODY/; plan tests => 7; my $head; # expected page header my $foot; # expected page footer my @body; # sections of page body # Read contents of header and footer open my $h, '<', 't/htdocs/head.html' or die "Could not open < t/htdocs/head.html: $!"; open my $f, '<', 't/htdocs/foot.html' or die "Could not open < t/htdocs/foot.html: $!"; $head = do { local $/; <$h> }; $foot = do { local $/; <$f> }; close $h; close $f; # Helper for replacing file contents sub set { my $file = shift; open my $fh, '>', $file or die "Could not open > $file: $!"; print $fh join('', @_); close $fh; } # Run tests set 't/htdocs/.htaccess', <Test\n", "This is a test page.\n"); set 't/htdocs/test.html', @body; ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot", '-less head'; @body = ("...\n", "This is a test page.\n"); set 't/htdocs/test.html', @body; ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot", '-ful head'; @body = ("\n", "This is a test page.\n", "\n"); set 't/htdocs/test.html', @body; ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot${body[2]}", '-wrapped document'; @body = ("\n", "This is a test page.\n"); set 't/htdocs/test.html', @body; ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot", ''; @body = ("\n\n", "This is a test page.\n"); set 't/htdocs/test.html', @body; ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot", ' with leading newline'; @body = ("This is a test page.\n"); set 't/htdocs/subdir/test.html', @body; ok GET_BODY('/subdir/test.html'), "$head${body[0]}", 'different injection in subdirectory'; set 't/htdocs/subdir/.htaccess', <