aboutsummaryrefslogtreecommitdiff
path: root/t/meta.t
blob: 3b26ee7d2c48f11f0120d3b5935bac13d3c1811c (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/perl
use warnings;
use strict;
use Cwd qw(getcwd);
use Test::More;
use IkiWiki;

my $tmp = 't/tmp';
my $srcdir = "$tmp/in";
my $destdir = "$tmp/out";

my $installed = $ENV{INSTALLED_TESTS};

my @command;
if ($installed) {
	@command = qw(ikiwiki);
}
else {
	ok(! system("make -s ikiwiki.out"));
	@command = ("perl", "-I".getcwd, qw(./ikiwiki.out
		--underlaydir=underlays/basewiki
		--set underlaydirbase=underlays
		--templatedir=templates));
}

push @command, qw(--plugin meta --disable-plugin htmlscrubber);
push @command, $srcdir, $destdir;

sub write_build_read_compare {
	my ($pagename, $input, $expected_output) = @_;
	ok(! system("mkdir -p $srcdir"), q{setup});
	writefile("$pagename.mdwn", $srcdir, $input);
	ok(! system(@command), q{build});
	like(readfile("$destdir/$pagename/index.html"), $expected_output);
	ok(! system("rm -rf $tmp"), q{teardown});
}

write_build_read_compare(
	'title',
	q{[[!meta title="a page about bar"]]},
	qr{<title>a page about bar</title>},
);

write_build_read_compare(
	'description',
	q{[[!meta description="a page about bar"]]},
	qr{<meta name="description" content="a page about bar" />},
);

write_build_read_compare(
	'guid',
	q{[[!meta guid="12345"]]},
	qr{<meta name="guid" content="12345" />},
);

write_build_read_compare(
	'license',
	q{[[!meta license="you get to keep both pieces"]]},
	qr{<div class="pagelicense">},
);

write_build_read_compare(
	'copyright',
	q{[[!meta copyright="12345"]]},
	qr{<div class="pagecopyright">},
);

write_build_read_compare(
	'enclosure',
	q{[[!meta enclosure="ikiwiki/login-selector/wordpress.png"]]},
	qr{<meta name="enclosure" content="/ikiwiki/login-selector/wordpress.png" />},
);

write_build_read_compare(
	'author',
	q{[[!meta author="Noodly J. Appendage"]]},
	qr{<meta name="author" content="Noodly J. Appendage" />},
);

write_build_read_compare(
	'authorurl',
	q{[[!meta authorurl="http://noodly.appendage"]]},
	qr{<meta name="authorurl" content="http://noodly.appendage" />},
);

write_build_read_compare(
	'permalink',
	q{[[!meta permalink="http://noodly.appendage"]]},
	qr{<link rel="bookmark" href="http://noodly.appendage" />},
);

write_build_read_compare(
	'date',
	q{[[!meta date="12345"]]},
	qr{<meta name="date" content="12345" />},
);

write_build_read_compare(
	'updated',
	q{[[!meta updated="12345"]]},
	qr{<meta name="updated" content="12345" />},
);

#write_build_read_compare(
#	'stylesheet',
#	q{[[!meta stylesheet="wonka.css"]]},
#	qr{<link href="wonka.css"},
#);

#write_build_read_compare(
#	'script',
#	q{[[!meta script="wonka.js"]]},
#	qr{<link href="wonka.js"},
#);

write_build_read_compare(
	'openid',
	q{[[!meta openid="wonka.openid.example"]]},
	qr{<link href="wonka\.openid\.example" rel="openid\.delegate" />},
);

write_build_read_compare(
	'foaf',
	q{[[!meta foaf="wonka.foaf.example"]]},
	qr{<link rel="meta" type="application/rdf\+xml" title="FOAF"},
);

write_build_read_compare(
	'redir',
	q{[[!meta redir="http://wonka.redir.example"]]},
	qr{<meta http-equiv="refresh" content="0; URL=http://wonka\.redir\.example" />},
);

#write_build_read_compare(
#	'link',
#	q{[[!meta link="http://wonka.link.example"]]},
#	qr{<link href="http://wonka\.link\.example" />},
#);

write_build_read_compare(
	'name',
	q{[[!meta name="thingy" value1="hi" value2="hello"]]},
	qr{<meta name="thingy" value[0-9]{1}=".+?" value[0-9]{1}=".+?" />},
);

write_build_read_compare(
	'keywords',
	q{[[!meta keywords="word1,word2,word3"]]},
	qr{<meta name="keywords" content="word1,word2,word3" />},
);

write_build_read_compare(
	'arbitrary',
	q{[[!meta moo="mooooo"]]},
	qr{<meta name="moo" content="mooooo" />},
);

#write_build_read_compare(
#	'twittercard1',
#	'[[!meta twitter:card="player"]]',
#	qr{<meta name="twitter:card" content="player" />},
#);

write_build_read_compare(
	'twittercard2',
	'[[!meta name="twitter:card" content="player"]]',
	qr{<meta name="twitter:card" content="player" />},
);

done_testing();