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 and oldrenderedfiles
123 ok(loadindex(), "load index");
124 is_deeply(\%pagesources, {
125 }, "%pagesources loaded correctly");
126 is_deeply(\%pagemtime, {
127 }, "%pagemtime loaded correctly");
128 is_deeply(\%pagectime, {
131 "bar.png" => $now-100000,
132 }, "%pagemtime loaded correctly");
133 is_deeply(\%renderedfiles, {
134 }, "%renderedfiles loaded correctly");
135 is_deeply(\%oldrenderedfiles, {
137 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
138 "bar.png" => ["bar.png"],
139 }, "%oldrenderedfiles loaded correctly");
141 }, "%links loaded correctly");
142 is_deeply(\%depends, {
143 }, "%depends loaded correctly");
144 is_deeply(\%pagestate, {
145 }, "%pagestate loaded correctly");
146 is_deeply(\%pagecase, {
147 }, "%pagecase generated correctly");
148 is_deeply(\%destsources, {
149 }, "%destsources generated correctly");
150 is_deeply(\%typedlinks, {
151 }, "%typedlinks cleared correctly");
152 is_deeply(\%oldtypedlinks, {
153 }, "%oldtypedlinks cleared correctly");
155 system "rm -rf $config{wikistatedir}";