fixed
[ikiwiki.git] / t / renamepage.t
bloba706cbb46a15466c0adf9e579a0aeabf12f01ec6
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 21;
5 use Encode;
7 BEGIN { use_ok("IkiWiki"); }
8 BEGIN { use_ok("IkiWiki::Plugin::link"); }
10 %config=IkiWiki::defaultconfig();
11 $config{srcdir}=$config{destdir}="/dev/null";
12 IkiWiki::checkconfig();
14 # tests of the link plugin's renamepage function
15 sub try {
16 my ($page, $oldpage, $newpage, $content)=@_;
18 %IkiWiki::pagecase=();
19 %links=();
20 $IkiWiki::config{userdir}="foouserdir";
21 foreach my $page ($page, $oldpage, $newpage) {
22 $IkiWiki::pagecase{lc $page}=$page;
23 $links{$page}=[];
26 IkiWiki::Plugin::link::renamepage(
27 page => $page,
28 oldpage => $oldpage,
29 newpage => $newpage,
30 content => $content,
33 is(try("z", "foo" => "bar", "[[xxx]]"), "[[xxx]]"); # unrelated link
34 is(try("z", "foo" => "bar", "[[bar]]"), "[[bar]]"); # link already to new page
35 is(try("z", "foo" => "bar", "[[foo]]"), "[[bar]]"); # basic conversion to new page name
36 is(try("z", "foo" => "bar", "[[/foo]]"), "[[/bar]]"); # absolute link
37 is(try("z", "foo" => "bar", "[[Foo]]"), "[[Bar]]"); # preserve case
38 is(try("z", "x/foo" => "x/bar", "[[x/Foo]]"), "[[x/Bar]]"); # preserve case of subpage
39 is(try("z", "foo" => "bar", "[[/Foo]]"), "[[/Bar]]"); # preserve case w/absolute
40 is(try("z", "foo" => "bar", "[[foo]] [[xxx]]"), "[[bar]] [[xxx]]"); # 2 links, 1 converted
41 is(try("z", "foo" => "bar", "[[xxx|foo]]"), "[[xxx|bar]]"); # conversion w/text
42 is(try("z", "foo" => "bar", "[[foo#anchor]]"), "[[bar#anchor]]"); # with anchor
43 is(try("z", "foo" => "bar", "[[xxx|foo#anchor]]"), "[[xxx|bar#anchor]]"); # with anchor
44 is(try("z", "foo" => "bar", "[[!moo ]]"), "[[!moo ]]"); # preprocessor directive unchanged
45 is(try("bugs", "bugs/foo" => "wishlist/bar", "[[foo]]"), "[[wishlist/bar]]"); # subpage link
46 is(try("z", "foo_bar" => "bar", "[[foo_bar]]"), "[[bar]]"); # old link with underscore
47 is(try("z", "foo" => "bar_foo", "[[foo]]"), "[[bar_foo]]"); # new link with underscore
48 is(try("z", "foo_bar" => "bar_foo", "[[foo_bar]]"), "[[bar_foo]]"); # both with underscore
49 is(try("z", "foo" => "bar__".ord("(")."__", "[[foo]]"), "[[bar(]]"); # new link with escaped chars
50 is(try("z", "foo__".ord("(")."__" => "bar(", "[[foo(]]"), "[[bar(]]"); # old link with escaped chars
51 is(try("z", "foo__".ord("(")."__" => "bar__".ord(")")."__", "[[foo(]]"), "[[bar)]]"); # both with escaped chars