]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/tag.t
+1
[git.ikiwiki.info.git] / t / tag.t
1 #!/usr/bin/perl
2 package IkiWiki;
4 use warnings;
5 use strict;
6 use Test::More;
8 BEGIN { use_ok("IkiWiki"); }
9 BEGIN { use_ok("IkiWiki::Render"); }
10 BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
11 BEGIN { use_ok("IkiWiki::Plugin::tag"); }
13 ok(! system("rm -rf t/tmp; mkdir t/tmp"));
15 $config{srcdir} = 't/tmp';
16 $config{underlaydir} = 't/tmp';
17 $config{templatedir} = 'templates';
18 $config{usedirs} = 1;
19 $config{htmlext} = 'html';
20 $config{wiki_file_chars} = "-[:alnum:]+/.:_";
21 $config{userdir} = "users";
22 $config{tagbase} = "tags";
23 $config{tag_autocreate} = 1;
24 $config{tag_autocreate_commit} = 0;
25 $config{default_pageext} = "mdwn";
26 $config{wiki_file_prune_regexps} = [qr/^\./];
27 $config{underlaydirbase} = '.';
29 is(checkconfig(), 1);
31 %oldrenderedfiles=%pagectime=();
32 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
33 %destsources=%renderedfiles=%pagecase=%pagestate=();
35 foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) {
36         $pagesources{$page} = "$page.mdwn";
37         $pagemtime{$page} = $pagectime{$page} = 1000000;
38         writefile("$page.mdwn", "t/tmp", "your ad here");
39 }
41 $links{one}=[qw(tags/numbers alpha tags/letters)];
42 $links{two}=[qw(tags/numbers)];
43 $links{alpha}=[qw(tags/letters one)];
44 $links{beta}=[qw(tags/letters)];
45 $typedlinks{one}={tag => {"tags/numbers" => 1 }};
46 $typedlinks{two}={tag => {"tags/numbers" => 1 }};
47 $typedlinks{alpha}={tag => {"tags/letters" => 1 }};
48 $typedlinks{beta}={tag => {"tags/letters" => 1 }};
50 ok(pagespec_match("one", "tagged(numbers)"));
51 ok(!pagespec_match("two", "tagged(alpha)"));
52 ok(pagespec_match("one", "link(tags/numbers)"));
53 ok(pagespec_match("one", "link(alpha)"));
55 # emulate preprocessing [[!tag numbers primes lucky]] on page "seven", causing
56 # the "numbers" and "primes" tag pages to be auto-created
57 IkiWiki::Plugin::tag::preprocess_tag(page => "seven", numbers => undef, primes => undef, lucky => undef);
58 is($autofiles{"tags/lucky.mdwn"}{plugin}, "tag");
59 is($autofiles{"tags/numbers.mdwn"}{plugin}, "tag");
60 is($autofiles{"tags/primes.mdwn"}{plugin}, "tag");
61 is_deeply([sort keys %autofiles], [qw(tags/lucky.mdwn tags/numbers.mdwn tags/primes.mdwn)]);
63 ok(!-e "t/tmp/tags/lucky.mdwn");
64 my (%pages, @del);
65 IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del);
66 ok(! -s "t/tmp/tags/lucky.mdwn");
67 ok(-s "t/tmp/.ikiwiki/transient/tags/lucky.mdwn");
68 is_deeply(\%pages, {"t/tmp/tags/lucky" => 1});
69 is_deeply(\@del, []);
71 # generating an autofile that already exists does nothing
72 %pages = @del = ();
73 IkiWiki::gen_autofile("tags/numbers.mdwn", \%pages, \@del);
74 is_deeply(\%pages, {});
75 is_deeply(\@del, []);
77 # generating an autofile that we just deleted does nothing
78 %pages = ();
79 @del = ('tags/primes.mdwn');
80 IkiWiki::gen_autofile("tags/primes.mdwn", \%pages, \@del);
81 is_deeply(\%pages, {});
82 is_deeply(\@del, ['tags/primes.mdwn']);
84 done_testing;