summaryrefslogtreecommitdiff
path: root/t/urlto.t
blob: 338632e9450399a02a2fa416f0746996e33d80ad (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 26;
  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. is(IkiWiki::urlto('', undef, 1), "http://smcv.example.co.uk/");
  19. # "local" (absolute path within site) version (default for cgiurl)
  20. is(IkiWiki::cgiurl(), "/cgi-bin/ikiwiki.cgi");
  21. is(IkiWiki::cgiurl(do => 'badger'), "/cgi-bin/ikiwiki.cgi?do=badger");
  22. is(IkiWiki::baseurl(undef), "/");
  23. is(IkiWiki::urlto('index', undef), "/");
  24. is(IkiWiki::urlto('index'), "/");
  25. is(IkiWiki::urlto('stoats', undef), "/stoats/");
  26. is(IkiWiki::urlto('stoats'), "/stoats/");
  27. is(IkiWiki::urlto(''), "/");
  28. # fully-relative version (default for urlto and baseurl)
  29. is(IkiWiki::baseurl('badger/mushroom'), "../../");
  30. is(IkiWiki::urlto('badger/mushroom', 'snake'), "../badger/mushroom/");
  31. is(IkiWiki::urlto('', 'snake'), "../");
  32. is(IkiWiki::urlto('', 'penguin/herring'), "../../");
  33. # explicit cgiurl override
  34. is(IkiWiki::cgiurl(cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki");
  35. is(IkiWiki::cgiurl(do => 'badger', cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki?do=badger");
  36. # with url and cgiurl on different sites, "local" degrades to absolute
  37. $IkiWiki::config{url} = "http://example.co.uk/~smcv";
  38. $IkiWiki::config{cgiurl} = "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi";
  39. is(IkiWiki::checkconfig(), 1);
  40. is(IkiWiki::cgiurl(), "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi");
  41. is(IkiWiki::baseurl(undef), "http://example.co.uk/~smcv/");
  42. is(IkiWiki::urlto('stoats', undef), "http://example.co.uk/~smcv/stoats/");
  43. is(IkiWiki::urlto('', undef), "http://example.co.uk/~smcv/");