]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/autoindex-committed.t
3.20161229.1~bpo8+1
[git.ikiwiki.info.git] / t / autoindex-committed.t
1 #!/usr/bin/perl
2 package IkiWiki;
4 use warnings;
5 use strict;
6 use Test::More tests => 43;
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"));
17 $config{verbose} = 1;
18 $config{srcdir} = 't/tmp/in';
19 $config{underlaydir} = 't/tmp/underlay';
20 $config{underlaydirbase} = '.';
21 $config{templatedir} = 'templates';
22 $config{usedirs} = 1;
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} = 1;
31 is(checkconfig(), 1);
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/in", "your ad here");
49 }
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/in", "this page is internal");
57 # a directory containing only a page in an underlay shouldn't be indexed
58 # (arguably; see [[transient autocreated tagbase is not transient autoindexed]])
59 $pagesources{"has_underlay/underlay"} = "has_underlay/underlay.mdwn";
60 $pagemtime{"has_underlay/underlay"} = 123456789;
61 $pagectime{"has_underlay/underlay"} = 123456789;
62 writefile("has_underlay/underlay.mdwn", "t/tmp/underlay", "this page is in an underlay");
64 # a directory containing only a transient page shouldn't be indexed
65 # (arguably; see [[transient autocreated tagbase is not transient autoindexed]])
66 $pagesources{"has_transient/transient"} = "has_transient/transient.mdwn";
67 $pagemtime{"has_transient/transient"} = 123456789;
68 $pagectime{"has_transient/transient"} = 123456789;
69 writefile("has_transient/transient.mdwn", "t/tmp/in/.ikiwiki/transient", "this page is transient");
71 # a directory containing only an attachment should be indexed
72 $pagesources{"attached/pie.jpg"} = "attached/pie.jpg";
73 $pagemtime{"attached/pie.jpg"} = 123456789;
74 $pagectime{"attached/pie.jpg"} = 123456789;
75 writefile("attached/pie.jpg", "t/tmp/in", "I lied, this isn't a real JPEG");
77 # "gone" disappeared just before this refresh pass so it still has a mtime
78 $pagemtime{gone} = $pagectime{gone} = 1000000;
80 my %pages;
81 my @del;
83 IkiWiki::Plugin::autoindex::refresh();
85 # this page is still on record as having been deleted, because it has
86 # a reason to be re-created
87 is($wikistate{autoindex}{autofile}{"deleted.mdwn"}, 1);
88 is($autofiles{"deleted.mdwn"}{plugin}, "autoindex");
89 %pages = ();
90 @del = ();
91 IkiWiki::gen_autofile("deleted.mdwn", \%pages, \@del);
92 is_deeply(\%pages, {});
93 is_deeply(\@del, []);
94 ok(! -f "t/tmp/in/deleted.mdwn");
96 # this page is tried as an autofile, but because it'll be in @del, it's not
97 # actually created
98 ok(! exists $wikistate{autoindex}{autofile}{"gone.mdwn"});
99 %pages = ();
100 @del = ("gone.mdwn");
101 is($autofiles{"gone.mdwn"}{plugin}, "autoindex");
102 IkiWiki::gen_autofile("gone.mdwn", \%pages, \@del);
103 is_deeply(\%pages, {});
104 is_deeply(\@del, ["gone.mdwn"]);
105 ok(! -f "t/tmp/in/gone.mdwn");
107 # this page does not exist and has no reason to be re-created, but we no longer
108 # have a special case for that - see
109 # [[todo/autoindex_should_use_add__95__autofile]] - so it won't be created
110 # even if it gains subpages later
111 is($wikistate{autoindex}{autofile}{"expunged.mdwn"}, 1);
112 ok(! exists $autofiles{"expunged.mdwn"});
113 ok(! -f "t/tmp/in/expunged.mdwn");
115 # a directory containing only an internal page shouldn't be indexed
116 ok(! exists $wikistate{autoindex}{autofile}{"has_internal.mdwn"});
117 ok(! exists $autofiles{"has_internal.mdwn"});
118 ok(! -f "t/tmp/in/has_internal.mdwn");
120 # a directory containing only a page in an underlay shouldn't be indexed
121 # (arguably; see [[transient autocreated tagbase is not transient autoindexed]])
122 ok(! exists $wikistate{autoindex}{autofile}{"has_underlay.mdwn"});
123 ok(! exists $autofiles{"has_underlay.mdwn"});
124 ok(! -f "t/tmp/in/has_underlay.mdwn");
126 # a directory containing only a transient page shouldn't be indexed
127 # (arguably; see [[transient autocreated tagbase is not transient autoindexed]])
128 ok(! exists $wikistate{autoindex}{autofile}{"has_transient.mdwn"});
129 ok(! exists $autofiles{"has_transient.mdwn"});
130 ok(! -f "t/tmp/in/has_transient.mdwn");
132 # this page was re-created, but that no longer gets a special case
133 # (see [[todo/autoindex_should_use_add__95__autofile]]) so it's the same as
134 # deleted
135 is($wikistate{autoindex}{autofile}{"reinstated.mdwn"}, 1);
136 ok(! exists $autofiles{"reinstated.mdwn"});
137 ok(! -f "t/tmp/in/reinstated.mdwn");
139 # needs creating (deferred; part of the autofile mechanism now)
140 ok(! exists $wikistate{autoindex}{autofile}{"tags.mdwn"});
141 %pages = ();
142 @del = ();
143 is($autofiles{"tags.mdwn"}{plugin}, "autoindex");
144 IkiWiki::gen_autofile("tags.mdwn", \%pages, \@del);
145 is_deeply(\%pages, {"t/tmp/in/tags" => 1});
146 is_deeply(\@del, []);
147 ok(-s "t/tmp/in/tags.mdwn");
149 # needs creating because of an attachment
150 ok(! exists $wikistate{autoindex}{autofile}{"attached.mdwn"});
151 %pages = ();
152 @del = ();
153 is($autofiles{"attached.mdwn"}{plugin}, "autoindex");
154 IkiWiki::gen_autofile("attached.mdwn", \%pages, \@del);
155 is_deeply(\%pages, {"t/tmp/in/attached" => 1});
156 is_deeply(\@del, []);
157 ok(-s "t/tmp/in/attached.mdwn");
159 1;