2 # -*- cperl-indent-level: 8; -*-
3 # Testcases for the Ikiwiki parentlinks 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/parentlinks/templates";
18 IkiWiki::loadplugins();
19 IkiWiki::checkconfig();
22 $expected{'parentlinks'} =
27 [ {depth => 0, height => 2, },
28 {depth => 1, height => 1, },
30 "ikiwiki/pagespec/attachment" =>
31 [ {depth => 0, height => 3, depth_0 => 1, height_3 => 1},
32 {depth => 1, height => 2, },
33 {depth => 2, height => 1, },
44 ok($template=template('parentlinks.tmpl'), "template created");
45 ok($params{template}=$template, "params populated");
47 while ((my $page, my $exp) = each %{$expected}) {
48 my @path=(split("/", $page));
50 my $msgprefix="$page $loop";
52 # manually run the plugin hook
54 $template->clear_params();
55 IkiWiki::Plugin::parentlinks::pagetemplate(%params);
56 my $res=$template->param($loop);
58 is(scalar(@$res), $pagedepth, "$msgprefix: path length");
59 # logic & arithmetic validation tests
60 for (my $i=0; $i<$pagedepth; $i++) {
62 is($r->{height}, $pagedepth - $r->{depth},
63 "$msgprefix\[$i\]: height = pagedepth - depth");
64 ok($r->{depth} ge 0, "$msgprefix\[$i\]: depth>=0");
65 ok($r->{height} ge 0, "$msgprefix\[$i\]: height>=0");
67 # comparison tests, iff the test-suite has been written
68 if (scalar(@$exp) eq $pagedepth) {
69 for (my $i=0; $i<$pagedepth; $i++) {
72 map { is($r->{$_}, $e->{$_}, "$msgprefix\[$i\]: $_"); } keys %$e;
76 # diag("Testsuite is incomplete for ($page,$loop); cannot run comparison tests.");
82 test_loop('parentlinks', $expected{'parentlinks'});