]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
extend the 'tag' test to cover auto-creation of tag pages
authorSimon McVittie <smcv@debian.org>
Sat, 25 Dec 2010 22:53:57 +0000 (22:53 +0000)
committerSimon McVittie <smcv@debian.org>
Sat, 25 Dec 2010 22:54:54 +0000 (22:54 +0000)
.gitignore
t/tag.t

index e9ab152b6413d20385e317c7020406b01268f607..6b7efe5c150a177fcd9c4bc5e5c297e48771078e 100644 (file)
@@ -16,3 +16,4 @@ po/underlays/basewiki/*/*/*.mdwn
 po/underlays/directives/ikiwiki/directive/*.mdwn
 po/underlays_copy_stamp
 underlays/locale
 po/underlays/directives/ikiwiki/directive/*.mdwn
 po/underlays_copy_stamp
 underlays/locale
+/t/tmp/
diff --git a/t/tag.t b/t/tag.t
index fe547d85bc51eaa306d85b90e28d79d4793f8a4e..ec17d543418e4bb0bcc00fd81aa4ceb22d0f74a7 100755 (executable)
--- a/t/tag.t
+++ b/t/tag.t
@@ -3,15 +3,30 @@ package IkiWiki;
 
 use warnings;
 use strict;
 
 use warnings;
 use strict;
-use Test::More tests => 7;
+use Test::More tests => 21;
 
 BEGIN { use_ok("IkiWiki"); }
 
 BEGIN { use_ok("IkiWiki"); }
+BEGIN { use_ok("IkiWiki::Render"); }
+BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
 BEGIN { use_ok("IkiWiki::Plugin::tag"); }
 
 ok(! system("rm -rf t/tmp; mkdir t/tmp"));
 
 BEGIN { use_ok("IkiWiki::Plugin::tag"); }
 
 ok(! system("rm -rf t/tmp; mkdir t/tmp"));
 
+$config{verbose} = 1;
+$config{srcdir} = 't/tmp';
+$config{underlaydir} = 't/tmp';
+$config{templatedir} = 'templates';
+$config{usedirs} = 1;
+$config{htmlext} = 'html';
+$config{wiki_file_chars} = "-[:alnum:]+/.:_";
 $config{userdir} = "users";
 $config{tagbase} = "tags";
 $config{userdir} = "users";
 $config{tagbase} = "tags";
+$config{tag_autocreate} = 1;
+$config{default_pageext} = "mdwn";
+$config{wiki_file_prune_regexps} = [qr/^\./];
+$config{underlaydirbase} = '.';
+
+is(checkconfig(), 1);
 
 %oldrenderedfiles=%pagectime=();
 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
 
 %oldrenderedfiles=%pagectime=();
 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
@@ -20,6 +35,7 @@ $config{tagbase} = "tags";
 foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) {
        $pagesources{$page} = "$page.mdwn";
        $pagemtime{$page} = $pagectime{$page} = 1000000;
 foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) {
        $pagesources{$page} = "$page.mdwn";
        $pagemtime{$page} = $pagectime{$page} = 1000000;
+       writefile("$page.mdwn", "t/tmp", "your ad here");
 }
 
 $links{one}=[qw(tags/numbers alpha tags/letters)];
 }
 
 $links{one}=[qw(tags/numbers alpha tags/letters)];
@@ -36,4 +52,31 @@ ok(!pagespec_match("two", "tagged(alpha)"));
 ok(pagespec_match("one", "link(tags/numbers)"));
 ok(pagespec_match("one", "link(alpha)"));
 
 ok(pagespec_match("one", "link(tags/numbers)"));
 ok(pagespec_match("one", "link(alpha)"));
 
+# emulate preprocessing [[!tag numbers primes lucky]] on page "seven", causing
+# the "numbers" and "primes" tag pages to be auto-created
+IkiWiki::Plugin::tag::preprocess_tag(page => "seven", numbers => undef, primes => undef, lucky => undef);
+is($autofiles{"tags/lucky.mdwn"}{plugin}, "tag");
+is($autofiles{"tags/numbers.mdwn"}{plugin}, "tag");
+is($autofiles{"tags/primes.mdwn"}{plugin}, "tag");
+
+ok(!-e "t/tmp/tags/lucky.mdwn");
+my (%pages, @del);
+IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del);
+is_deeply(\%pages, {"t/tmp/tags/lucky" => 1}) || diag explain \%pages;
+is_deeply(\@del, []) || diag explain \@del;
+ok(-s "t/tmp/tags/lucky.mdwn");
+
+# generating an autofile that already exists does nothing
+%pages = @del = ();
+IkiWiki::gen_autofile("tags/numbers.mdwn", \%pages, \@del);
+is_deeply(\%pages, {}) || diag explain \%pages;
+is_deeply(\@del, []) || diag explain \@del;
+
+# generating an autofile that we just deleted does nothing
+%pages = ();
+@del = ('tags/primes.mdwn');
+IkiWiki::gen_autofile("tags/primes.mdwn", \%pages, \@del);
+is_deeply(\%pages, {}) || diag explain \%pages;
+is_deeply(\@del, ['tags/primes.mdwn']) || diag explain \@del;
+
 1;
 1;