summaryrefslogtreecommitdiffstats
path: root/tests/Test-np.px
blob: 1253c5df232a9621334817e201bd5fa765020eb8 (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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env perl

use strict;
use warnings;

use HTTPTest;


###############################################################################

my $mainpage = <<EOF;
<html>
<head>
  <title>Main Page</title>
</head>
<body>
  <p>
    Some text and a link to a <a href="http://localhost:{{port}}/firstlevel/secondpage.html">second page</a>.
  </p>
</body>
</html>
EOF

my $secondpage = <<EOF;
<html>
<head>
  <title>Second Page</title>
</head>
<body>
  <p>
    Some text and a link to a <a href="http://localhost:{{port}}/firstlevel/lowerlevel/thirdpage.html">third page</a>.
  </p>
</body>
</html>
EOF

my $thirdpage = <<EOF;
<html>
<head>
  <title>Third Page</title>
</head>
<body>
  <p>
    Some text and a link to a <a href="http://localhost:{{port}}/higherlevelpage.html">higher level page</a>.
  </p>
</body>
</html>
EOF

my $fourthpage = <<EOF;
<html>
<head>
  <title>Fourth Page</title>
</head>
<body>
  <p>
    This page is only linked by the higher level page. Therefore, it should not
    be downloaded.
  </p>
</body>
</html>
EOF

my $higherlevelpage = <<EOF;
<html>
<head>
  <title>Higher Level Page</title>
</head>
<body>
  <p>
    This page is on a higher level in the URL path hierarchy. Therefore, it
    should not be downloaded. Wget should not visit the following link to a
    <a href="http://localhost:{{port}}/firstlevel/fourthpage.html">fourth page</a>.
  </p>
</body>
</html>
EOF

# code, msg, headers, content
my %urls = (
    '/firstlevel/index.html' => {
        code => "200",
        msg => "Dontcare",
        headers => {
            "Content-type" => "text/html",
        },
        content => $mainpage,
    },
    '/firstlevel/secondpage.html' => {
        code => "200",
        msg => "Dontcare",
        headers => {
            "Content-type" => "text/html",
        },
        content => $secondpage,
    },
    '/firstlevel/lowerlevel/thirdpage.html' => {
        code => "200",
        msg => "Dontcare",
        headers => {
            "Content-type" => "text/html",
        },
        content => $thirdpage,
    },
    '/firstlevel/fourthpage.html' => {
        code => "200",
        msg => "Dontcare",
        headers => {
            "Content-type" => "text/plain",
        },
        content => $fourthpage,
    },
    '/higherlevelpage.html' => {
        code => "200",
        msg => "Dontcare",
        headers => {
            "Content-type" => "text/plain",
        },
        content => $higherlevelpage,
    },
);

my $cmdline = $WgetTest::WGETPATH . " -np -nH -r http://localhost:{{port}}/firstlevel/";

my $expected_error_code = 0;

my %expected_downloaded_files = (
    'firstlevel/index.html' => {
        content => $mainpage,
    },
    'firstlevel/secondpage.html' => {
        content => $secondpage,
    },
    'firstlevel/lowerlevel/thirdpage.html' => {
        content => $thirdpage,
    },
);

###############################################################################

my $the_test = HTTPTest->new (input => \%urls,
                              cmdline => $cmdline,
                              errcode => $expected_error_code,
                              output => \%expected_downloaded_files);
exit $the_test->run();

# vim: et ts=4 sw=4