summaryrefslogtreecommitdiff
path: root/t/index.t
blob: 392a167e9747131dbcd065b022a725ebf35f16d2 (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 => 31;
  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. $typedlinks{"bar"}={tag => {"Foo" => 1}};
  30. $links{"bar.png"}=[];
  31. $depends{"Foo"}={};
  32. $depends{"bar"}={"foo*" => 1};
  33. $depends{"bar.png"}={};
  34. $pagestate{"bar"}{meta}{title}="a page about bar";
  35. $pagestate{"bar"}{meta}{moo}="mooooo";
  36. # only loaded plugins save state, so this should not be saved out
  37. $pagestate{"bar"}{nosuchplugin}{moo}="mooooo";
  38. ok(saveindex(), "save index");
  39. ok(-s "$config{wikistatedir}/indexdb", "index file created");
  40. # Clear state.
  41. %oldrenderedfiles=%pagectime=();
  42. %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
  43. %destsources=%renderedfiles=%pagecase=%pagestate=();
  44. ok(loadindex(), "load index");
  45. is_deeply(\%pagesources, {
  46. Foo => "Foo.mdwn",
  47. bar => "bar.mdwn",
  48. "bar.png" => "bar.png",
  49. }, "%pagesources loaded correctly");
  50. is_deeply(\%pagemtime, {
  51. Foo => $now,
  52. bar => $now-1000,
  53. "bar.png" => $now,
  54. }, "%pagemtime loaded correctly");
  55. is_deeply(\%pagectime, {
  56. Foo => $now,
  57. bar => $now-100000,
  58. "bar.png" => $now-100000,
  59. }, "%pagemtime loaded correctly");
  60. is_deeply(\%renderedfiles, {
  61. Foo => ["Foo.html"],
  62. bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
  63. "bar.png" => ["bar.png"],
  64. }, "%renderedfiles loaded correctly");
  65. is_deeply(\%oldrenderedfiles, {
  66. Foo => ["Foo.html"],
  67. bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
  68. "bar.png" => ["bar.png"],
  69. }, "%oldrenderedfiles loaded correctly");
  70. is_deeply(\%links, {
  71. Foo => ["bar.png"],
  72. bar => ["Foo", "new-page"],
  73. "bar.png" => [],
  74. }, "%links loaded correctly");
  75. is_deeply(\%depends, {
  76. Foo => {},
  77. bar => {"foo*" => 1},
  78. "bar.png" => {},
  79. }, "%depends loaded correctly");
  80. is_deeply(\%pagestate, {
  81. bar => {
  82. meta => {
  83. title => "a page about bar",
  84. moo => "mooooo",
  85. },
  86. },
  87. }, "%pagestate loaded correctly");
  88. is_deeply(\%pagecase, {
  89. foo => "Foo",
  90. bar => "bar",
  91. "bar.png" => "bar.png"
  92. }, "%pagecase generated correctly");
  93. is_deeply(\%destsources, {
  94. "Foo.html" => "Foo",
  95. "bar.html" => "bar",
  96. "bar.rss" => "bar",
  97. "sparkline-foo.gif" => "bar",
  98. "bar.png" => "bar.png",
  99. }, "%destsources generated correctly");
  100. is_deeply(\%typedlinks, {
  101. bar => {tag => {"Foo" => 1}},
  102. }, "%typedlinks loaded correctly");
  103. is_deeply(\%oldtypedlinks, {
  104. bar => {tag => {"Foo" => 1}},
  105. }, "%oldtypedlinks loaded correctly");
  106. # Clear state.
  107. %oldrenderedfiles=%pagectime=();
  108. %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
  109. %destsources=%renderedfiles=%pagecase=%pagestate=();
  110. # When state is loaded for a wiki rebuild, only ctime, oldrenderedfiles,
  111. # and pagesources are retained.
  112. $config{rebuild}=1;
  113. ok(loadindex(), "load index");
  114. is_deeply(\%pagesources, {
  115. Foo => "Foo.mdwn",
  116. bar => "bar.mdwn",
  117. "bar.png" => "bar.png",
  118. }, "%pagesources loaded correctly");
  119. is_deeply(\%pagemtime, {
  120. }, "%pagemtime loaded correctly");
  121. is_deeply(\%pagectime, {
  122. Foo => $now,
  123. bar => $now-100000,
  124. "bar.png" => $now-100000,
  125. }, "%pagemtime loaded correctly");
  126. is_deeply(\%renderedfiles, {
  127. }, "%renderedfiles loaded correctly");
  128. is_deeply(\%oldrenderedfiles, {
  129. Foo => ["Foo.html"],
  130. bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
  131. "bar.png" => ["bar.png"],
  132. }, "%oldrenderedfiles loaded correctly");
  133. is_deeply(\%links, {
  134. }, "%links loaded correctly");
  135. is_deeply(\%depends, {
  136. }, "%depends loaded correctly");
  137. is_deeply(\%pagestate, {
  138. }, "%pagestate loaded correctly");
  139. is_deeply(\%pagecase, { # generated implicitly since pagesources is loaded
  140. foo => "Foo",
  141. bar => "bar",
  142. "bar.png" => "bar.png"
  143. }, "%pagecase generated correctly");
  144. is_deeply(\%destsources, {
  145. }, "%destsources generated correctly");
  146. is_deeply(\%typedlinks, {
  147. }, "%typedlinks cleared correctly");
  148. is_deeply(\%oldtypedlinks, {
  149. }, "%oldtypedlinks cleared correctly");
  150. system "rm -rf $config{wikistatedir}";