]> sipb.mit.edu Git - ikiwiki.git/blob - t/index.t
Merge commit 'upstream/master' into prv/po
[ikiwiki.git] / t / index.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use IkiWiki;
5
6 package IkiWiki; # use internal variables
7 use Test::More tests => 27;
8
9 $config{wikistatedir}="/tmp/ikiwiki-test.$$";
10 system "rm -rf $config{wikistatedir}";
11
12 ok(! loadindex(), "loading nonexistent index file");
13
14 # Load standard plugins.
15 ok(loadplugin("meta"), "meta plugin loaded");
16 ok(loadplugin("mdwn"), "mdwn plugin loaded");
17
18 # Set up a default state.
19 $pagesources{"Foo"}="Foo.mdwn";
20 $pagesources{"bar"}="bar.mdwn";
21 $pagesources{"bar.png"}="bar.png";
22 my $now=time();
23 $pagemtime{"Foo"}=$now;
24 $pagemtime{"bar"}=$now-1000;
25 $pagemtime{"bar.png"}=$now;
26 $pagectime{"Foo"}=$now;
27 $pagectime{"bar"}=$now-100000;
28 $pagectime{"bar.png"}=$now-100000;
29 $renderedfiles{"Foo"}=["Foo.html"];
30 $renderedfiles{"bar"}=["bar.html", "bar.rss", "sparkline-foo.gif"];
31 $renderedfiles{"bar.png"}=["bar.png"];
32 $links{"Foo"}=["bar.png"];
33 $links{"bar"}=["Foo", "new-page"];
34 $links{"bar.png"}=[];
35 $depends{"Foo"}="";
36 $depends{"bar"}="foo*";
37 $depends{"bar.png"}="";
38 $pagestate{"bar"}{meta}{title}="a page about bar";
39 $pagestate{"bar"}{meta}{moo}="mooooo";
40 # only loaded plugins save state, so this should not be saved out
41 $pagestate{"bar"}{nosuchplugin}{moo}="mooooo";
42
43 ok(saveindex(), "save index");
44 ok(-s "$config{wikistatedir}/indexdb", "index file created");
45
46 # Clear state.
47 %oldrenderedfiles=%pagectime=();
48 %pagesources=%pagemtime=%oldlinks=%links=%depends=
49 %destsources=%renderedfiles=%pagecase=%pagestate=();
50
51 ok(loadindex(), "load index");
52 is_deeply(\%pagesources, {
53         Foo => "Foo.mdwn",
54         bar => "bar.mdwn",
55         "bar.png" => "bar.png",
56 }, "%pagesources loaded correctly");
57 is_deeply(\%pagemtime, {
58         Foo => $now,
59         bar => $now-1000,
60         "bar.png" => $now,
61 }, "%pagemtime loaded correctly");
62 is_deeply(\%pagectime, {
63         Foo => $now,
64         bar => $now-100000,
65         "bar.png" => $now-100000,
66 }, "%pagemtime loaded correctly");
67 is_deeply(\%renderedfiles, {
68         Foo => ["Foo.html"],
69         bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
70         "bar.png" => ["bar.png"],
71 }, "%renderedfiles loaded correctly");
72 is_deeply(\%oldrenderedfiles, {
73         Foo => ["Foo.html"],
74         bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
75         "bar.png" => ["bar.png"],
76 }, "%oldrenderedfiles loaded correctly");
77 is_deeply(\%links, {
78         Foo => ["bar.png"],
79         bar => ["Foo", "new-page"],
80         "bar.png" => [],
81 }, "%links loaded correctly");
82 is_deeply(\%depends, {
83         Foo => "",
84         bar => "foo*",
85         "bar.png" => "",
86 }, "%depends loaded correctly");
87 is_deeply(\%pagestate, {
88         bar => {
89                 meta => {
90                         title => "a page about bar",
91                         moo => "mooooo",
92                 },
93         },
94 }, "%pagestate loaded correctly");
95 is_deeply(\%pagecase, {
96         foo => "Foo",
97         bar => "bar",
98         "bar.png" => "bar.png"
99 }, "%pagecase generated correctly");
100 is_deeply(\%destsources, {
101         "Foo.html" => "Foo",
102         "bar.html" => "bar",
103         "bar.rss" => "bar",
104         "sparkline-foo.gif" => "bar",
105         "bar.png" => "bar.png",
106 }, "%destsources generated correctly");
107
108 # Clear state.
109 %oldrenderedfiles=%pagectime=();
110 %pagesources=%pagemtime=%oldlinks=%links=%depends=
111 %destsources=%renderedfiles=%pagecase=%pagestate=();
112
113 # When state is loaded for a wiki rebuild, only ctime and oldrenderedfiles
114 # are retained.
115 $config{rebuild}=1;
116 ok(loadindex(), "load index");
117 is_deeply(\%pagesources, {
118 }, "%pagesources loaded correctly");
119 is_deeply(\%pagemtime, {
120 }, "%pagemtime loaded correctly");
121 is_deeply(\%pagectime, {
122         Foo => $now,
123         bar => $now-100000,
124         "bar.png" => $now-100000,
125 }, "%pagemtime loaded correctly");
126 is_deeply(\%renderedfiles, {
127 }, "%renderedfiles loaded correctly");
128 is_deeply(\%oldrenderedfiles, {
129         Foo => ["Foo.html"],
130         bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
131         "bar.png" => ["bar.png"],
132 }, "%oldrenderedfiles loaded correctly");
133 is_deeply(\%links, {
134 }, "%links loaded correctly");
135 is_deeply(\%depends, {
136 }, "%depends loaded correctly");
137 is_deeply(\%pagestate, {
138 }, "%pagestate loaded correctly");
139 is_deeply(\%pagecase, {
140 }, "%pagecase generated correctly");
141 is_deeply(\%destsources, {
142 }, "%destsources generated correctly");
143
144 system "rm -rf $config{wikistatedir}";