4 use Test::More tests => 21;
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);
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/");
23 # "local" (absolute path within site) version (default for cgiurl)
24 is(IkiWiki::cgiurl(), "/cgi-bin/ikiwiki.cgi");
25 is(IkiWiki::cgiurl(do => 'badger'), "/cgi-bin/ikiwiki.cgi?do=badger");
26 is(IkiWiki::baseurl(undef), "/");
27 is(IkiWiki::urlto('index', undef), "/");
28 is(IkiWiki::urlto('index'), "/");
29 is(IkiWiki::urlto('stoats', undef), "/stoats/");
30 is(IkiWiki::urlto('stoats'), "/stoats/");
32 # fully-relative version (default for urlto and baseurl)
33 is(IkiWiki::baseurl('badger/mushroom'), "../../");
34 is(IkiWiki::urlto('badger/mushroom', 'snake'), "../badger/mushroom/");
36 # explicit cgiurl override
37 is(IkiWiki::cgiurl(cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki");
38 is(IkiWiki::cgiurl(do => 'badger', cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki?do=badger");
40 # with url and cgiurl on different sites, "local" degrades to absolute
41 $IkiWiki::config{url} = "http://example.co.uk/~smcv";
42 $IkiWiki::config{cgiurl} = "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi";
43 is(IkiWiki::checkconfig(), 1);
44 is(IkiWiki::cgiurl(), "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi");
45 is(IkiWiki::baseurl(undef), "http://example.co.uk/~smcv/");
46 is(IkiWiki::urlto('stoats', undef), "http://example.co.uk/~smcv/stoats/");