summaryrefslogtreecommitdiff
path: root/t/index.t
blob: e79609902a5856f4a58cc47dec9477df074a0030 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use IkiWiki;
  5. package IkiWiki; # use internal variables
  6. use Test::More tests => 27;
  7. $config{wikistatedir}="/tmp/ikiwiki-test.$$";
  8. system "rm -rf $config{wikistatedir}";
  9. ok(! loadindex(), "loading nonexistent index file");
  10. # Load standard plugins.
  11. ok(loadplugin("meta"), "meta plugin loaded");
  12. ok(loadplugin("mdwn"), "mdwn plugin loaded");
  13. # Set up a default state.
  14. $pagesources{"Foo"}="Foo.mdwn";
  15. $pagesources{"bar"}="bar.mdwn";
  16. $pagesources{"bar.png"}="bar.png";
  17. my $now=time();
  18. $pagemtime{"Foo"}=$now;
  19. $pagemtime{"bar"}=$now-1000;
  20. $pagemtime{"bar.png"}=$now;
  21. $pagectime{"Foo"}=$now;
  22. $pagectime{"bar"}=$now-100000;
  23. $pagectime{"bar.png"}=$now-100000;
  24. $renderedfiles{"Foo"}=["Foo.html"];
  25. $renderedfiles{"bar"}=["bar.html", "bar.rss", "sparkline-foo.gif"];
  26. $renderedfiles{"bar.png"}=["bar.png"];
  27. $links{"Foo"}=["bar.png"];
  28. $links{"bar"}=["Foo", "new-page"];
  29. $links{"bar.png"}=[];
  30. $depends{"Foo"}="";
  31. $depends{"bar"}="foo*";
  32. $depends{"bar.png"}="";
  33. $pagestate{"bar"}{meta}{title}="a page about bar";
  34. $pagestate{"bar"}{meta}{moo}="mooooo";
  35. # only loaded plugins save state, so this should not be saved out
  36. $pagestate{"bar"}{nosuchplugin}{moo}="mooooo";
  37. ok(saveindex(), "save index");
  38. ok(-s "$config{wikistatedir}/indexdb", "index file created");
  39. # Clear state.
  40. %oldrenderedfiles=%pagectime=();
  41. %pagesources=%pagemtime=%oldlinks=%links=%depends=
  42. %destsources=%renderedfiles=%pagecase=%pagestate=();
  43. ok(loadindex(), "load index");
  44. is_deeply(\%pagesources, {
  45. Foo => "Foo.mdwn",
  46. bar => "bar.mdwn",
  47. "bar.png" => "bar.png",
  48. }, "%pagesources loaded correctly");
  49. is_deeply(\%pagemtime, {
  50. Foo => $now,
  51. bar => $now-1000,
  52. "bar.png" => $now,
  53. }, "%pagemtime loaded correctly");
  54. is_deeply(\%pagectime, {
  55. Foo => $now,
  56. bar => $now-100000,
  57. "bar.png" => $now-100000,
  58. }, "%pagemtime loaded correctly");
  59. is_deeply(\%renderedfiles, {
  60. Foo => ["Foo.html"],
  61. bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
  62. "bar.png" => ["bar.png"],
  63. }, "%renderedfiles loaded correctly");
  64. is_deeply(\%oldrenderedfiles, {
  65. Foo => ["Foo.html"],
  66. bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
  67. "bar.png" => ["bar.png"],
  68. }, "%oldrenderedfiles loaded correctly");
  69. is_deeply(\%links, {
  70. Foo => ["bar.png"],
  71. bar => ["Foo", "new-page"],
  72. "bar.png" => [],
  73. }, "%links loaded correctly");
  74. is_deeply(\%depends, {
  75. Foo => "",
  76. bar => "foo*",
  77. "bar.png" => "",
  78. }, "%depends loaded correctly");
  79. is_deeply(\%pagestate, {
  80. bar => {
  81. meta => {
  82. title => "a page about bar",
  83. moo => "mooooo",
  84. },
  85. },
  86. }, "%pagestate loaded correctly");
  87. is_deeply(\%pagecase, {
  88. foo => "Foo",
  89. bar => "bar",
  90. "bar.png" => "bar.png"
  91. }, "%pagecase generated correctly");
  92. is_deeply(\%destsources, {
  93. "Foo.html" => "Foo",
  94. "bar.html" => "bar",
  95. "bar.rss" => "bar",
  96. "sparkline-foo.gif" => "bar",
  97. "bar.png" => "bar.png",
  98. }, "%destsources generated correctly");
  99. # Clear state.
  100. %oldrenderedfiles=%pagectime=();
  101. %pagesources=%pagemtime=%oldlinks=%links=%depends=
  102. %destsources=%renderedfiles=%pagecase=%pagestate=();
  103. # When state is loaded for a wiki rebuild, only ctime and oldrenderedfiles
  104. # are retained.
  105. $config{rebuild}=1;
  106. ok(loadindex(), "load index");
  107. is_deeply(\%pagesources, {
  108. }, "%pagesources loaded correctly");
  109. is_deeply(\%pagemtime, {
  110. }, "%pagemtime loaded correctly");
  111. is_deeply(\%pagectime, {
  112. Foo => $now,
  113. bar => $now-100000,
  114. "bar.png" => $now-100000,
  115. }, "%pagemtime loaded correctly");
  116. is_deeply(\%renderedfiles, {
  117. }, "%renderedfiles loaded correctly");
  118. is_deeply(\%oldrenderedfiles, {
  119. Foo => ["Foo.html"],
  120. bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
  121. "bar.png" => ["bar.png"],
  122. }, "%oldrenderedfiles loaded correctly");
  123. is_deeply(\%links, {
  124. }, "%links loaded correctly");
  125. is_deeply(\%depends, {
  126. }, "%depends loaded correctly");
  127. is_deeply(\%pagestate, {
  128. }, "%pagestate loaded correctly");
  129. is_deeply(\%pagecase, {
  130. }, "%pagecase generated correctly");
  131. is_deeply(\%destsources, {
  132. }, "%destsources generated correctly");
  133. system "rm -rf $config{wikistatedir}";