Debian Codegraph @

tests/Test-iri-forced-remote.px

raw
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use WgetFeature qw(iri);
7 use HTTPTest;
8
9 # cf. http://en.wikipedia.org/wiki/Latin1
10 # http://en.wikipedia.org/wiki/ISO-8859-15
11
12 ###############################################################################
13 # Force remote encoding to ISO-8859-1
14 #
15 # mime : charset found in Content-Type HTTP MIME header
16 # meta : charset found in Content-Type meta tag
17 #
18 # index.html mime + file = iso-8859-15
19 # p1_français.html meta + file = iso-8859-1, mime = utf-8
20 # p2_één.html mime + file = iso-8859-1
21 # p3_€€€.html meta + file = utf-8, mime = iso-8859-1
22 #
23
24 my $ccedilla_l15 = "\xE7";
25 my $ccedilla_u8 = "\xC3\xA7";
26 my $eacute_l1 = "\xE9";
27 my $eacute_u8 = "\xC3\xA9";
28 my $eurosign_l15 = "\xA4";
29 my $eurosign_u8 = "\xE2\x82\xAC";
30
31 my $pageindex = <<EOF;
32 <html>
33 <head>
34 <title>Main Page</title>
35 </head>
36 <body>
37 <p>
38 Link to page 1 <a href="http://localhost:{{port}}/p1_fran${ccedilla_l15}ais.html">La seule page en fran&ccedil;ais</a>.
39 Link to page 3 <a href="http://localhost:{{port}}/p3_${eurosign_l15}${eurosign_l15}${eurosign_l15}.html">My tailor is rich</a>.
40 </p>
41 </body>
42 </html>
43 EOF
44
45 my $pagefrancais = <<EOF;
46 <html>
47 <head>
48 <title>La seule page en français</title>
49 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
50 </head>
51 <body>
52 <p>
53 Link to page 2 <a href="http://localhost:{{port}}/p2_${eacute_l1}${eacute_l1}n.html">Die enkele nerderlangstalige pagina</a>.
54 </p>
55 </body>
56 </html>
57 EOF
58
59 my $pageeen = <<EOF;
60 <html>
61 <head>
62 <title>Die enkele nederlandstalige pagina</title>
63 </head>
64 <body>
65 <p>
66 &Eacute;&eacute;n is niet veel maar toch meer dan nul.<br/>
67 Nerdelands is een mooie taal... dit zin stuckje spreekt vanzelf, of niet :)
68 </p>
69 </body>
70 </html>
71 EOF
72
73 my $pageeuro = <<EOF;
74 <html>
75 <head>
76 <title>Euro page</title>
77 </head>
78 <body>
79 <p>
80 My tailor isn't rich anymore.
81 </p>
82 </body>
83 </html>
84 EOF
85
86 my $page404 = <<EOF;
87 <html>
88 <head>
89 <title>404</title>
90 </head>
91 <body>
92 <p>
93 Nop nop nop...
94 </p>
95 </body>
96 </html>
97 EOF
98
99 # code, msg, headers, content
100 my %urls = (
101 '/index.html' => {
102 code => "200",
103 msg => "Ok",
104 headers => {
105 "Content-type" => "text/html; charset=ISO-8859-15",
106 },
107 content => $pageindex,
108 },
109 '/robots.txt' => {
110 code => "200",
111 msg => "Ok",
112 headers => {
113 "Content-type" => "text/plain",
114 },
115 content => "",
116 },
117 '/p1_fran%C3%A7ais.html' => { # UTF-8 encoded
118 code => "200",
119 msg => "Ok",
120 headers => {
121 # wrong charset specified by meta tag in $pagefrancais, overridden by HTTP Content-Type
122 "Content-type" => "text/html; charset=iso-8859-1",
123 },
124 content => $pagefrancais,
125 },
126 '/p2_%C3%A9%C3%A9n.html' => { # UTF-8 encoded
127 code => "200",
128 msg => "Ok",
129 headers => {
130 "Content-type" => "text/html; charset=UTF-8",
131 },
132 content => $pageeen,
133 },
134 '/p3_%E2%82%AC%E2%82%AC%E2%82%AC.html' => { # UTF-8 encoded
135 code => "200",
136 msg => "Ok",
137 headers => {
138 "Content-type" => "text/plain",
139 },
140 content => $pageeuro,
141 },
142 '/p3_%C2%A4%C2%A4%C2%A4.html' => { # UTF-8 encoded
143 code => "200",
144 msg => "Ok",
145 headers => {
146 "Content-type" => "text/plain",
147 },
148 content => $pageeuro,
149 },
150 );
151
152 my $cmdline = $WgetTest::WGETPATH . " --iri -e robots=on --trust-server-names --local-encoding=utf-8 -nH -r http://localhost:{{port}}/";
153
154 my $expected_error_code = 0;
155
156 my %expected_downloaded_files = (
157 'index.html' => {
158 content => $pageindex,
159 },
160 'robots.txt' => {
161 content => "",
162 },
163 "p1_fran${ccedilla_u8}ais.html" => {
164 content => $pagefrancais,
165 },
166 "p2_${eacute_u8}${eacute_u8}n.html" => {
167 content => $pageeen,
168 },
169 "p3_${eurosign_u8}${eurosign_u8}${eurosign_u8}.html" => {
170 content => $pageeuro,
171 },
172 );
173
174 ###############################################################################
175
176 my $the_test = HTTPTest->new (input => \%urls,
177 cmdline => $cmdline,
178 errcode => $expected_error_code,
179 output => \%expected_downloaded_files);
180 exit $the_test->run();
181
182 # vim: et ts=4 sw=4