9 unless (eval { require XML::Twig }) {
11 use Test::More skip_all => "XML::Twig is not available"
16 BEGIN { use_ok("IkiWiki"); }
17 BEGIN { use_ok("IkiWiki::Render"); }
18 BEGIN { use_ok("IkiWiki::Plugin::map"); }
19 BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
21 ok(! system("rm -rf t/tmp; mkdir t/tmp"));
24 $config{srcdir} = 't/tmp';
25 $config{underlaydir} = 't/tmp';
26 $config{underlaydirbase} = '.';
27 $config{templatedir} = 'templates';
29 $config{htmlext} = 'html';
30 $config{wiki_file_chars} = "-[:alnum:]+/.:_";
31 $config{userdir} = "users";
32 $config{tagbase} = "tags";
33 $config{default_pageext} = "mdwn";
34 $config{wiki_file_prune_regexps} = [qr/^\./];
35 $config{autoindex_commit} = 0;
39 %oldrenderedfiles=%pagectime=();
40 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
41 %destsources=%renderedfiles=%pagecase=%pagestate=();
57 foreach my $page (@pages) {
58 # we use a non-default extension for these, so they're distinguishable
59 # from programmatically-created pages
60 $pagesources{$page} = "$page.mdwn";
61 $destsources{$page} = "$page.mdwn";
62 $pagemtime{$page} = $pagectime{$page} = 1000000;
63 writefile("$page.mdwn", "t/tmp", "your ad here");
77 return { %stuff, name => $name, kids => $kids };
86 # expected is a list of hashes
88 foreach my $li ($ul->children) {
89 my @kids = $li->children;
93 my $expectation = shift @$expected;
95 is($kids[0]->tag, 'a');
98 if ($expectation->{parent}) {
99 is($a->att('class'), 'mapparent');
102 is($a->att('class'), 'mapitem');
105 is_deeply([$a->text], [$expectation->{name}]);
107 if (@{$expectation->{kids}}) {
110 check_nodes($kids[1], $expectation->{kids});
113 is_deeply([@kids], [$a]);
119 my $pagespec = shift;
120 my $expected = shift;
121 comment("*** $pagespec ***\n");
123 my $html = IkiWiki::Plugin::map::preprocess(pages => $pagespec,
127 my $tree = XML::Twig->new(pretty_print => 'indented');
132 print "malformed XML: $@\n$html\n";
135 my $fragment = $tree->root;
137 is($fragment->tag, 'div');
138 is($fragment->att('class'), 'map');
141 check_nodes(($fragment->children)[0], $expected);
144 ok(! $fragment->children);
150 check('doesnotexist', []);
152 check('alpha', [node('alpha', [])]);
169 check('alpha or alpha/*',
186 check('alpha or alpha/1 or beta',
194 check('alpha/1 or beta',
202 check('alpha/1/i* or alpha/2/a or beta',
218 check('alpha/1/i* or alpha/2/a',