X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/f398ad035b973608d380c9939ea845d8e2a0cdc2..36c476d3bbea6b708f6977d3f0e8eb5612ad5c9c:/t/po.t diff --git a/t/po.t b/t/po.t index 1cd18c317..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 => 68; +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,9 +45,10 @@ $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"); ok(IkiWiki::loadplugin('po'), "po plugin loaded"); IkiWiki::checkconfig(); @@ -53,6 +57,7 @@ $pagesources{'index'}='index.mdwn'; $pagesources{'index.fr'}='index.fr.po'; $pagesources{'index.es'}='index.es.po'; $pagesources{'test1'}='test1.mdwn'; +$pagesources{'test1.es'}='test1.es.po'; $pagesources{'test1.fr'}='test1.fr.po'; $pagesources{'test2'}='test2.mdwn'; $pagesources{'test2.es'}='test2.es.po'; @@ -63,17 +68,106 @@ $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 -writefile('index.mdwn', $config{srcdir}, '[[translatable]] [[nontranslatable]]'); -writefile('test1.mdwn', $config{srcdir}, 'test1 content'); +writefile('index.mdwn', $config{srcdir}, + "[[!meta title=\"index title\"]]\n[[translatable]] [[nontranslatable]]"); +writefile('test1.mdwn', $config{srcdir}, + "[[!meta title=\"test1 title\"]]\ntest1 content"); 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 @@ -88,6 +182,9 @@ ok(! IkiWiki::Plugin::po::istranslation('index'), "index is not a translation"); ok(IkiWiki::Plugin::po::istranslation('index.fr'), "index.fr is a translation"); ok(IkiWiki::Plugin::po::istranslation('index.es'), "index.es is a translation"); ok(IkiWiki::Plugin::po::istranslation('/index.fr'), "/index.fr is a translation"); +ok(IkiWiki::Plugin::po::istranslatable('test1'), "test1 is translatable"); +ok(IkiWiki::Plugin::po::istranslation('test1.es'), "test1.es is a translation"); +ok(IkiWiki::Plugin::po::istranslation('test1.fr'), "test1.fr is a translation"); ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable"); ok(! IkiWiki::Plugin::po::istranslation('test2'), "test2 is not a translation"); ok(! IkiWiki::Plugin::po::istranslatable('test3'), "test3 is not translatable"); @@ -126,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)"; @@ -137,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; @@ -159,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'; @@ -185,3 +303,210 @@ $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'); +is($pagestate{'index'}{meta}{title}, 'index title'); +is($pagestate{'index.es'}{meta}{title}, 'index title'); +is($pagestate{'index.fr'}{meta}{title}, 'index title'); +refresh_n_scan('test1.mdwn'); +is($pagestate{'test1'}{meta}{title}, 'test1 title'); +is($pagestate{'test1.es'}{meta}{title}, 'test1 title'); +is($pagestate{'test1.fr'}{meta}{title}, 'test1 title'); + +### istranslatedto +ok(IkiWiki::Plugin::po::istranslatedto('index', 'es')); +ok(IkiWiki::Plugin::po::istranslatedto('index', 'fr')); +ok(! IkiWiki::Plugin::po::istranslatedto('index', 'cz')); +ok(IkiWiki::Plugin::po::istranslatedto('test1', 'es')); +ok(IkiWiki::Plugin::po::istranslatedto('test1', 'fr')); +ok(! IkiWiki::Plugin::po::istranslatedto('test1', 'cz')); +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;