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";
41 # only loaded plugins save state, so this should not be saved out
42 $pagestate{"bar"}{nosuchplugin}{moo}="mooooo";
44 ok(saveindex(), "save index");
45 ok(-s "$config{wikistatedir}/indexdb", "index file created");
48 %oldrenderedfiles=%pagectime=();
49 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
50 %destsources=%renderedfiles=%pagecase=%pagestate=();
52 ok(loadindex(), "load index");
53 is_deeply(\%pagesources, {
56 "bar.png" => "bar.png",
57 }, "%pagesources loaded correctly");
58 is_deeply(\%pagemtime, {
62 }, "%pagemtime loaded correctly");
63 is_deeply(\%pagectime, {
66 "bar.png" => $now-100000,
67 }, "%pagemtime loaded correctly");
68 is_deeply(\%renderedfiles, {
70 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
71 "bar.png" => ["bar.png"],
72 }, "%renderedfiles loaded correctly");
73 is_deeply(\%oldrenderedfiles, {
75 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
76 "bar.png" => ["bar.png"],
77 }, "%oldrenderedfiles loaded correctly");
80 bar => ["Foo", "new-page"],
82 }, "%links loaded correctly");
83 is_deeply(\%depends, {
87 }, "%depends loaded correctly");
88 is_deeply(\%pagestate, {
91 title => "a page about bar",
95 }, "%pagestate loaded correctly");
96 is_deeply(\%pagecase, {
99 "bar.png" => "bar.png"
100 }, "%pagecase generated correctly");
101 is_deeply(\%destsources, {
105 "sparkline-foo.gif" => "bar",
106 "bar.png" => "bar.png",
107 }, "%destsources generated correctly");
108 is_deeply(\%typedlinks, {
109 bar => {tag => {"Foo" => 1}},
110 }, "%typedlinks loaded correctly");
111 is_deeply(\%oldtypedlinks, {
112 bar => {tag => {"Foo" => 1}},
113 }, "%oldtypedlinks loaded correctly");
116 %oldrenderedfiles=%pagectime=();
117 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
118 %destsources=%renderedfiles=%pagecase=%pagestate=();
120 # When state is loaded for a wiki rebuild, only ctime, oldrenderedfiles,
121 # and pagesources are retained.
123 ok(loadindex(), "load index");
124 is_deeply(\%pagesources, {
127 "bar.png" => "bar.png",
128 }, "%pagesources loaded correctly");
129 is_deeply(\%pagemtime, {
130 }, "%pagemtime loaded correctly");
131 is_deeply(\%pagectime, {
134 "bar.png" => $now-100000,
135 }, "%pagemtime loaded correctly");
136 is_deeply(\%renderedfiles, {
137 }, "%renderedfiles loaded correctly");
138 is_deeply(\%oldrenderedfiles, {
140 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
141 "bar.png" => ["bar.png"],
142 }, "%oldrenderedfiles loaded correctly");
144 }, "%links loaded correctly");
145 is_deeply(\%depends, {
146 }, "%depends loaded correctly");
147 is_deeply(\%pagestate, {
148 }, "%pagestate loaded correctly");
149 is_deeply(\%pagecase, { # generated implicitly since pagesources is loaded
152 "bar.png" => "bar.png"
153 }, "%pagecase generated correctly");
154 is_deeply(\%destsources, {
155 }, "%destsources generated correctly");
156 is_deeply(\%typedlinks, {
157 }, "%typedlinks cleared correctly");
158 is_deeply(\%oldtypedlinks, {
159 }, "%oldtypedlinks cleared correctly");
161 system "rm -rf $config{wikistatedir}";