X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/8c2962ec48ae57605d6d0e297be437a97b6229ca..refs/heads/master:/t/po.t?ds=sidebyside diff --git a/t/po.t b/t/po.t index 51321fa96..ccb508bef 100755 --- a/t/po.t +++ b/t/po.t @@ -3,6 +3,7 @@ use warnings; use strict; use File::Temp qw{tempdir}; +use utf8; BEGIN { unless (eval { require Locale::Po4a::Chooser }) { @@ -17,7 +18,7 @@ BEGIN { } } -use Test::More tests => 91; +use Test::More; BEGIN { use_ok("IkiWiki"); } @@ -34,6 +35,8 @@ $config{destdir} = "$dir/dst"; $config{destdir} = "$dir/dst"; $config{underlaydirbase} = "/dev/null"; $config{underlaydir} = "/dev/null"; +$config{url} = "http://example.com"; +$config{cgiurl} = "http://example.com/ikiwiki.cgi"; $config{discussion} = 0; $config{po_master_language} = { code => 'en', name => 'English' @@ -42,7 +45,7 @@ $config{po_slave_languages} = { es => 'Castellano', fr => "Français" }; -$config{po_translatable_pages}='index or test1 or test2 or translatable'; +$config{po_translatable_pages}='index or test1 or test2 or translatable or debian*'; $config{po_link_to}='negotiated'; IkiWiki::loadplugins(); ok(IkiWiki::loadplugin('meta'), "meta plugin loaded"); @@ -65,8 +68,19 @@ $pagesources{'translatable'}='translatable.mdwn'; $pagesources{'translatable.fr'}='translatable.fr.po'; $pagesources{'translatable.es'}='translatable.es.po'; $pagesources{'nontranslatable'}='nontranslatable.mdwn'; +$pagesources{'debian911356'}='debian911356.mdwn'; +$pagesources{'debian911356ish'}='debian911356ish.mdwn'; +$pagesources{'debian911356.fr'}='debian911356.fr.po'; +$pagesources{'debian911356ish.fr'}='debian911356ish.fr.po'; +$pagesources{'debian911356-inlined'}='debian911356-inlined.mdwn'; +$pagesources{'debian911356-inlined.fr'}='debian911356-inlined.fr.po'; +$pagesources{'templates/feedlink.tmpl'}='templates/feedlink.tmpl'; +$pagesources{'templates/inlinepage.tmpl'}='templates/inlinepage.tmpl'; +my $now=time; foreach my $page (keys %pagesources) { $IkiWiki::pagecase{lc $page}=$page; + $IkiWiki::pagectime{$page}=$now; + $IkiWiki::pagemtime{$page}=$now; } ### populate srcdir @@ -78,6 +92,82 @@ writefile('test2.mdwn', $config{srcdir}, 'test2 content'); writefile('test3.mdwn', $config{srcdir}, 'test3 content'); writefile('translatable.mdwn', $config{srcdir}, '[[nontranslatable]]'); writefile('nontranslatable.mdwn', $config{srcdir}, '[[/]] [[translatable]]'); +writefile('debian911356.mdwn', $config{srcdir}, < +EOF +# Make inlines' appearance predictable so we can screen-scrape them +writefile('templates/inlinepage.tmpl', $config{srcdir}, < +
+ + +EOF ### istranslatable/istranslation # we run these tests twice because memoization attempts made them @@ -133,7 +223,7 @@ is_deeply(\@{$links{'index.fr'}}, ['translatable.fr', 'nontranslatable'], "$msgp is_deeply(\@{$links{'translatable'}}, ['nontranslatable'], "$msgprefix translatable"); is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], "$msgprefix translatable.es"); is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], "$msgprefix translatable.fr"); -is_deeply(\@{$links{'nontranslatable'}}, ['/', 'translatable', 'translatable.fr', 'translatable.es'], "$msgprefix nontranslatable"); +is_deeply([sort @{$links{'nontranslatable'}}], [sort('/', 'translatable', 'translatable.fr', 'translatable.es')], "$msgprefix nontranslatable"); $config{po_link_to}='current'; $msgprefix="links (po_link_to=current)"; @@ -144,7 +234,7 @@ is_deeply(\@{$links{'index.fr'}}, [ (map bestlink('index.fr', $_), ('translatabl is_deeply(\@{$links{'translatable'}}, [bestlink('translatable', 'nontranslatable')], "$msgprefix translatable"); is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], "$msgprefix translatable.es"); is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], "$msgprefix translatable.fr"); -is_deeply(\@{$links{'nontranslatable'}}, ['/', 'translatable', 'translatable.fr', 'translatable.es'], "$msgprefix nontranslatable"); +is_deeply([sort @{$links{'nontranslatable'}}], [sort('/', 'translatable', 'translatable.fr', 'translatable.es')], "$msgprefix nontranslatable"); ### targetpage $config{usedirs}=0; @@ -166,11 +256,32 @@ $msgprefix="urlto (po_link_to=current)"; is(urlto('', 'index'), './index.en.html', "$msgprefix index -> ''"); is(urlto('', 'nontranslatable'), '../index.en.html', "$msgprefix nontranslatable -> ''"); 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'; $msgprefix="urlto (po_link_to=negotiated)"; is(urlto('', 'index'), './', "$msgprefix index -> ''"); is(urlto('', 'nontranslatable'), '../', "$msgprefix nontranslatable -> ''"); 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 $config{po_link_to}='current'; @@ -192,6 +303,10 @@ $msgprefix="beautify_urlpath (po_link_to=negotiated)"; is(IkiWiki::beautify_urlpath('test1/index.html'), './test1/', "$msgprefix test1/index.html"); is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/', "$msgprefix test1/index.en.html"); is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/', "$msgprefix test1/index.fr.html"); +$config{po_link_to}='current'; +$msgprefix="beautify_urlpath (po_link_to=current)"; +is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/index.en.html', "$msgprefix test1/index.en.html"); +is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html"); ### re-scan refresh_n_scan('index.mdwn'); @@ -214,3 +329,184 @@ ok(! IkiWiki::Plugin::po::istranslatedto('nontranslatable', 'es')); ok(! IkiWiki::Plugin::po::istranslatedto('nontranslatable', 'cz')); ok(! IkiWiki::Plugin::po::istranslatedto('test1.es', 'fr')); ok(! IkiWiki::Plugin::po::istranslatedto('test1.fr', 'es')); + +### islanguagecode +ok(IkiWiki::Plugin::po::islanguagecode('en')); +ok(IkiWiki::Plugin::po::islanguagecode('es')); +ok(IkiWiki::Plugin::po::islanguagecode('arn')); +ok(! IkiWiki::Plugin::po::islanguagecode('es_')); +ok(! IkiWiki::Plugin::po::islanguagecode('_en')); + +# Actually render translated pages +use IkiWiki::Render; + +my %output; +foreach my $page (sort keys %pagesources) { + my $source = "$config{srcdir}/$pagesources{$page}"; + if (-e $source) { + IkiWiki::scan($pagesources{$page}); + } +} + +# This is the most complicated case, so use this while we test rendering +$config{po_link_to}='current'; + +foreach my $page (sort keys %pagesources) { + my $source = "$config{srcdir}/$pagesources{$page}"; + if (-e $source && defined IkiWiki::pagetype($pagesources{$page})) { + IkiWiki::scan($pagesources{$page}); + my $content = readfile($source); + #print STDERR "-------------------------------------\n"; + #print STDERR "SOURCE: $page: $content\n"; + $content = IkiWiki::filter($page, $page, $content); + #print STDERR "FILTERED: $page: $content\n"; + $content = IkiWiki::preprocess($page, $page, $content); + #print STDERR "PREPROCESSED: $page: $content\n"; + $content = IkiWiki::linkify($page, $page, $content); + #print STDERR "LINKIFIED: $page: $content\n"; + $content = IkiWiki::htmlize($page, $page, IkiWiki::pagetype($pagesources{$page}), $content); + #print STDERR "HTMLIZED: $page: $content\n"; + IkiWiki::run_hooks(format => sub { + $content=shift->( + page => $page, + content => $content, + ); + }); + #print STDERR "FORMATTED: $page: $content\n"; + $output{$page} = $content; + } +} + +like($output{index}, qr{ +

+ + translatable + \s* + + nontranslatable + +

+}sx); + +like($output{'index.es'}, qr{ +

+ + translatable + \s* + + nontranslatable + +

+}sx); + +like($output{'index.fr'}, qr{ +

+ + translatable + \s* + + nontranslatable + +

+}sx); + +like($output{'translatable'}, qr{ + + nontranslatable + +}sx); + +TODO: { +local $TODO = 'was [[/]] meant to be a link to the index?'; +unlike($output{'nontranslatable'}, qr{ + class=.createlink. +}sx); +}; +like($output{'nontranslatable'}, qr{ + + translatable + +}sx); + +like($output{debian911356}, qr{ +

Before\sfirst\sinline

+ \s* +

English\scontent

+ \s* +

Between\sinlines

+ \s* +

English\scontent

+ \s* +

After\sinlines

+}sx); + +like($output{'debian911356.fr'}, qr{ +

Avant\sla\spremière\sinline

+ \s* +

Contenu\sfrançais

+ \s* +

Entre\sles\sinlines

+ \s* +

Contenu\sfrançais

+ \s* +

Après\sles\sinlines

+}sx); + +# Variation of Debian #911356 without using raw inlines. +like($output{debian911356ish}, qr{ +

Before\sfirst\sinline

+ \s* + + \s* + + \s* +
debian911356-inlined
+ \s* +

English\scontent

+ \s* + + \s* +

Between\sinlines

+ \s* + + \s* + + \s* +
debian911356-inlined
+ \s* +

English\scontent

+ \s* + + \s* +

After\sinlines

+}sx); + +like($output{'debian911356ish.fr'}, qr{ +

Avant\sla\spremière\sinline

+ \s* + + \s* + + \s* +
debian911356-inlined\.fr
+ \s* +

Contenu\sfrançais

+ \s* + + \s* +

Entre\sles\sinlines

+ \s* + + \s* + + \s* +
debian911356-inlined\.fr
+ \s* +

Contenu\sfrançais

+ \s* + + \s* +

Après\sles\sinlines

+}sx); + +done_testing;