2 # -*- cperl-indent-level: 8; -*-
8 unless (eval { require Locale::Po4a::Chooser }) {
10 use Test::More skip_all => "Locale::Po4a::Chooser::new is not available"
13 unless (eval { require Locale::Po4a::Po }) {
15 use Test::More skip_all => "Locale::Po4a::Po::new is not available"
20 use Test::More tests => 34;
22 BEGIN { use_ok("IkiWiki"); }
27 %config=IkiWiki::defaultconfig();
28 $config{srcdir}=$config{destdir}="/dev/null";
29 ## will need this when more thorough tests are written
30 # $config{srcdir} = "t/po/src";
31 # $config{destdir} = File::Temp->newdir("ikiwiki-test-po.XXXXXXXXXX", TMPDIR => 1)->dirname;
32 $config{po_master_language} = { code => 'en',
35 $config{po_slave_languages} = {
39 $config{po_translatable_pages}='index or test1 or test2';
40 $config{po_link_to}='negotiated';
41 IkiWiki::loadplugins();
42 IkiWiki::checkconfig();
43 ok(IkiWiki::loadplugin('po'), "po plugin loaded");
45 ### seed %pagesources and %pagecase
46 $pagesources{'index'}='index.mdwn';
47 $pagesources{'index.fr'}='index.fr.po';
48 $pagesources{'test1'}='test1.mdwn';
49 $pagesources{'test1.fr'}='test1.fr.po';
50 $pagesources{'test2'}='test2.mdwn';
51 $pagesources{'test2.es'}='test2.es.po';
52 $pagesources{'test2.fr'}='test2.fr.po';
53 $pagesources{'test3'}='test3.mdwn';
54 $pagesources{'test3.es'}='test3.es.mdwn';
55 foreach my $page (keys %pagesources) {
56 $IkiWiki::pagecase{lc $page}=$page;
59 ### istranslatable/istranslation
60 # we run these tests twice because memoization attempts made them
61 # succeed once every two tries...
62 ok(IkiWiki::Plugin::po::istranslatable('index'), "index is translatable");
63 ok(IkiWiki::Plugin::po::istranslatable('index'), "index is translatable");
64 ok(! IkiWiki::Plugin::po::istranslatable('index.fr'), "index is not translatable");
65 ok(! IkiWiki::Plugin::po::istranslatable('index.fr'), "index is not translatable");
66 ok(! IkiWiki::Plugin::po::istranslation('index'), "index is not a translation");
67 ok(! IkiWiki::Plugin::po::istranslation('index'), "index is not a translation");
68 ok(IkiWiki::Plugin::po::istranslation('index.fr'), "index.fr is a translation");
69 ok(IkiWiki::Plugin::po::istranslation('index.fr'), "index.fr is a translation");
70 ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable");
71 ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable");
72 ok(! IkiWiki::Plugin::po::istranslation('test2'), "test2 is not a translation");
73 ok(! IkiWiki::Plugin::po::istranslation('test2'), "test2 is not a translation");
74 ok(! IkiWiki::Plugin::po::istranslatable('test3'), "test3 is not translatable");
75 ok(! IkiWiki::Plugin::po::istranslatable('test3'), "test3 is not translatable");
76 ok(! IkiWiki::Plugin::po::istranslation('test3'), "test3 is not a translation");
77 ok(! IkiWiki::Plugin::po::istranslation('test3'), "test3 is not a translation");
81 $msgprefix="targetpage (usedirs=0)";
82 is(targetpage('test1', 'html'), 'test1.en.html', "$msgprefix test1");
83 is(targetpage('test1.fr', 'html'), 'test1.fr.html', "$msgprefix test1.fr");
85 $msgprefix="targetpage (usedirs=1)";
86 is(targetpage('index', 'html'), 'index.en.html', "$msgprefix index");
87 is(targetpage('index.fr', 'html'), 'index.fr.html', "$msgprefix index.fr");
88 is(targetpage('test1', 'html'), 'test1/index.en.html', "$msgprefix test1");
89 is(targetpage('test1.fr', 'html'), 'test1/index.fr.html', "$msgprefix test1.fr");
90 is(targetpage('test3', 'html'), 'test3/index.html', "$msgprefix test3 (non-translatable page)");
91 is(targetpage('test3.es', 'html'), 'test3.es/index.html', "$msgprefix test3.es (non-translatable page)");
94 $config{po_link_to}='current';
95 $msgprefix="bestlink (po_link_to=current)";
96 is(bestlink('test1.fr', 'test2'), 'test2.fr', "$msgprefix test1.fr -> test2");
97 is(bestlink('test1.fr', 'test2.es'), 'test2.es', "$msgprefix test1.fr -> test2.es");
98 $config{po_link_to}='negotiated';
99 $msgprefix="bestlink (po_link_to=negotiated)";
100 is(bestlink('test1.fr', 'test2'), 'test2', "$msgprefix test1.fr -> test2");
101 is(bestlink('test1.fr', 'test2.es'), 'test2.es', "$msgprefix test1.fr -> test2.es");
104 $config{po_link_to}='default';
105 $msgprefix="beautify_urlpath (po_link_to=default)";
106 is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/index.en.html', "$msgprefix test1/index.en.html");
107 is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html");
108 $config{po_link_to}='negotiated';
109 $msgprefix="beautify_urlpath (po_link_to=negotiated)";
110 is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/', "$msgprefix test1/index.en.html");
111 is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html");