aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2008-07-14 20:56:51 +0200
committerintrigeri <intrigeri@boum.org>2008-07-14 23:03:27 +0200
commit9b8ba60daccb186631e54c2f1af6a29701129bcb (patch)
treecce90f6d0a70d6f3be6fa1ba0b4943c8ee3d61bd /t
parentcff4201eed692a11412969a25da997279d01b0d6 (diff)
downloadikiwiki-9b8ba60daccb186631e54c2f1af6a29701129bcb.tar
ikiwiki-9b8ba60daccb186631e54c2f1af6a29701129bcb.tar.gz
added testsuite for the pedigree plugin
Signed-off-by: intrigeri <intrigeri@boum.org>
Diffstat (limited to 't')
-rwxr-xr-xt/pedigree.t156
-rw-r--r--t/pedigree/templates/pedigree.tmpl10
2 files changed, 166 insertions, 0 deletions
diff --git a/t/pedigree.t b/t/pedigree.t
new file mode 100755
index 000000000..aa78cbe67
--- /dev/null
+++ b/t/pedigree.t
@@ -0,0 +1,156 @@
+#!/usr/bin/perl
+# -*- cperl-indent-level: 8; -*-
+# Testcases for the Ikiwiki pedigree 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/pedigree/templates";
+IkiWiki::loadplugins();
+IkiWiki::checkconfig();
+ok(IkiWiki::loadplugin("pedigree"), "pedigree plugin loaded");
+
+# Test data
+$expected{'pedigree'} =
+ {
+ "" => [],
+ "ikiwiki" => [],
+ "ikiwiki/pagespec" => [
+ {absdepth => 0,
+ distance => 2,
+ is_root => 1,
+ is_second_ancestor => '',
+ is_grand_mother => 1,
+ is_mother => '',
+ },
+ {absdepth => 1,
+ distance => 1,
+ is_root => '',
+ is_second_ancestor => 1,
+ is_grand_mother => '',
+ is_mother => 1,
+ },
+ ],
+ "ikiwiki/pagespec/attachment" => [
+ {absdepth => 0,
+ distance => 3,
+ is_root => 1,
+ is_second_ancestor => '',
+ is_grand_mother => '',
+ is_mother => '',
+ },
+ {absdepth => 1,
+ distance => 2,
+ is_root => '',
+ is_second_ancestor => 1,
+ is_grand_mother => 1,
+ is_mother => '',
+ },
+ {absdepth => 2,
+ distance => 1,
+ is_root => '',
+ is_second_ancestor => '',
+ is_grand_mother => '',
+ is_mother => 1,
+ },
+ ],
+ };
+
+$expected{'pedigree_but_root'} =
+ {
+ "" => [],
+ "ikiwiki" => [],
+ "ikiwiki/pagespec" => [],
+ "ikiwiki/pagespec/attachment" => [],
+ };
+
+$expected{'pedigree_but_two_oldest'} =
+ {
+ "" => [],
+ "ikiwiki" => [],
+ "ikiwiki/pagespec" => [],
+ "ikiwiki/pagespec/attachment" => [],
+ };
+
+# Test function
+sub test_loop($$) {
+ my $loop=shift;
+ my $expected=shift;
+ my $template;
+ my %params;
+ my $offset;
+
+ if ($loop eq 'pedigree') {
+ $offset=0;
+ } elsif ($loop eq 'pedigree_but_root') {
+ $offset=1;
+ } elsif ($loop eq 'pedigree_but_two_oldest') {
+ $offset=2;
+ }
+
+ ok($template=template('pedigree.tmpl'), "template created");
+ ok($params{template}=$template, "params populated");
+
+ while ((my $page, my $exp) = each %{$expected}) {
+ my @path=(split("/", $page));
+ my $pagedepth=@path;
+ my $expdepth;
+ if (($pagedepth - $offset) >= 0) {
+ $expdepth=$pagedepth - $offset;
+ } else {
+ $expdepth=0;
+ }
+ my $msgprefix="$page $loop";
+
+ # manually run the plugin hook
+ $params{page}=$page;
+ $template->clear_params();
+ IkiWiki::Plugin::pedigree::pagetemplate(%params);
+ my $res=$template->param($loop);
+
+ is(scalar(@$res), $expdepth, "$msgprefix: path length");
+ # logic & arithmetic validation tests
+ for (my $i=0; $i<$expdepth; $i++) {
+ my $r=$res->[$i];
+ is($r->{distance}, $pagedepth - $r->{absdepth},
+ "$msgprefix\[$i\]: distance = pagedepth - absdepth");
+ ok($r->{absdepth} ge 0, "$msgprefix\[$i\]: absdepth>=0");
+ ok($r->{distance} ge 0, "$msgprefix\[$i\]: distance>=0");
+ unless ($loop eq 'pedigree') {
+ ok($r->{reldepth} ge 0, "$msgprefix\[$i\]: reldepth>=0");
+ TODO: {
+ local $TODO = "Known bug" if
+ (($loop eq 'pedigree_but_root')
+ && ($i >= $offset));
+ is($r->{reldepth} + $offset, $r->{absdepth},
+ "$msgprefix\[$i\]: reldepth+offset=absdepth");
+ }
+ }
+ }
+ # comparison tests, iff the test-suite has been written
+ if (scalar(@$exp) eq $expdepth) {
+ for (my $i=0; $i<$expdepth; $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
+map {
+ test_loop($_, $expected{$_});
+} ('pedigree', 'pedigree_but_root', 'pedigree_but_two_oldest');
diff --git a/t/pedigree/templates/pedigree.tmpl b/t/pedigree/templates/pedigree.tmpl
new file mode 100644
index 000000000..3590244ee
--- /dev/null
+++ b/t/pedigree/templates/pedigree.tmpl
@@ -0,0 +1,10 @@
+<!-- This template file only has to "use" the loops tested by pedigree.t -->
+
+<TMPL_LOOP NAME="PEDIGREE">
+</TMPL_LOOP>
+
+<TMPL_LOOP NAME="PEDIGREE_BUT_ROOT">
+</TMPL_LOOP>
+
+<TMPL_LOOP NAME="PEDIGREE_BUT_TWO_OLDEST">
+</TMPL_LOOP>