diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-07-16 17:31:15 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-07-16 17:31:15 -0400 |
commit | 2c05a34be17c805d929f0ad563acf857eba1d46b (patch) | |
tree | 5466b9a35d4102b606dcb154186989c8857b1b4d /t | |
parent | 4ed0a630cb8a10d583c5e88cc7a87a5cecdedc8d (diff) | |
parent | 35668b87d3247a7de6c4dbb9edd7e0d909603524 (diff) | |
download | ikiwiki-2c05a34be17c805d929f0ad563acf857eba1d46b.tar ikiwiki-2c05a34be17c805d929f0ad563acf857eba1d46b.tar.gz |
Merge commit 'intrigeri/pedigree'
Diffstat (limited to 't')
-rwxr-xr-x | t/parentlinks.t | 82 | ||||
-rw-r--r-- | t/parentlinks/templates/parentlinks.tmpl | 4 |
2 files changed, 86 insertions, 0 deletions
diff --git a/t/parentlinks.t b/t/parentlinks.t new file mode 100755 index 000000000..593937a97 --- /dev/null +++ b/t/parentlinks.t @@ -0,0 +1,82 @@ +#!/usr/bin/perl +# -*- cperl-indent-level: 8; -*- +# Testcases for the Ikiwiki parentlinks plugin. + +use warnings; +use strict; +use Test::More 'no_plan'; + +my %expected; + +BEGIN { use_ok("IkiWiki"); } + +# Init +%config=IkiWiki::defaultconfig(); +$config{srcdir}=$config{destdir}="/dev/null"; +$config{underlaydir}="underlays/basewiki"; +$config{templatedir}="t/parentlinks/templates"; +IkiWiki::loadplugins(); +IkiWiki::checkconfig(); + +# Test data +$expected{'parentlinks'} = + { + "" => [], + "ikiwiki" => [], + "ikiwiki/pagespec" => + [ {depth => 0, height => 2, }, + {depth => 1, height => 1, }, + ], + "ikiwiki/pagespec/attachment" => + [ {depth => 0, height => 3, depth_0 => 1, height_3 => 1}, + {depth => 1, height => 2, }, + {depth => 2, height => 1, }, + ], + }; + +# Test function +sub test_loop($$) { + my $loop=shift; + my $expected=shift; + my $template; + my %params; + + ok($template=template('parentlinks.tmpl'), "template created"); + ok($params{template}=$template, "params populated"); + + while ((my $page, my $exp) = each %{$expected}) { + my @path=(split("/", $page)); + my $pagedepth=@path; + my $msgprefix="$page $loop"; + + # manually run the plugin hook + $params{page}=$page; + $template->clear_params(); + IkiWiki::Plugin::parentlinks::pagetemplate(%params); + my $res=$template->param($loop); + + is(scalar(@$res), $pagedepth, "$msgprefix: path length"); + # logic & arithmetic validation tests + for (my $i=0; $i<$pagedepth; $i++) { + my $r=$res->[$i]; + is($r->{height}, $pagedepth - $r->{depth}, + "$msgprefix\[$i\]: height = pagedepth - depth"); + ok($r->{depth} ge 0, "$msgprefix\[$i\]: depth>=0"); + ok($r->{height} ge 0, "$msgprefix\[$i\]: height>=0"); + } + # comparison tests, iff the test-suite has been written + if (scalar(@$exp) eq $pagedepth) { + for (my $i=0; $i<$pagedepth; $i++) { + my $e=$exp->[$i]; + my $r=$res->[$i]; + map { is($r->{$_}, $e->{$_}, "$msgprefix\[$i\]: $_"); } keys %$e; + } + } + # else { + # diag("Testsuite is incomplete for ($page,$loop); cannot run comparison tests."); + # } + } +} + +# Main +test_loop('parentlinks', $expected{'parentlinks'}); diff --git a/t/parentlinks/templates/parentlinks.tmpl b/t/parentlinks/templates/parentlinks.tmpl new file mode 100644 index 000000000..3ca3b0030 --- /dev/null +++ b/t/parentlinks/templates/parentlinks.tmpl @@ -0,0 +1,4 @@ +<!-- This template file only has to "use" the loops tested by parentlinks.t --> + +<TMPL_LOOP NAME="PARENTLINKS"> +</TMPL_LOOP> |