summaryrefslogtreecommitdiff
path: root/t/autoindex.t
blob: b47f2e0eb867603784100921458c59204cc88067 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki;
  3. use warnings;
  4. use strict;
  5. use Test::More;
  6. BEGIN { use_ok("IkiWiki"); }
  7. BEGIN { use_ok("IkiWiki::Render"); }
  8. BEGIN { use_ok("IkiWiki::Plugin::autoindex"); }
  9. BEGIN { use_ok("IkiWiki::Plugin::html"); }
  10. BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
  11. ok(! system("rm -rf t/tmp; mkdir t/tmp"));
  12. $config{verbose} = 1;
  13. $config{srcdir} = 't/tmp';
  14. $config{underlaydir} = 't/tmp';
  15. $config{underlaydirbase} = '.';
  16. $config{templatedir} = 'templates';
  17. $config{usedirs} = 1;
  18. $config{htmlext} = 'html';
  19. $config{wiki_file_chars} = "-[:alnum:]+/.:_";
  20. $config{userdir} = "users";
  21. $config{tagbase} = "tags";
  22. $config{default_pageext} = "mdwn";
  23. $config{wiki_file_prune_regexps} = [qr/^\./];
  24. is(checkconfig(), 1);
  25. %oldrenderedfiles=%pagectime=();
  26. %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
  27. %destsources=%renderedfiles=%pagecase=%pagestate=();
  28. # pages that (we claim) were deleted in an earlier pass
  29. $wikistate{autoindex}{deleted}{deleted} = 1;
  30. $wikistate{autoindex}{deleted}{expunged} = 1;
  31. $wikistate{autoindex}{deleted}{reinstated} = 1;
  32. foreach my $page (qw(tags/numbers deleted/bar reinstated reinstated/foo gone/bar)) {
  33. # we use a non-default extension for these, so they're distinguishable
  34. # from programmatically-created pages
  35. $pagesources{$page} = "$page.html";
  36. $pagemtime{$page} = $pagectime{$page} = 1000000;
  37. writefile("$page.html", "t/tmp", "your ad here");
  38. }
  39. # "gone" disappeared just before this refresh pass so it still has a mtime
  40. $pagemtime{gone} = $pagectime{gone} = 1000000;
  41. IkiWiki::Plugin::autoindex::refresh();
  42. # these pages are still on record as having been deleted, because they have
  43. # a reason to be re-created
  44. is($wikistate{autoindex}{deleted}{deleted}, 1);
  45. is($wikistate{autoindex}{deleted}{gone}, 1);
  46. ok(! -f "t/tmp/deleted.mdwn");
  47. ok(! -f "t/tmp/gone.mdwn");
  48. # this page does not exist and has no reason to be re-created, so we forget
  49. # about it - it will be re-created if it gains sub-pages
  50. ok(! exists $wikistate{autoindex}{deleted}{expunged});
  51. ok(! -f "t/tmp/expunged.mdwn");
  52. # this page was re-created, so it drops off the radar
  53. ok(! exists $wikistate{autoindex}{deleted}{reinstated});
  54. ok(! -f "t/tmp/reinstated.mdwn");
  55. # needs creating
  56. ok(! exists $wikistate{autoindex}{deleted}{tags});
  57. ok(-s "t/tmp/tags.mdwn");
  58. done_testing();
  59. 1;