]> sipb.mit.edu Git - ikiwiki.git/blob - t/autoindex.t
autoindex test: check that an internal page doesn't 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 => 20;
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 # "gone" disappeared just before this refresh pass so it still has a mtime
56 $pagemtime{gone} = $pagectime{gone} = 1000000;
57
58 IkiWiki::Plugin::autoindex::refresh();
59
60 # these pages are still on record as having been deleted, because they have
61 # a reason to be re-created
62 is($wikistate{autoindex}{deleted}{deleted}, 1);
63 is($wikistate{autoindex}{deleted}{gone}, 1);
64 ok(! -f "t/tmp/deleted.mdwn");
65 ok(! -f "t/tmp/gone.mdwn");
66
67 # this page does not exist and has no reason to be re-created, so we forget
68 # about it - it will be re-created if it gains sub-pages
69 ok(! exists $wikistate{autoindex}{deleted}{expunged});
70 ok(! -f "t/tmp/expunged.mdwn");
71
72 # a directory containing only an internal page shouldn't be indexed
73 ok(! exists $wikistate{autoindex}{deleted}{has_internal});
74 ok(! -f "t/tmp/has_internal.mdwn");
75
76 # this page was re-created, so it drops off the radar
77 ok(! exists $wikistate{autoindex}{deleted}{reinstated});
78 ok(! -f "t/tmp/reinstated.mdwn");
79
80 # needs creating
81 ok(! exists $wikistate{autoindex}{deleted}{tags});
82 ok(-s "t/tmp/tags.mdwn");
83
84 1;