Added my site, even though it's in an early state
[ikiwiki.git] / t / index.t
blob392a167e9747131dbcd065b022a725ebf35f16d2
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use IkiWiki;
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";
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 $typedlinks{"bar"}={tag => {"Foo" => 1}};
35 $links{"bar.png"}=[];
36 $depends{"Foo"}={};
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");
47 # Clear state.
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, {
54 Foo => "Foo.mdwn",
55 bar => "bar.mdwn",
56 "bar.png" => "bar.png",
57 }, "%pagesources loaded correctly");
58 is_deeply(\%pagemtime, {
59 Foo => $now,
60 bar => $now-1000,
61 "bar.png" => $now,
62 }, "%pagemtime loaded correctly");
63 is_deeply(\%pagectime, {
64 Foo => $now,
65 bar => $now-100000,
66 "bar.png" => $now-100000,
67 }, "%pagemtime loaded correctly");
68 is_deeply(\%renderedfiles, {
69 Foo => ["Foo.html"],
70 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
71 "bar.png" => ["bar.png"],
72 }, "%renderedfiles loaded correctly");
73 is_deeply(\%oldrenderedfiles, {
74 Foo => ["Foo.html"],
75 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
76 "bar.png" => ["bar.png"],
77 }, "%oldrenderedfiles loaded correctly");
78 is_deeply(\%links, {
79 Foo => ["bar.png"],
80 bar => ["Foo", "new-page"],
81 "bar.png" => [],
82 }, "%links loaded correctly");
83 is_deeply(\%depends, {
84 Foo => {},
85 bar => {"foo*" => 1},
86 "bar.png" => {},
87 }, "%depends loaded correctly");
88 is_deeply(\%pagestate, {
89 bar => {
90 meta => {
91 title => "a page about bar",
92 moo => "mooooo",
95 }, "%pagestate loaded correctly");
96 is_deeply(\%pagecase, {
97 foo => "Foo",
98 bar => "bar",
99 "bar.png" => "bar.png"
100 }, "%pagecase generated correctly");
101 is_deeply(\%destsources, {
102 "Foo.html" => "Foo",
103 "bar.html" => "bar",
104 "bar.rss" => "bar",
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");
115 # Clear state.
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.
122 $config{rebuild}=1;
123 ok(loadindex(), "load index");
124 is_deeply(\%pagesources, {
125 Foo => "Foo.mdwn",
126 bar => "bar.mdwn",
127 "bar.png" => "bar.png",
128 }, "%pagesources loaded correctly");
129 is_deeply(\%pagemtime, {
130 }, "%pagemtime loaded correctly");
131 is_deeply(\%pagectime, {
132 Foo => $now,
133 bar => $now-100000,
134 "bar.png" => $now-100000,
135 }, "%pagemtime loaded correctly");
136 is_deeply(\%renderedfiles, {
137 }, "%renderedfiles loaded correctly");
138 is_deeply(\%oldrenderedfiles, {
139 Foo => ["Foo.html"],
140 bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
141 "bar.png" => ["bar.png"],
142 }, "%oldrenderedfiles loaded correctly");
143 is_deeply(\%links, {
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
150 foo => "Foo",
151 bar => "bar",
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}";