]> sipb.mit.edu Git - ikiwiki.git/blob - t/autoindex.t
Merge branch 'ready/autoindex-autofile' into HEAD
[ikiwiki.git] / t / autoindex.t
1 #!/usr/bin/perl
2 package IkiWiki;
3
4 use warnings;
5 use strict;
6 use Test::More tests => 37;
7
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"); }
14
15 ok(! system("rm -rf t/tmp; mkdir t/tmp"));
16
17 $config{verbose} = 1;
18 $config{srcdir} = 't/tmp';
19 $config{underlaydir} = 't/tmp';
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
30 is(checkconfig(), 1);
31
32 %oldrenderedfiles=%pagectime=();
33 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
34 %destsources=%renderedfiles=%pagecase=%pagestate=();
35
36 # Pages that (we claim) were deleted in an earlier pass. We're using deleted,
37 # not autofile, to test backwards compat.
38 $wikistate{autoindex}{deleted}{deleted} = 1;
39 $wikistate{autoindex}{deleted}{expunged} = 1;
40 $wikistate{autoindex}{deleted}{reinstated} = 1;
41
42 foreach my $page (qw(tags/numbers deleted/bar reinstated reinstated/foo gone/bar)) {
43         # we use a non-default extension for these, so they're distinguishable
44         # from programmatically-created pages
45         $pagesources{$page} = "$page.html";
46         $pagemtime{$page} = $pagectime{$page} = 1000000;
47         writefile("$page.html", "t/tmp", "your ad here");
48 }
49
50 # a directory containing only an internal page shouldn't be indexed
51 $pagesources{"has_internal/internal"} = "has_internal/internal._aggregated";
52 $pagemtime{"has_internal/internal"} = 123456789;
53 $pagectime{"has_internal/internal"} = 123456789;
54 writefile("has_internal/internal._aggregated", "t/tmp", "this page is internal");
55
56 # a directory containing only an attachment should be indexed
57 $pagesources{"attached/pie.jpg"} = "attached/pie.jpg";
58 $pagemtime{"attached/pie.jpg"} = 123456789;
59 $pagectime{"attached/pie.jpg"} = 123456789;
60 writefile("attached/pie.jpg", "t/tmp", "I lied, this isn't a real JPEG");
61
62 # "gone" disappeared just before this refresh pass so it still has a mtime
63 $pagemtime{gone} = $pagectime{gone} = 1000000;
64
65 my %pages;
66 my @del;
67
68 IkiWiki::Plugin::autoindex::refresh();
69
70 # this page is still on record as having been deleted, because it has
71 # a reason to be re-created
72 is($wikistate{autoindex}{autofile}{"deleted.mdwn"}, 1);
73 is($autofiles{"deleted.mdwn"}{plugin}, "autoindex");
74 %pages = ();
75 @del = ();
76 IkiWiki::gen_autofile("deleted.mdwn", \%pages, \@del);
77 is_deeply(\%pages, {}) || diag explain \%pages;
78 is_deeply(\@del, []) || diag explain \@del;
79 ok(! -f "t/tmp/deleted.mdwn");
80
81 # this page is tried as an autofile, but because it'll be in @del, it's not
82 # actually created
83 ok(! exists $wikistate{autoindex}{autofile}{"gone.mdwn"});
84 %pages = ();
85 @del = ("gone.mdwn");
86 is($autofiles{"gone.mdwn"}{plugin}, "autoindex");
87 IkiWiki::gen_autofile("gone.mdwn", \%pages, \@del);
88 is_deeply(\%pages, {}) || diag explain \%pages;
89 is_deeply(\@del, ["gone.mdwn"]) || diag explain \@del;
90 ok(! -f "t/tmp/gone.mdwn");
91
92 # this page does not exist and has no reason to be re-created, but we no longer
93 # have a special case for that - see
94 # [[todo/autoindex_should_use_add__95__autofile]] - so it won't be created
95 # even if it gains subpages later
96 is($wikistate{autoindex}{autofile}{"expunged.mdwn"}, 1);
97 ok(! exists $autofiles{"expunged.mdwn"});
98 ok(! -f "t/tmp/expunged.mdwn");
99
100 # a directory containing only an internal page shouldn't be indexed
101 ok(! exists $wikistate{autoindex}{autofile}{"has_internal.mdwn"});
102 ok(! exists $autofiles{"has_internal.mdwn"});
103 ok(! -f "t/tmp/has_internal.mdwn");
104
105 # this page was re-created, but that no longer gets a special case
106 # (see [[todo/autoindex_should_use_add__95__autofile]]) so it's the same as
107 # deleted
108 is($wikistate{autoindex}{autofile}{"reinstated.mdwn"}, 1);
109 ok(! exists $autofiles{"reinstated.mdwn"});
110 ok(! -f "t/tmp/reinstated.mdwn");
111
112 # needs creating (deferred; part of the autofile mechanism now)
113 ok(! exists $wikistate{autoindex}{autofile}{"tags.mdwn"});
114 %pages = ();
115 @del = ();
116 is($autofiles{"tags.mdwn"}{plugin}, "autoindex");
117 IkiWiki::gen_autofile("tags.mdwn", \%pages, \@del);
118 is_deeply(\%pages, {"t/tmp/tags" => 1}) || diag explain \%pages;
119 is_deeply(\@del, []) || diag explain \@del;
120 ok(-s "t/tmp/tags.mdwn");
121
122 # needs creating because of an attachment
123 ok(! exists $wikistate{autoindex}{autofile}{"attached.mdwn"});
124 %pages = ();
125 @del = ();
126 is($autofiles{"attached.mdwn"}{plugin}, "autoindex");
127 IkiWiki::gen_autofile("attached.mdwn", \%pages, \@del);
128 is_deeply(\%pages, {"t/tmp/attached" => 1}) || diag explain \%pages;
129 is_deeply(\@del, []) || diag explain \@del;
130 ok(-s "t/tmp/attached.mdwn");
131
132 1;