]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/color.t
reply to question about new plugin
[git.ikiwiki.info.git] / t / color.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More;
5 use Encode;
7 BEGIN { use_ok("IkiWiki"); }
8 BEGIN { use_ok("IkiWiki::Render"); }
10 %config=IkiWiki::defaultconfig();
11 $config{srcdir}=$config{destdir}="/dev/null";
13 my $installed = $ENV{INSTALLED_TESTS};
15 unless ($installed) {
16         $config{templatedir} = "templates";
17         $config{underlaydir} = "underlays/basewiki";
18         $config{underlaydirbase} = "underlays";
19 }
21 sub render {
22         my $content = shift;
23         $IkiWiki::pagesources{foo} = "foo.mdwn";
24         $IkiWiki::pagemtime{foo} = 42;
25         $IkiWiki::pagectime{foo} = 42;
26         $content = IkiWiki::filter("foo", "foo", $content);
27         $content = IkiWiki::preprocess("foo", "foo", $content);
28         $content = IkiWiki::linkify("foo", "foo", $content);
29         $content = IkiWiki::htmlize("foo", "foo", "mdwn", $content);
30         $content = IkiWiki::genpage("foo", $content);
31         return $content;
32 }
34 foreach my $scrub (0, 1) {
35         if ($scrub) {
36                 $config{add_plugins}=[qw(color htmlscrubber toc)];
37         }
38         else {
39                 $config{add_plugins}=[qw(color toc)];
40         }
42         IkiWiki::loadplugins();
43         IkiWiki::checkconfig();
45         like(render('[[!color foreground="fuchsia" background="lime" text="Alert"]]'),
46                 qr{(?s)<span class="color" style="color: fuchsia; background-color: lime">Alert</span>});
47         like(render('[[!color foreground="#336699" text="Hello"]]'),
48                 qr{(?s)<span class="color" style="color: \#336699">Hello</span>});
49         like(render('[[!color background="#123" text="[Over there](http://localhost/)"]]'),
50                 qr{(?s)<span class="color" style="background-color: \#123"><a href="http://localhost/">Over there</a></span>});
51         like(render('[[!color background="censored()" text="Hi"]]'),
52                 qr{(?s)<span class="color" style="">Hi</span>});
53         like(render('[[!color foreground="x; pwned: exploit" text="Hi"]]'),
54                 qr{(?s)<span class="color" style="">Hi</span>});
56         like(render("[[!toc ]]\n\n## [[!color foreground=red text=Important]]"),
57                 qr{<a href="\#index1h2">Important</a>});
58 }
60 done_testing();