Merge branch 'ready/imgforpdf-and-more'
[ikiwiki.git] / t / inline.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More;
5 use IkiWiki;
6
7 my $blob;
8
9 ok(! system("rm -rf t/tmp"));
10 ok(! system("mkdir t/tmp"));
11
12 sub write_old_file {
13         my $name = shift;
14         my $content = shift;
15
16         writefile($name, "t/tmp/in", $content);
17         ok(utime(333333333, 333333333, "t/tmp/in/$name"));
18 }
19
20 write_old_file("protagonists.mdwn",
21         '[[!inline pages="protagonists/*" rootpage="protagonists/new"]]');
22 write_old_file("friends.mdwn",
23         '[[!inline pages="friends/*" postform=yes]]');
24 write_old_file("antagonists.mdwn",
25         '[[!inline pages="antagonists/*"]]');
26 write_old_file("enemies.mdwn",
27         '[[!inline pages="enemies/*" postform=no rootpage=enemies]]');
28 foreach my $page (qw(protagonists/shepard protagonists/link
29                 antagonists/saren antagonists/ganondorf
30                 friends/liara friends/midna
31                 enemies/benezia enemies/zant)) {
32         write_old_file("$page.mdwn", "this page is *$page*");
33 }
34
35 ok(! system("make -s ikiwiki.out"));
36
37 my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tmp/in t/tmp/out -verbose";
38
39 ok(! system($command));
40
41 ok(! system("$command -refresh"));
42
43 $blob = readfile("t/tmp/out/protagonists.html");
44 like($blob, qr{Add a new post}, 'rootpage=yes gives postform');
45 like($blob, qr{<input type="hidden" name="from" value="protagonists/new"},
46         'explicit rootpage is /protagonists/new');
47
48 $blob = readfile("t/tmp/out/friends.html");
49 like($blob, qr{Add a new post}, 'postform=yes forces postform');
50 like($blob, qr{<input type="hidden" name="from" value="friends"},
51         'implicit rootpage is /friends');
52
53 $blob = readfile("t/tmp/out/antagonists.html");
54 unlike($blob, qr{Add a new post}, 'default is no postform');
55
56 $blob = readfile("t/tmp/out/enemies.html");
57 unlike($blob, qr{Add a new post}, 'postform=no forces no postform');
58
59 done_testing;