summaryrefslogtreecommitdiff
path: root/t/renamepage.t
blob: ce62bf468a0b3b498f5b01c953cba9c38ded9caf (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 11;
  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]] [[xxx]]"), "[[bar]] [[xxx]]"); # 2 links, 1 converted
  33. is(try("z", "foo" => "bar", "[[xxx|foo]]"), "[[xxx|bar]]"); # conversion w/text
  34. is(try("z", "foo" => "bar", "[[foo#anchor]]"), "[[bar#anchor]]"); # with anchor
  35. is(try("z", "foo" => "bar", "[[xxx|foo#anchor]]"), "[[xxx|bar#anchor]]"); # with anchor
  36. is(try("z", "foo" => "bar", "[[!moo ]]"), "[[!moo ]]"); # preprocessor directive unchanged
  37. is(try("bugs", "bugs/foo" => "wishlist/bar", "[[foo]]"), "[[wishlist/bar]]"); # subpage link