]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/meta.t
created
[git.ikiwiki.info.git] / t / meta.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Cwd qw(getcwd);
5 use Test::More;
6 use IkiWiki;
8 my $tmp = 't/tmp';
9 my $srcdir = "$tmp/in";
10 my $destdir = "$tmp/out";
12 my $installed = $ENV{INSTALLED_TESTS};
14 my @command;
15 if ($installed) {
16         @command = qw(ikiwiki);
17 }
18 else {
19         ok(! system("make -s ikiwiki.out"));
20         @command = ("perl", "-I".getcwd, qw(./ikiwiki.out
21                 --underlaydir=underlays/basewiki
22                 --set underlaydirbase=underlays
23                 --templatedir=templates));
24 }
26 push @command, qw(--plugin meta --disable-plugin htmlscrubber);
27 push @command, $srcdir, $destdir;
29 sub write_build_read_compare {
30         my ($pagename, $input, $expected_output) = @_;
31         ok(! system("rm -rf $tmp"), q{setup});
32         ok(! system("mkdir -p $srcdir"), q{setup});
33         writefile("$pagename.mdwn", $srcdir, $input);
34         ok(! system(@command), q{build});
35         like(readfile("$destdir/$pagename/index.html"), $expected_output);
36 }
38 write_build_read_compare(
39         'title',
40         q{[[!meta title="a page about bar"]]},
41         qr{<title>a page about bar</title>},
42 );
44 write_build_read_compare(
45         'description',
46         q{[[!meta description="a page about bar"]]},
47         qr{<meta name="description" content="a page about bar" />},
48 );
50 write_build_read_compare(
51         'guid',
52         q{[[!meta guid="12345"]]},
53         qr{<meta name="guid" content="12345" />},
54 );
56 write_build_read_compare(
57         'license',
58         q{[[!meta license="you get to keep both pieces"]]},
59         qr{<div class="pagelicense">},
60 );
62 write_build_read_compare(
63         'copyright',
64         q{[[!meta copyright="12345"]]},
65         qr{<div class="pagecopyright">},
66 );
68 write_build_read_compare(
69         'author',
70         q{[[!meta author="Noodly J. Appendage"]]},
71         qr{<meta name="author" content="Noodly J. Appendage" />},
72 );
74 write_build_read_compare(
75         'authorurl',
76         q{[[!meta authorurl="http://noodly.appendage"]]},
77         qr{<meta name="authorurl" content="http://noodly.appendage" />},
78 );
80 write_build_read_compare(
81         'permalink',
82         q{[[!meta permalink="http://noodly.appendage"]]},
83         qr{<link rel="bookmark" href="http://noodly.appendage" />},
84 );
86 write_build_read_compare(
87         'date',
88         q{[[!meta date="2000-01-23"]]},
89         qr{<meta name="date" content="2000-01-23" />},
90 );
92 write_build_read_compare(
93         'updated',
94         q{[[!meta updated="2018-03-21"]]},
95         qr{<meta name="updated" content="2018-03-21" />},
96 );
98 #write_build_read_compare(
99 #       'stylesheet',
100 #       q{[[!meta stylesheet="wonka.css"]]},
101 #       qr{<link href="wonka.css"},
102 #);
104 #write_build_read_compare(
105 #       'script',
106 #       q{[[!meta script="wonka.js"]]},
107 #       qr{<link href="wonka.js"},
108 #);
110 write_build_read_compare(
111         'openid',
112         q{[[!meta openid="wonka.openid.example"]]},
113         qr{<link href="wonka\.openid\.example" rel="openid\.delegate" />},
114 );
116 write_build_read_compare(
117         'foaf',
118         q{[[!meta foaf="wonka.foaf.example"]]},
119         qr{<link rel="meta" type="application/rdf\+xml" title="FOAF"},
120 );
122 write_build_read_compare(
123         'redir',
124         q{[[!meta redir="http://wonka.redir.example"]]},
125         qr{<meta http-equiv="refresh" content="0; URL=http://wonka\.redir\.example" />},
126 );
128 #write_build_read_compare(
129 #       'link',
130 #       q{[[!meta link="http://wonka.link.example"]]},
131 #       qr{<link href="http://wonka\.link\.example" />},
132 #);
134 write_build_read_compare(
135         'name',
136         q{[[!meta name="thingy" value1="hi" value2="hello"]]},
137         qr{<meta name="thingy" value[0-9]{1}=".+?" value[0-9]{1}=".+?" />},
138 );
140 write_build_read_compare(
141         'keywords',
142         q{[[!meta keywords="word1,word2,word3"]]},
143         qr{<meta name="keywords" content="word1,word2,word3" />},
144 );
146 write_build_read_compare(
147         'arbitrary',
148         q{[[!meta moo="mooooo"]]},
149         qr{<meta name="moo" content="mooooo" />},
150 );
152 #write_build_read_compare(
153 #       'twittercard1',
154 #       '[[!meta twitter:card="player"]]',
155 #       qr{<meta name="twitter:card" content="player" />},
156 #);
158 write_build_read_compare(
159         'twittercard2',
160         '[[!meta name="twitter:card" content="player"]]',
161         qr{<meta name="twitter:card" content="player" />},
162 );
164 write_build_read_compare(
165         'malformed_ISO-8601',
166         '[[!meta date="2018-02-281T12:00:00-0500"]]',
167         qr{Error: cannot parse date/time: 2018-02-281T12:00:00-0500},
168 );
170 write_build_read_compare(
171         'nonsense_month',
172         '[[!meta date="2018-14-22T14:22:45-0500"]]',
173         qr{Error: cannot parse date/time: 2018-14-22T14:22:45-0500},
174 );
176 done_testing();