koha-news.tmpl - Cancel button still referenced "opac-news" instead of "koha-news"
[koha.git] / t / Charset.t
blob9919daaf7be4683448039a5dad996b9185544aef
1 #!/usr/bin/perl
4 use strict;
5 use C4::Interface::CGI::Output; #
7 use vars qw( @tests );
8 use vars qw( $loaded );
10 BEGIN {
11 @tests = (
13 'Normal HTML without meta tag',
14 sub { guesscharset($_[0]) },
15 undef,
16 <<EOF
17 <title>control case</title>
18 EOF
19 ], [
20 'Result of guesscharset with normal HTML with irrelevant meta tag',
21 sub { guesscharset($_[0]) },
22 undef,
23 <<EOF
24 <meta http-equiv="Content-Language" content="zh-TW">
25 EOF
26 ], [
27 'Result of guesstype with normal HTML with irrelevant meta tag',
28 sub { guesstype($_[0]) },
29 'text/html',
30 <<EOF
31 <meta http-equiv="Content-Language" content="zh-TW">
32 EOF
33 ], [
34 'Result of guesscharset with normal HTML with relevant meta tag',
35 sub { guesscharset($_[0]) },
36 'big5',
37 <<EOF
38 <meta http-equiv="Content-Type" content="text/html; charset=big5">
39 EOF
40 ], [
41 'Result of guesstype with normal HTML with relevant meta tag',
42 sub { guesstype($_[0]) },
43 'text/html; charset=big5',
44 <<EOF
45 <meta http-equiv="Content-Type" content="text/html; charset=big5">
46 EOF
47 ], [
48 'Variant 1 using single quotes',
49 sub { guesstype($_[0]) },
50 'text/html; charset=iso-2022-jp',
51 <<EOF
52 <meta http-equiv="Content-Type" content='text/html; charset=iso-2022-jp'>
53 EOF
54 ], [
55 'Variant 2 using single quotes',
56 sub { guesstype($_[0]) },
57 'text/html; charset=utf-8',
58 <<EOF
59 <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
60 EOF
61 ], [
62 'Unquoted Content-Type',
63 sub { guesstype($_[0]) },
64 'text/html; charset=big5',
65 <<EOF
66 <meta http-equiv=Content-Type content="text/html; charset=big5">
67 EOF
68 ], [
69 'XML syntax',
70 sub { guesstype($_[0]) },
71 'text/html; charset=iso-8859-2',
72 <<EOF
73 <meta http-equiv=Content-Type content="text/html; charset=iso-8859-2" />
74 EOF
75 ], [
76 'Expected attributes in reverse order',
77 sub { guesstype($_[0]) },
78 'text/html; charset=big5',
79 <<EOF
80 <meta content="text/html; charset=big5" http-equiv="Content-Type">
81 EOF
82 ], [
83 'Extra whitespace at end',
84 sub { guesstype($_[0]) },
85 'text/html; charset=big5',
86 <<EOF
87 <meta http-equiv="Content-Type" content="text/html; charset=big5" >
88 EOF
89 ], [
90 'Multiple lines',
91 sub { guesstype($_[0]) },
92 'text/html; charset=big5',
93 <<EOF
94 <meta
95 http-equiv="Content-Type"
96 content="text/html; charset=big5"
98 EOF
99 ], [
100 # FIXME - THIS IS NOT A WELL-WRITTEN TEST CASE!!!
101 'With surrounding HTML',
102 sub { guesstype($_[0]) },
103 'text/html; charset=us-ascii',
104 <<EOF
105 <html>
106 <head>
107 <title>Test case with surrounding HTML</title>
108 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
109 </head>
110 <body>
111 The return value should not be contaiminated with any surround HTML
112 FIXME: Auth.pm returns in code that can contaminate the charset
113 FIXME: if we do not explicitly disallow whitespace in the charset
114 </body>
115 </html>
121 BEGIN { $| = 1; printf "1..%d\n", scalar(@tests); }
122 END {print "not ok 1\n" unless $loaded;}
123 $loaded = 1;
126 # Run all tests in sequence
127 for (my $i = 1; $i <= scalar @tests; $i += 1) {
128 my $test = $tests[$i - 1];
129 my($title, $f, $expected, $input) = @$test;
130 die "not ok $i (malformed test case)\n"
131 unless @$test == 4 && ref $f eq 'CODE';
133 my $output = &$f($input);
134 if (
135 (!defined $output && !defined $expected)
136 || (defined $output && defined $expected && $output eq $expected)
138 print "ok $i - $title\n";
139 } else {
140 print "not ok $i - $title: got ",
141 (defined $output? "\"$output\"": 'undef'),
142 ', expected ',
143 (defined $expected? "\"$expected\"": 'undef'),
144 "\n";