6 package IkiWiki; # use internal variables
7 use Test::More tests => 27;
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"];
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";
43 ok(saveindex(), "save index");
44 ok(-s "$config{wikistatedir}/indexdb", "index file created");
47 %oldrenderedfiles=%pagectime=();
48 %pagesources=%pagemtime=%oldlinks=%links=%depends=
49 %destsources=%renderedfiles=%pagecase=%pagestate=();
51 ok(loadindex(), "load index");
52 is_deeply(\%pagesources, {
55 "bar.png" => "bar.png",
56 }, "%pagesources loaded correctly");
57 is_deeply(\%pagemtime, {
61 }, "%pagemtime loaded correctly");
62 is_deeply(\%pagectime, {
65 "bar.png" => $now-100000,
66 }, "%pagemtime loaded correctly");
67 is_deeply(\%renderedfiles, {
69 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
70 "bar.png" => ["bar.png"],
71 }, "%renderedfiles loaded correctly");
72 is_deeply(\%oldrenderedfiles, {
74 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
75 "bar.png" => ["bar.png"],
76 }, "%oldrenderedfiles loaded correctly");
79 bar => ["Foo", "new-page"],
81 }, "%links loaded correctly");
82 is_deeply(\%depends, {
86 }, "%depends loaded correctly");
87 is_deeply(\%pagestate, {
90 title => "a page about bar",
94 }, "%pagestate loaded correctly");
95 is_deeply(\%pagecase, {
98 "bar.png" => "bar.png"
99 }, "%pagecase generated correctly");
100 is_deeply(\%destsources, {
104 "sparkline-foo.gif" => "bar",
105 "bar.png" => "bar.png",
106 }, "%destsources generated correctly");
109 %oldrenderedfiles=%pagectime=();
110 %pagesources=%pagemtime=%oldlinks=%links=%depends=
111 %destsources=%renderedfiles=%pagecase=%pagestate=();
113 # When state is loaded for a wiki rebuild, only ctime and oldrenderedfiles
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, {
124 "bar.png" => $now-100000,
125 }, "%pagemtime loaded correctly");
126 is_deeply(\%renderedfiles, {
127 }, "%renderedfiles loaded correctly");
128 is_deeply(\%oldrenderedfiles, {
130 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
131 "bar.png" => ["bar.png"],
132 }, "%oldrenderedfiles loaded correctly");
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");
144 system "rm -rf $config{wikistatedir}";