po test: add more cases, including (semi-)absolute URLs

Three cases are sub-optimal, but having fixed urlto(''), they all
basically work.
master
Simon McVittie 2010-12-25 22:17:32 +00:00
parent f328a2eab2
commit be6ca4c4e9
1 changed files with 24 additions and 1 deletions

25
t/po.t
View File

@ -17,7 +17,7 @@ BEGIN {
} }
} }
use Test::More tests => 93; use Test::More tests => 109;
BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki"); }
@ -34,6 +34,8 @@ $config{destdir} = "$dir/dst";
$config{destdir} = "$dir/dst"; $config{destdir} = "$dir/dst";
$config{underlaydirbase} = "/dev/null"; $config{underlaydirbase} = "/dev/null";
$config{underlaydir} = "/dev/null"; $config{underlaydir} = "/dev/null";
$config{url} = "http://example.com";
$config{cgiurl} = "http://example.com/ikiwiki.cgi";
$config{discussion} = 0; $config{discussion} = 0;
$config{po_master_language} = { code => 'en', $config{po_master_language} = { code => 'en',
name => 'English' name => 'English'
@ -166,11 +168,32 @@ $msgprefix="urlto (po_link_to=current)";
is(urlto('', 'index'), './index.en.html', "$msgprefix index -> ''"); is(urlto('', 'index'), './index.en.html', "$msgprefix index -> ''");
is(urlto('', 'nontranslatable'), '../index.en.html', "$msgprefix nontranslatable -> ''"); is(urlto('', 'nontranslatable'), '../index.en.html', "$msgprefix nontranslatable -> ''");
is(urlto('', 'translatable.fr'), '../index.fr.html', "$msgprefix translatable.fr -> ''"); is(urlto('', 'translatable.fr'), '../index.fr.html', "$msgprefix translatable.fr -> ''");
# when asking for a semi-absolute or absolute URL, we can't know what the
# current language is, so for translatable pages we use the master language
is(urlto('nontranslatable'), '/nontranslatable/', "$msgprefix 1-arg -> nontranslatable");
is(urlto('translatable'), '/translatable/index.en.html', "$msgprefix 1-arg -> translatable");
is(urlto('nontranslatable', undef, 1), 'http://example.com/nontranslatable/', "$msgprefix 1-arg -> nontranslatable");
is(urlto('index', undef, 1), 'http://example.com/index.en.html', "$msgprefix 1-arg -> index");
is(urlto('', undef, 1), 'http://example.com/index.en.html', "$msgprefix 1-arg -> ''");
# FIXME: should these three produce the negotiatable URL instead of the master
# language?
is(urlto(''), '/index.en.html', "$msgprefix 1-arg -> ''");
is(urlto('index'), '/index.en.html', "$msgprefix 1-arg -> index");
is(urlto('translatable', undef, 1), 'http://example.com/translatable/index.en.html', "$msgprefix 1-arg -> translatable");
$config{po_link_to}='negotiated'; $config{po_link_to}='negotiated';
$msgprefix="urlto (po_link_to=negotiated)"; $msgprefix="urlto (po_link_to=negotiated)";
is(urlto('', 'index'), './', "$msgprefix index -> ''"); is(urlto('', 'index'), './', "$msgprefix index -> ''");
is(urlto('', 'nontranslatable'), '../', "$msgprefix nontranslatable -> ''"); is(urlto('', 'nontranslatable'), '../', "$msgprefix nontranslatable -> ''");
is(urlto('', 'translatable.fr'), '../', "$msgprefix translatable.fr -> ''"); is(urlto('', 'translatable.fr'), '../', "$msgprefix translatable.fr -> ''");
is(urlto('nontranslatable'), '/nontranslatable/', "$msgprefix 1-arg -> nontranslatable");
is(urlto('translatable'), '/translatable/', "$msgprefix 1-arg -> translatable");
is(urlto(''), '/', "$msgprefix 1-arg -> ''");
is(urlto('index'), '/', "$msgprefix 1-arg -> index");
is(urlto('nontranslatable', undef, 1), 'http://example.com/nontranslatable/', "$msgprefix 1-arg -> nontranslatable");
is(urlto('translatable', undef, 1), 'http://example.com/translatable/', "$msgprefix 1-arg -> translatable");
is(urlto('index', undef, 1), 'http://example.com/', "$msgprefix 1-arg -> index");
is(urlto('', undef, 1), 'http://example.com/', "$msgprefix 1-arg -> ''");
### bestlink ### bestlink
$config{po_link_to}='current'; $config{po_link_to}='current';