File: basic.t

package info (click to toggle)
libapache2-mod-perl2 2.0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 12,016 kB
  • sloc: perl: 97,771; ansic: 14,493; makefile: 51; sh: 18
file content (120 lines) | stat: -rw-r--r-- 2,816 bytes parent folder | download | duplicates (7)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil qw(t_cmp t_catfile_apache t_client_log_error_is_expected);
use Apache::TestRequest;
use Apache::TestConfig ();

my %modules = (
    registry    => 'ModPerl::Registry',
    registry_bb => 'ModPerl::RegistryBB',
    perlrun     => 'ModPerl::PerlRun',
);

my @aliases = sort keys %modules;

plan tests => @aliases * 5 + 3, need 'mod_alias.c';

my $vars = Apache::Test::config()->{vars};
my $script_file = t_catfile_apache $vars->{serverroot}, 'cgi-bin', 'basic.pl';

# very basic compilation/response test
for my $alias (@aliases) {
    my $url = "/$alias/basic.pl";

    ok t_cmp(
        GET_BODY($url),
        "ok $script_file",
        "$modules{$alias} basic cgi test",
    );
}

# test non-executable bit (it should be executed w/o a problem)
for my $alias (@aliases) {
    if (Apache::TestConfig::WIN32) {
        skip "non-executable bit test for Win32", 0;
        next;
    }
    my $url = "/$alias/not_executable.pl";

    t_client_log_error_is_expected();
    ok t_cmp(
        HEAD($url)->code,
        200,
        "$modules{$alias} non-executable file",
    );
}

# test environment pre-set
for my $alias (@aliases) {
    my $url = "/$alias/env.pl?foo=bar";

    ok t_cmp(
        GET_BODY($url),
        "foo=bar",
        "$modules{$alias} mod_cgi-like environment pre-set",
    );
}

# require (actually chdir test)
for my $alias (@aliases) {
    my $url = "/$alias/require.pl";

    ok t_cmp(
        GET_BODY($url),
        "it works",
        "$modules{$alias} mod_cgi-like environment pre-set",
    );
}


# exit
for my $alias (@aliases) {
    my $url = "/$alias/exit.pl";

    ok t_cmp(
        GET_BODY_ASSERT($url),
        "before exit",
        "$modules{$alias} mod_cgi-like environment pre-set",
    );
}



# test method handlers
{
    my $url = "/registry_oo_conf/env.pl?foo=bar";
    ok t_cmp(
        GET_BODY($url),
        "foo=bar",
        "ModPerl::Registry->handler mod_cgi-like environment pre-set",
    );
}

# test mod_perl api usage
{
    my $url = "/registry/content_type.pl";
    ok t_cmp(
        GET_BODY($url),
        "ok",
        "\$r->content_type('text/plain')",
    );
}


# test that files with .html extension, which are configured to run as
# scripts get the headerparse stage working: the default mime handler
# sets $r->content_type for .html files, so we can't rely on
# content_type not being set in making the decision whether to parse
# headers or not
{
    my $url = "/registry/send_headers.html";
    my $res = GET $url;
    ok t_cmp(
        $res->content_type,
        "text/plain",
        "script's content-type",
    );
}