1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use HTTPTest;
7
8
9###############################################################################
10
11my $mainpage = <<EOF;
12<html>
13<head>
14  <title>Main Page</title>
15</head>
16<body>
17  <p>
18    Some text and a link to a <a href="http://localhost:{{port}}/firstlevel/secondpage.html">second page</a>.
19  </p>
20</body>
21</html>
22EOF
23
24my $secondpage = <<EOF;
25<html>
26<head>
27  <title>Second Page</title>
28</head>
29<body>
30  <p>
31    Some text and a link to a <a href="http://localhost:{{port}}/firstlevel/lowerlevel/thirdpage.html">third page</a>.
32  </p>
33</body>
34</html>
35EOF
36
37my $thirdpage = <<EOF;
38<html>
39<head>
40  <title>Third Page</title>
41</head>
42<body>
43  <p>
44    Some text and a link to a <a href="http://localhost:{{port}}/higherlevelpage.html">higher level page</a>.
45  </p>
46</body>
47</html>
48EOF
49
50my $fourthpage = <<EOF;
51<html>
52<head>
53  <title>Fourth Page</title>
54</head>
55<body>
56  <p>
57    This page is only linked by the higher level page. Therefore, it should not
58    be downloaded.
59  </p>
60</body>
61</html>
62EOF
63
64my $higherlevelpage = <<EOF;
65<html>
66<head>
67  <title>Higher Level Page</title>
68</head>
69<body>
70  <p>
71    This page is on a higher level in the URL path hierarchy. Therefore, it
72    should not be downloaded. Wget should not visit the following link to a
73    <a href="http://localhost:{{port}}/firstlevel/fourthpage.html">fourth page</a>.
74  </p>
75</body>
76</html>
77EOF
78
79# code, msg, headers, content
80my %urls = (
81    '/firstlevel/index.html' => {
82        code => "200",
83        msg => "Dontcare",
84        headers => {
85            "Content-type" => "text/html",
86        },
87        content => $mainpage,
88    },
89    '/firstlevel/secondpage.html' => {
90        code => "200",
91        msg => "Dontcare",
92        headers => {
93            "Content-type" => "text/html",
94        },
95        content => $secondpage,
96    },
97    '/firstlevel/lowerlevel/thirdpage.html' => {
98        code => "200",
99        msg => "Dontcare",
100        headers => {
101            "Content-type" => "text/html",
102        },
103        content => $thirdpage,
104    },
105    '/firstlevel/fourthpage.html' => {
106        code => "200",
107        msg => "Dontcare",
108        headers => {
109            "Content-type" => "text/plain",
110        },
111        content => $fourthpage,
112    },
113    '/higherlevelpage.html' => {
114        code => "200",
115        msg => "Dontcare",
116        headers => {
117            "Content-type" => "text/plain",
118        },
119        content => $higherlevelpage,
120    },
121);
122
123my $cmdline = $WgetTest::WGETPATH . " -np -nH -r http://localhost:{{port}}/firstlevel/";
124
125my $expected_error_code = 0;
126
127my %expected_downloaded_files = (
128    'firstlevel/index.html' => {
129        content => $mainpage,
130    },
131    'firstlevel/secondpage.html' => {
132        content => $secondpage,
133    },
134    'firstlevel/lowerlevel/thirdpage.html' => {
135        content => $thirdpage,
136    },
137);
138
139###############################################################################
140
141my $the_test = HTTPTest->new (name => "Test-np",
142                              input => \%urls,
143                              cmdline => $cmdline,
144                              errcode => $expected_error_code,
145                              output => \%expected_downloaded_files);
146exit $the_test->run();
147
148# vim: et ts=4 sw=4
149
150