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