6 package IkiWiki; # use internal variables
7 use Test::More tests => 31;
9 $config{wikistatedir}="/tmp/ikiwiki-test.$$";
10 system "rm -rf $config{wikistatedir}";
12 ok(! loadindex(), "loading nonexistent index file");
14 # Load standard plugins.
15 ok(loadplugin("meta"), "meta plugin loaded");
16 ok(loadplugin("mdwn"), "mdwn plugin loaded");
18 # Set up a default state.
19 $pagesources{"Foo"}="Foo.mdwn";
20 $pagesources{"bar"}="bar.mdwn";
21 $pagesources{"bar.png"}="bar.png";
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 $typedlinks{"bar"}={tag => {"Foo" => 1}};
37 $depends{"bar"}={"foo*" => 1};
38 $depends{"bar.png"}={};
39 $pagestate{"bar"}{meta}{title}="a page about bar";
40 $pagestate{"bar"}{meta}{moo}="mooooo";
42 ok(saveindex(), "save index");
43 ok(-s "$config{wikistatedir}/indexdb", "index file created");
46 %oldrenderedfiles=%pagectime=();
47 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
48 %destsources=%renderedfiles=%pagecase=%pagestate=();
50 ok(loadindex(), "load index");
51 is_deeply(\%pagesources, {
54 "bar.png" => "bar.png",
55 }, "%pagesources loaded correctly");
56 is_deeply(\%pagemtime, {
60 }, "%pagemtime loaded correctly");
61 is_deeply(\%pagectime, {
64 "bar.png" => $now-100000,
65 }, "%pagemtime loaded correctly");
66 is_deeply(\%renderedfiles, {
68 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
69 "bar.png" => ["bar.png"],
70 }, "%renderedfiles loaded correctly");
71 is_deeply(\%oldrenderedfiles, {
73 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
74 "bar.png" => ["bar.png"],
75 }, "%oldrenderedfiles loaded correctly");
78 bar => ["Foo", "new-page"],
80 }, "%links loaded correctly");
81 is_deeply(\%depends, {
85 }, "%depends loaded correctly");
86 is_deeply(\%pagestate, {
89 title => "a page about bar",
93 }, "%pagestate loaded correctly");
94 is_deeply(\%pagecase, {
97 "bar.png" => "bar.png"
98 }, "%pagecase generated correctly");
99 is_deeply(\%destsources, {
103 "sparkline-foo.gif" => "bar",
104 "bar.png" => "bar.png",
105 }, "%destsources generated correctly");
106 is_deeply(\%typedlinks, {
107 bar => {tag => {"Foo" => 1}},
108 }, "%typedlinks loaded correctly");
109 is_deeply(\%oldtypedlinks, {
110 bar => {tag => {"Foo" => 1}},
111 }, "%oldtypedlinks loaded correctly");
114 %oldrenderedfiles=%pagectime=();
115 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
116 %destsources=%renderedfiles=%pagecase=%pagestate=();
118 # When state is loaded for a wiki rebuild, only ctime, oldrenderedfiles,
119 # and pagesources are retained.
121 ok(loadindex(), "load index");
122 is_deeply(\%pagesources, {
125 "bar.png" => "bar.png",
126 }, "%pagesources loaded correctly");
127 is_deeply(\%pagemtime, {
128 }, "%pagemtime loaded correctly");
129 is_deeply(\%pagectime, {
132 "bar.png" => $now-100000,
133 }, "%pagemtime loaded correctly");
134 is_deeply(\%renderedfiles, {
135 }, "%renderedfiles loaded correctly");
136 is_deeply(\%oldrenderedfiles, {
138 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
139 "bar.png" => ["bar.png"],
140 }, "%oldrenderedfiles loaded correctly");
142 }, "%links loaded correctly");
143 is_deeply(\%depends, {
144 }, "%depends loaded correctly");
145 is_deeply(\%pagestate, {
146 }, "%pagestate loaded correctly");
147 is_deeply(\%pagecase, { # generated implicitly since pagesources is loaded
150 "bar.png" => "bar.png"
151 }, "%pagecase generated correctly");
152 is_deeply(\%destsources, {
153 }, "%destsources generated correctly");
154 is_deeply(\%typedlinks, {
155 }, "%typedlinks cleared correctly");
156 is_deeply(\%oldtypedlinks, {
157 }, "%oldtypedlinks cleared correctly");
159 system "rm -rf $config{wikistatedir}";