2 # -*- cperl-indent-level: 8; -*-
3 # Testcases for the Ikiwiki parentlinks plugin.
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'} =
26 [ {depth => 0, height => 2, },
27 {depth => 1, height => 1, },
29 "ikiwiki/pagespec/attachment" =>
30 [ {depth => 0, height => 3, depth_0 => 1, height_3 => 1},
31 {depth => 1, height => 2, },
32 {depth => 2, height => 1, },
43 ok($template=template('parentlinks.tmpl'), "template created");
44 ok($params{template}=$template, "params populated");
46 while ((my $page, my $exp) = each %{$expected}) {
47 my @path=(split("/", $page));
49 my $msgprefix="$page $loop";
51 # manually run the plugin hook
53 $template->clear_params();
54 IkiWiki::Plugin::parentlinks::pagetemplate(%params);
55 my $res=$template->param($loop);
57 is(scalar(@$res), $pagedepth, "$msgprefix: path length");
58 # logic & arithmetic validation tests
59 for (my $i=0; $i<$pagedepth; $i++) {
61 is($r->{height}, $pagedepth - $r->{depth},
62 "$msgprefix\[$i\]: height = pagedepth - depth");
63 ok($r->{depth} ge 0, "$msgprefix\[$i\]: depth>=0");
64 ok($r->{height} ge 0, "$msgprefix\[$i\]: height>=0");
66 # comparison tests, iff the test-suite has been written
67 if (scalar(@$exp) eq $pagedepth) {
68 for (my $i=0; $i<$pagedepth; $i++) {
71 map { is($r->{$_}, $e->{$_}, "$msgprefix\[$i\]: $_"); } keys %$e;
75 # diag("Testsuite is incomplete for ($page,$loop); cannot run comparison tests.");
81 test_loop('parentlinks', $expected{'parentlinks'});