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