]> sipb.mit.edu Git - ikiwiki.git/blob - t/autoindex.t
autoindex.t: check that attachments cause indexing
[ikiwiki.git] / t / autoindex.t
1 #!/usr/bin/perl
2 package IkiWiki;
3
4 use warnings;
5 use strict;
6 use Test::More tests => 22;
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
37 $wikistate{autoindex}{deleted}{deleted} = 1;
38 $wikistate{autoindex}{deleted}{expunged} = 1;
39 $wikistate{autoindex}{deleted}{reinstated} = 1;
40
41 foreach my $page (qw(tags/numbers deleted/bar reinstated reinstated/foo gone/bar)) {
42         # we use a non-default extension for these, so they're distinguishable
43         # from programmatically-created pages
44         $pagesources{$page} = "$page.html";
45         $pagemtime{$page} = $pagectime{$page} = 1000000;
46         writefile("$page.html", "t/tmp", "your ad here");
47 }
48
49 # a directory containing only an internal page shouldn't be indexed
50 $pagesources{"has_internal/internal"} = "has_internal/internal._aggregated";
51 $pagemtime{"has_internal/internal"} = 123456789;
52 $pagectime{"has_internal/internal"} = 123456789;
53 writefile("has_internal/internal._aggregated", "t/tmp", "this page is internal");
54
55 # a directory containing only an attachment should be indexed
56 $pagesources{"attached/pie.jpg"} = "attached/pie.jpg";
57 $pagemtime{"attached/pie.jpg"} = 123456789;
58 $pagectime{"attached/pie.jpg"} = 123456789;
59 writefile("attached/pie.jpg", "t/tmp", "I lied, this isn't a real JPEG");
60
61 # "gone" disappeared just before this refresh pass so it still has a mtime
62 $pagemtime{gone} = $pagectime{gone} = 1000000;
63
64 IkiWiki::Plugin::autoindex::refresh();
65
66 # these pages are still on record as having been deleted, because they have
67 # a reason to be re-created
68 is($wikistate{autoindex}{deleted}{deleted}, 1);
69 is($wikistate{autoindex}{deleted}{gone}, 1);
70 ok(! -f "t/tmp/deleted.mdwn");
71 ok(! -f "t/tmp/gone.mdwn");
72
73 # this page does not exist and has no reason to be re-created, so we forget
74 # about it - it will be re-created if it gains sub-pages
75 ok(! exists $wikistate{autoindex}{deleted}{expunged});
76 ok(! -f "t/tmp/expunged.mdwn");
77
78 # a directory containing only an internal page shouldn't be indexed
79 ok(! exists $wikistate{autoindex}{deleted}{has_internal});
80 ok(! -f "t/tmp/has_internal.mdwn");
81
82 # this page was re-created, so it drops off the radar
83 ok(! exists $wikistate{autoindex}{deleted}{reinstated});
84 ok(! -f "t/tmp/reinstated.mdwn");
85
86 # needs creating
87 ok(! exists $wikistate{autoindex}{deleted}{tags});
88 ok(-s "t/tmp/tags.mdwn");
89
90 # needs creating because of an attachment
91 ok(! exists $wikistate{autoindex}{deleted}{attached});
92 ok(-s "t/tmp/attached.mdwn");
93
94 1;