aboutsummaryrefslogtreecommitdiff
path: root/t/basic.t
blob: c82f6e2d609e95d02655b4274c3b05f19bf3c8e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;
use Apache::TestRequest qw/GET_BODY/;

plan tests => 5;

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 < head.html: $!";
open my $f, '<', 't/htdocs/foot.html' or die "Could not open < foot.html: $!";
$head = do { local $/; <$h> };
$foot = do { local $/; <$f> };
close $h; close $f;

# Set up helpers

sub set_conf {
	open my $c, '>', 't/htdocs/.htaccess' or die;
	print $c shift;
	close $c;
}
sub set_body {
	open my $b, '>', 't/htdocs/test.html' or die;
	print $b join('', @_);
	close $b;
}

# Run tests

set_conf <<CONF;
Inject head.html foot.html
CONF

@body = ("<title>Test</title>\n", "This is a test page.\n");
set_body @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot",
   '<head>-less head';

@body = ("<head>...</head>\n", "This is a test page.\n");
set_body @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot",
   '<head>-ful head';

@body = ("<html>\n", "This is a test page.\n", "</html>\n");
set_body @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot${body[2]}",
   '<html>-wrapped document';

@body = ("<!doctype html>\n", "This is a test page.\n");
set_body @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot",
   '<!doctype>';

@body = ("\n<!doctype html>\n", "This is a test page.\n");
set_body @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot",
   '<!doctype> with leading newline';

unlink 't/htdocs/.htaccess';
unlink 't/htdocs/test.html';