6 use Test
::More tests
=> 38;
8 BEGIN { use_ok
("IkiWiki"); }
9 BEGIN { use_ok
("IkiWiki::Render"); }
10 BEGIN { use_ok
("IkiWiki::Plugin::aggregate"); }
11 BEGIN { use_ok
("IkiWiki::Plugin::autoindex"); }
12 BEGIN { use_ok
("IkiWiki::Plugin::html"); }
13 BEGIN { use_ok
("IkiWiki::Plugin::mdwn"); }
15 ok
(! system("rm -rf t/tmp; mkdir t/tmp"));
18 $config{srcdir
} = 't/tmp';
19 $config{underlaydir
} = 't/tmp';
20 $config{underlaydirbase
} = '.';
21 $config{templatedir
} = 'templates';
23 $config{htmlext
} = 'html';
24 $config{wiki_file_chars
} = "-[:alnum:]+/.:_";
25 $config{userdir
} = "users";
26 $config{tagbase
} = "tags";
27 $config{default_pageext
} = "mdwn";
28 $config{wiki_file_prune_regexps
} = [qr/^\./];
29 $config{autoindex_commit
} = 0;
33 %oldrenderedfiles=%pagectime=();
34 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
35 %destsources=%renderedfiles=%pagecase=%pagestate=();
37 # Pages that (we claim) were deleted in an earlier pass. We're using deleted,
38 # not autofile, to test backwards compat.
39 $wikistate{autoindex
}{deleted
}{deleted
} = 1;
40 $wikistate{autoindex
}{deleted
}{expunged
} = 1;
41 $wikistate{autoindex
}{deleted
}{reinstated
} = 1;
43 foreach my $page (qw(tags/numbers deleted/bar reinstated reinstated/foo gone/bar)) {
44 # we use a non-default extension for these, so they're distinguishable
45 # from programmatically-created pages
46 $pagesources{$page} = "$page.html";
47 $pagemtime{$page} = $pagectime{$page} = 1000000;
48 writefile
("$page.html", "t/tmp", "your ad here");
51 # a directory containing only an internal page shouldn't be indexed
52 $pagesources{"has_internal/internal"} = "has_internal/internal._aggregated";
53 $pagemtime{"has_internal/internal"} = 123456789;
54 $pagectime{"has_internal/internal"} = 123456789;
55 writefile
("has_internal/internal._aggregated", "t/tmp", "this page is internal");
57 # a directory containing only an attachment should be indexed
58 $pagesources{"attached/pie.jpg"} = "attached/pie.jpg";
59 $pagemtime{"attached/pie.jpg"} = 123456789;
60 $pagectime{"attached/pie.jpg"} = 123456789;
61 writefile
("attached/pie.jpg", "t/tmp", "I lied, this isn't a real JPEG");
63 # "gone" disappeared just before this refresh pass so it still has a mtime
64 $pagemtime{gone
} = $pagectime{gone
} = 1000000;
69 IkiWiki
::Plugin
::autoindex
::refresh
();
71 # this page is still on record as having been deleted, because it has
72 # a reason to be re-created
73 is
($wikistate{autoindex
}{autofile
}{"deleted.mdwn"}, 1);
74 is
($autofiles{"deleted.mdwn"}{plugin
}, "autoindex");
77 IkiWiki
::gen_autofile
("deleted.mdwn", \
%pages, \
@del);
78 is_deeply
(\
%pages, {}) || diag explain \
%pages;
79 is_deeply
(\
@del, []) || diag explain \
@del;
80 ok
(! -f
"t/tmp/deleted.mdwn");
82 # this page is tried as an autofile, but because it'll be in @del, it's not
84 ok
(! exists $wikistate{autoindex
}{autofile
}{"gone.mdwn"});
87 is
($autofiles{"gone.mdwn"}{plugin
}, "autoindex");
88 IkiWiki
::gen_autofile
("gone.mdwn", \
%pages, \
@del);
89 is_deeply
(\
%pages, {}) || diag explain \
%pages;
90 is_deeply
(\
@del, ["gone.mdwn"]) || diag explain \
@del;
91 ok
(! -f
"t/tmp/gone.mdwn");
93 # this page does not exist and has no reason to be re-created, but we no longer
94 # have a special case for that - see
95 # [[todo/autoindex_should_use_add__95__autofile]] - so it won't be created
96 # even if it gains subpages later
97 is
($wikistate{autoindex
}{autofile
}{"expunged.mdwn"}, 1);
98 ok
(! exists $autofiles{"expunged.mdwn"});
99 ok
(! -f
"t/tmp/expunged.mdwn");
101 # a directory containing only an internal page shouldn't be indexed
102 ok
(! exists $wikistate{autoindex
}{autofile
}{"has_internal.mdwn"});
103 ok
(! exists $autofiles{"has_internal.mdwn"});
104 ok
(! -f
"t/tmp/has_internal.mdwn");
106 # this page was re-created, but that no longer gets a special case
107 # (see [[todo/autoindex_should_use_add__95__autofile]]) so it's the same as
109 is
($wikistate{autoindex
}{autofile
}{"reinstated.mdwn"}, 1);
110 ok
(! exists $autofiles{"reinstated.mdwn"});
111 ok
(! -f
"t/tmp/reinstated.mdwn");
113 # needs creating (deferred; part of the autofile mechanism now)
114 ok
(! exists $wikistate{autoindex
}{autofile
}{"tags.mdwn"});
117 is
($autofiles{"tags.mdwn"}{plugin
}, "autoindex");
118 IkiWiki
::gen_autofile
("tags.mdwn", \
%pages, \
@del);
119 is_deeply
(\
%pages, {"t/tmp/tags" => 1}) || diag explain \
%pages;
120 is_deeply
(\
@del, []) || diag explain \
@del;
121 ok
(! -s
"t/tmp/tags.mdwn");
122 ok
(-s
"t/tmp/.ikiwiki/transient/tags.mdwn");
124 # needs creating because of an attachment
125 ok
(! exists $wikistate{autoindex
}{autofile
}{"attached.mdwn"});
128 is
($autofiles{"attached.mdwn"}{plugin
}, "autoindex");
129 IkiWiki
::gen_autofile
("attached.mdwn", \
%pages, \
@del);
130 is_deeply
(\
%pages, {"t/tmp/attached" => 1}) || diag explain \
%pages;
131 is_deeply
(\
@del, []) || diag explain \
@del;
132 ok
(-s
"t/tmp/.ikiwiki/transient/attached.mdwn");