From: Simon McVittie Date: Sat, 2 Oct 2010 13:50:16 +0000 (+0100) Subject: Add a regression test for urlto, baseurl and cgiurl in relative/local/absolute modes X-Git-Tag: 3.20101231~106^2~8 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/70bdd57899294fffd30077b7518ba23710c9d55b?hp=4c224ae143ebc4b13f824fe1782561a5cd165864 Add a regression test for urlto, baseurl and cgiurl in relative/local/absolute modes --- diff --git a/t/urlto.t b/t/urlto.t new file mode 100755 index 000000000..a0b3baa45 --- /dev/null +++ b/t/urlto.t @@ -0,0 +1,44 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 19; + +BEGIN { use_ok("IkiWiki"); } + +$IkiWiki::config{srcdir} = '/does/not/exist/'; +$IkiWiki::config{usedirs} = 1; +$IkiWiki::config{htmlext} = "HTML"; +$IkiWiki::config{wiki_file_chars} = "A-Za-z0-9._"; + +$IkiWiki::config{url} = "http://smcv.example.co.uk"; +$IkiWiki::config{cgiurl} = "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi"; +is(IkiWiki::checkconfig(), 1); + +# absolute version +is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}), "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi"); +is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}, do => 'badger'), "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi?do=badger"); +is(IkiWiki::urlto('index', undef, 1), "http://smcv.example.co.uk/"); +is(IkiWiki::urlto('stoats', undef, 1), "http://smcv.example.co.uk/stoats/"); + +# "local" (absolute path within site) version (default for cgiurl) +is(IkiWiki::cgiurl(), "/cgi-bin/ikiwiki.cgi"); +is(IkiWiki::cgiurl(do => 'badger'), "/cgi-bin/ikiwiki.cgi?do=badger"); +is(IkiWiki::baseurl(undef), "/"); +is(IkiWiki::urlto('index', undef), "/"); +is(IkiWiki::urlto('stoats', undef), "/stoats/"); + +# fully-relative version (default for urlto and baseurl) +is(IkiWiki::baseurl('badger/mushroom'), "../../"); +is(IkiWiki::urlto('badger/mushroom', 'snake'), "../badger/mushroom/"); + +# explicit cgiurl override +is(IkiWiki::cgiurl(cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki"); +is(IkiWiki::cgiurl(do => 'badger', cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki?do=badger"); + +# with url and cgiurl on different sites, "local" degrades to absolute +$IkiWiki::config{url} = "http://example.co.uk/~smcv"; +$IkiWiki::config{cgiurl} = "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi"; +is(IkiWiki::checkconfig(), 1); +is(IkiWiki::cgiurl(), "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi"); +is(IkiWiki::baseurl(undef), "http://example.co.uk/~smcv/"); +is(IkiWiki::urlto('stoats', undef), "http://example.co.uk/~smcv/stoats/");