]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/urlto.t
po: report bug + test case + proposed fix
[git.ikiwiki.info.git] / t / urlto.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 31;
6 BEGIN { use_ok("IkiWiki"); }
8 $IkiWiki::config{srcdir} = '/does/not/exist/';
9 $IkiWiki::config{usedirs} = 1;
10 $IkiWiki::config{htmlext} = "HTML";
11 $IkiWiki::config{wiki_file_chars} = "A-Za-z0-9._";
13 $IkiWiki::config{url} = "http://smcv.example.co.uk";
14 $IkiWiki::config{cgiurl} = "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi";
15 is(IkiWiki::checkconfig(), 1);
17 # absolute version
18 is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}), "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi");
19 is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}, do => 'badger'), "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi?do=badger");
20 is(IkiWiki::urlto('index', undef, 1), "http://smcv.example.co.uk/");
21 is(IkiWiki::urlto('stoats', undef, 1), "http://smcv.example.co.uk/stoats/");
22 is(IkiWiki::urlto('', undef, 1), "http://smcv.example.co.uk/");
24 # "local" (absolute path within site) version (default for cgiurl)
25 is(IkiWiki::cgiurl(), "/cgi-bin/ikiwiki.cgi");
26 is(IkiWiki::cgiurl(do => 'badger'), "/cgi-bin/ikiwiki.cgi?do=badger");
27 is(IkiWiki::baseurl(undef), "/");
28 is(IkiWiki::urlto('index', undef), "/");
29 is(IkiWiki::urlto('index'), "/");
30 is(IkiWiki::urlto('stoats', undef), "/stoats/");
31 is(IkiWiki::urlto('stoats'), "/stoats/");
32 is(IkiWiki::urlto(''), "/");
34 # fully-relative version (default for urlto and baseurl)
35 is(IkiWiki::baseurl('badger/mushroom'), "../../");
36 is(IkiWiki::urlto('badger/mushroom', 'snake'), "../badger/mushroom/");
37 is(IkiWiki::urlto('', 'snake'), "../");
38 is(IkiWiki::urlto('', 'penguin/herring'), "../../");
40 # explicit cgiurl override
41 is(IkiWiki::cgiurl(cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki");
42 is(IkiWiki::cgiurl(do => 'badger', cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki?do=badger");
44 # with url and cgiurl on different sites, "local" degrades to protocol-relative
45 $IkiWiki::config{url} = "http://example.co.uk/~smcv";
46 $IkiWiki::config{cgiurl} = "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi";
47 is(IkiWiki::checkconfig(), 1);
48 is(IkiWiki::cgiurl(), "//dynamic.example.co.uk/~smcv/ikiwiki.cgi");
49 is(IkiWiki::baseurl(undef), "//example.co.uk/~smcv/");
50 is(IkiWiki::urlto('stoats', undef), "//example.co.uk/~smcv/stoats/");
51 is(IkiWiki::urlto('', undef), "//example.co.uk/~smcv/");
53 # with url and cgiurl on different schemes, "local" degrades to absolute for
54 # CGI but protocol-relative for static content, to avoid the CGI having
55 # mixed content
56 $IkiWiki::config{url} = "http://example.co.uk/~smcv";
57 $IkiWiki::config{cgiurl} = "https://dynamic.example.co.uk/~smcv/ikiwiki.cgi";
58 is(IkiWiki::checkconfig(), 1);
59 is(IkiWiki::cgiurl(), "https://dynamic.example.co.uk/~smcv/ikiwiki.cgi");
60 is(IkiWiki::baseurl(undef), "//example.co.uk/~smcv/");
61 is(IkiWiki::urlto('stoats', undef), "//example.co.uk/~smcv/stoats/");
62 is(IkiWiki::urlto('', undef), "//example.co.uk/~smcv/");