2 # -*- cperl-indent-level: 8; -*-
3 # Testcases for the Ikiwiki pedigree plugin.
7 use Test::More 'no_plan';
11 BEGIN { use_ok("IkiWiki"); }
14 %config=IkiWiki::defaultconfig();
15 $config{srcdir}=$config{destdir}="/dev/null";
16 $config{underlaydir}="underlays/basewiki";
17 $config{templatedir}="t/pedigree/templates";
18 IkiWiki::loadplugins();
19 IkiWiki::checkconfig();
20 ok(IkiWiki::loadplugin("pedigree"), "pedigree plugin loaded");
23 $expected{'pedigree'} =
27 "ikiwiki/pagespec" => [
31 is_second_ancestor => '',
38 is_second_ancestor => 1,
39 is_grand_mother => '',
43 "ikiwiki/pagespec/attachment" => [
47 is_second_ancestor => '',
48 is_grand_mother => '',
54 is_second_ancestor => 1,
61 is_second_ancestor => '',
62 is_grand_mother => '',
68 $expected{'pedigree_but_root'} =
72 "ikiwiki/pagespec" => [],
73 "ikiwiki/pagespec/attachment" => [],
76 $expected{'pedigree_but_two_oldest'} =
80 "ikiwiki/pagespec" => [],
81 "ikiwiki/pagespec/attachment" => [],
92 if ($loop eq 'pedigree') {
94 } elsif ($loop eq 'pedigree_but_root') {
96 } elsif ($loop eq 'pedigree_but_two_oldest') {
100 ok($template=template('pedigree.tmpl'), "template created");
101 ok($params{template}=$template, "params populated");
103 while ((my $page, my $exp) = each %{$expected}) {
104 my @path=(split("/", $page));
107 if (($pagedepth - $offset) >= 0) {
108 $expdepth=$pagedepth - $offset;
112 my $msgprefix="$page $loop";
114 # manually run the plugin hook
116 $template->clear_params();
117 IkiWiki::Plugin::pedigree::pagetemplate(%params);
118 my $res=$template->param($loop);
120 is(scalar(@$res), $expdepth, "$msgprefix: path length");
121 # logic & arithmetic validation tests
122 for (my $i=0; $i<$expdepth; $i++) {
124 is($r->{distance}, $pagedepth - $r->{absdepth},
125 "$msgprefix\[$i\]: distance = pagedepth - absdepth");
126 ok($r->{absdepth} ge 0, "$msgprefix\[$i\]: absdepth>=0");
127 ok($r->{distance} ge 0, "$msgprefix\[$i\]: distance>=0");
128 unless ($loop eq 'pedigree') {
129 ok($r->{reldepth} ge 0, "$msgprefix\[$i\]: reldepth>=0");
131 local $TODO = "Known bug" if
132 (($loop eq 'pedigree_but_root')
134 is($r->{reldepth} + $offset, $r->{absdepth},
135 "$msgprefix\[$i\]: reldepth+offset=absdepth");
139 # comparison tests, iff the test-suite has been written
140 if (scalar(@$exp) eq $expdepth) {
141 for (my $i=0; $i<$expdepth; $i++) {
144 map { is($r->{$_}, $e->{$_}, "$msgprefix\[$i\]: $_"); } keys %$e;
148 # diag("Testsuite is incomplete for ($page,$loop); cannot run comparison tests.");
155 test_loop($_, $expected{$_});
156 } ('pedigree', 'pedigree_but_root', 'pedigree_but_two_oldest');