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'} =
28 [ {depth => 0, height => 2, },
29 {depth => 1, height => 1, },
31 "ikiwiki/pagespec/attachment" =>
32 [ {depth => 0, height => 3, depth_0 => 1, height_3 => 1},
33 {depth => 1, height => 2, },
34 {depth => 2, height => 1, },
45 ok($template=template('pedigree.tmpl'), "template created");
46 ok($params{template}=$template, "params populated");
48 while ((my $page, my $exp) = each %{$expected}) {
49 my @path=(split("/", $page));
51 my $msgprefix="$page $loop";
53 # manually run the plugin hook
55 $template->clear_params();
56 IkiWiki::Plugin::pedigree::pagetemplate(%params);
57 my $res=$template->param($loop);
59 is(scalar(@$res), $pagedepth, "$msgprefix: path length");
60 # logic & arithmetic validation tests
61 for (my $i=0; $i<$pagedepth; $i++) {
63 is($r->{height}, $pagedepth - $r->{depth},
64 "$msgprefix\[$i\]: height = pagedepth - depth");
65 ok($r->{depth} ge 0, "$msgprefix\[$i\]: depth>=0");
66 ok($r->{height} ge 0, "$msgprefix\[$i\]: height>=0");
68 # comparison tests, iff the test-suite has been written
69 if (scalar(@$exp) eq $pagedepth) {
70 for (my $i=0; $i<$pagedepth; $i++) {
73 map { is($r->{$_}, $e->{$_}, "$msgprefix\[$i\]: $_"); } keys %$e;
77 # diag("Testsuite is incomplete for ($page,$loop); cannot run comparison tests.");
83 test_loop('pedigree', $expected{'pedigree'});