2008-07-14 20:56:51 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# -*- cperl-indent-level: 8; -*-
|
2008-07-15 16:25:39 +02:00
|
|
|
# Testcases for the Ikiwiki parentlinks plugin.
|
2008-07-14 20:56:51 +02:00
|
|
|
|
|
|
|
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";
|
2008-07-15 16:25:39 +02:00
|
|
|
$config{templatedir}="t/parentlinks/templates";
|
2008-07-14 20:56:51 +02:00
|
|
|
IkiWiki::loadplugins();
|
|
|
|
IkiWiki::checkconfig();
|
|
|
|
|
|
|
|
# Test data
|
2008-07-15 16:25:39 +02:00
|
|
|
$expected{'parentlinks'} =
|
2008-07-14 20:56:51 +02:00
|
|
|
{
|
|
|
|
"ikiwiki" => [],
|
2008-07-15 12:35:12 +02:00
|
|
|
"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, },
|
|
|
|
],
|
2008-07-14 20:56:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# Test function
|
|
|
|
sub test_loop($$) {
|
|
|
|
my $loop=shift;
|
|
|
|
my $expected=shift;
|
|
|
|
my $template;
|
|
|
|
my %params;
|
|
|
|
|
2008-07-15 16:25:39 +02:00
|
|
|
ok($template=template('parentlinks.tmpl'), "template created");
|
2008-07-14 20:56:51 +02:00
|
|
|
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();
|
2008-07-15 16:25:39 +02:00
|
|
|
IkiWiki::Plugin::parentlinks::pagetemplate(%params);
|
2008-07-14 20:56:51 +02:00
|
|
|
my $res=$template->param($loop);
|
|
|
|
|
2008-07-15 12:35:12 +02:00
|
|
|
is(scalar(@$res), $pagedepth, "$msgprefix: path length");
|
2008-07-14 20:56:51 +02:00
|
|
|
# logic & arithmetic validation tests
|
2008-07-15 12:35:12 +02:00
|
|
|
for (my $i=0; $i<$pagedepth; $i++) {
|
2008-07-14 20:56:51 +02:00
|
|
|
my $r=$res->[$i];
|
2008-07-15 12:35:12 +02:00
|
|
|
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");
|
2008-07-14 20:56:51 +02:00
|
|
|
}
|
|
|
|
# comparison tests, iff the test-suite has been written
|
2008-07-15 12:35:12 +02:00
|
|
|
if (scalar(@$exp) eq $pagedepth) {
|
|
|
|
for (my $i=0; $i<$pagedepth; $i++) {
|
2008-07-14 20:56:51 +02:00
|
|
|
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
|
2008-07-15 16:25:39 +02:00
|
|
|
test_loop('parentlinks', $expected{'parentlinks'});
|