summaryrefslogtreecommitdiff
path: root/t/renamepage.t
blob: ccb33d817827e91e17c6991e308bf3142838ccda (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 15;
  5. use Encode;
  6. BEGIN { use_ok("IkiWiki"); }
  7. BEGIN { use_ok("IkiWiki::Plugin::link"); }
  8. %config=IkiWiki::defaultconfig();
  9. $config{srcdir}=$config{destdir}="/dev/null";
  10. IkiWiki::checkconfig();
  11. # tests of the link plugin's renamepage function
  12. sub try {
  13. my ($page, $oldpage, $newpage, $content)=@_;
  14. %IkiWiki::pagecase=();
  15. %links=();
  16. $IkiWiki::config{userdir}="foouserdir";
  17. foreach my $page ($page, $oldpage, $newpage) {
  18. $IkiWiki::pagecase{lc $page}=$page;
  19. $links{$page}=[];
  20. }
  21. IkiWiki::Plugin::link::renamepage(
  22. page => $page,
  23. oldpage => $oldpage,
  24. newpage => $newpage,
  25. content => $content,
  26. );
  27. }
  28. is(try("z", "foo" => "bar", "[[xxx]]"), "[[xxx]]"); # unrelated link
  29. is(try("z", "foo" => "bar", "[[bar]]"), "[[bar]]"); # link already to new page
  30. is(try("z", "foo" => "bar", "[[foo]]"), "[[bar]]"); # basic conversion to new page name
  31. is(try("z", "foo" => "bar", "[[/foo]]"), "[[/bar]]"); # absolute link
  32. is(try("z", "foo" => "bar", "[[Foo]]"), "[[Bar]]"); # preserve case
  33. is(try("z", "x/foo" => "x/bar", "[[x/Foo]]"), "[[x/Bar]]"); # preserve case of subpage
  34. is(try("z", "foo" => "bar", "[[/Foo]]"), "[[/Bar]]"); # preserve case w/absolute
  35. is(try("z", "foo" => "bar", "[[foo]] [[xxx]]"), "[[bar]] [[xxx]]"); # 2 links, 1 converted
  36. is(try("z", "foo" => "bar", "[[xxx|foo]]"), "[[xxx|bar]]"); # conversion w/text
  37. is(try("z", "foo" => "bar", "[[foo#anchor]]"), "[[bar#anchor]]"); # with anchor
  38. is(try("z", "foo" => "bar", "[[xxx|foo#anchor]]"), "[[xxx|bar#anchor]]"); # with anchor
  39. is(try("z", "foo" => "bar", "[[!moo ]]"), "[[!moo ]]"); # preprocessor directive unchanged
  40. is(try("bugs", "bugs/foo" => "wishlist/bar", "[[foo]]"), "[[wishlist/bar]]"); # subpage link