summaryrefslogtreecommitdiff
path: root/t/urlto.t
blob: 25445579248d2b8e94b4d1a7abf5460d992f084f (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 21;
  5. BEGIN { use_ok("IkiWiki"); }
  6. $IkiWiki::config{srcdir} = '/does/not/exist/';
  7. $IkiWiki::config{usedirs} = 1;
  8. $IkiWiki::config{htmlext} = "HTML";
  9. $IkiWiki::config{wiki_file_chars} = "A-Za-z0-9._";
  10. $IkiWiki::config{url} = "http://smcv.example.co.uk";
  11. $IkiWiki::config{cgiurl} = "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi";
  12. is(IkiWiki::checkconfig(), 1);
  13. # absolute version
  14. is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}), "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi");
  15. is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}, do => 'badger'), "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi?do=badger");
  16. is(IkiWiki::urlto('index', undef, 1), "http://smcv.example.co.uk/");
  17. is(IkiWiki::urlto('stoats', undef, 1), "http://smcv.example.co.uk/stoats/");
  18. # "local" (absolute path within site) version (default for cgiurl)
  19. is(IkiWiki::cgiurl(), "/cgi-bin/ikiwiki.cgi");
  20. is(IkiWiki::cgiurl(do => 'badger'), "/cgi-bin/ikiwiki.cgi?do=badger");
  21. is(IkiWiki::baseurl(undef), "/");
  22. is(IkiWiki::urlto('index', undef), "/");
  23. is(IkiWiki::urlto('index'), "/");
  24. is(IkiWiki::urlto('stoats', undef), "/stoats/");
  25. is(IkiWiki::urlto('stoats'), "/stoats/");
  26. # fully-relative version (default for urlto and baseurl)
  27. is(IkiWiki::baseurl('badger/mushroom'), "../../");
  28. is(IkiWiki::urlto('badger/mushroom', 'snake'), "../badger/mushroom/");
  29. # explicit cgiurl override
  30. is(IkiWiki::cgiurl(cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki");
  31. is(IkiWiki::cgiurl(do => 'badger', cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki?do=badger");
  32. # with url and cgiurl on different sites, "local" degrades to absolute
  33. $IkiWiki::config{url} = "http://example.co.uk/~smcv";
  34. $IkiWiki::config{cgiurl} = "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi";
  35. is(IkiWiki::checkconfig(), 1);
  36. is(IkiWiki::cgiurl(), "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi");
  37. is(IkiWiki::baseurl(undef), "http://example.co.uk/~smcv/");
  38. is(IkiWiki::urlto('stoats', undef), "http://example.co.uk/~smcv/stoats/");