]> sipb.mit.edu Git - ikiwiki.git/blob - t/po.t
9afe8d88f200f3c636ce3b5622b8cfe08edb8445
[ikiwiki.git] / t / po.t
1 #!/usr/bin/perl
2 # -*- cperl-indent-level: 8; -*-
3 use warnings;
4 use strict;
5 use File::Temp;
6
7 BEGIN {
8         unless (eval { require Locale::Po4a::Chooser }) {
9                 eval q{
10                         use Test::More skip_all => "Locale::Po4a::Chooser::new is not available"
11                 }
12         }
13         unless (eval { require Locale::Po4a::Po }) {
14                 eval q{
15                         use Test::More skip_all => "Locale::Po4a::Po::new is not available"
16                 }
17         }
18 }
19
20 use Test::More tests => 24;
21
22 BEGIN { use_ok("IkiWiki"); }
23
24 my $msgprefix;
25
26 ### Init
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',
33                                 name => 'English'
34                               };
35 $config{po_slave_languages} = {
36                                es => 'Castellano',
37                                fr => "Français"
38                               };
39 $config{po_translatable_pages}='test1 or test2';
40 $config{po_link_to}='negotiated';
41 IkiWiki::loadplugins();
42 IkiWiki::checkconfig();
43 ok(IkiWiki::loadplugin('po'), "po plugin loaded");
44
45 ### seed %pagesources and %pagecase
46 $pagesources{'test1'}='test1.mdwn';
47 $pagesources{'test1.fr'}='test1.fr.po';
48 $pagesources{'test2'}='test2.mdwn';
49 $pagesources{'test2.es'}='test2.es.po';
50 $pagesources{'test2.fr'}='test2.fr.po';
51 $pagesources{'test3'}='test3.mdwn';
52 $pagesources{'test3.es'}='test3.es.mdwn';
53 foreach my $page (keys %pagesources) {
54     $IkiWiki::pagecase{lc $page}=$page;
55 }
56
57 ### istranslatable/istranslation
58 # we run these tests twice because memoization attempts made them
59 # succeed once every two tries...
60 ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable");
61 ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable");
62 ok(! IkiWiki::Plugin::po::istranslation('test2'), "test2 is not a translation");
63 ok(! IkiWiki::Plugin::po::istranslation('test2'), "test2 is not a translation");
64 ok(! IkiWiki::Plugin::po::istranslatable('test3'), "test3 is not translatable");
65 ok(! IkiWiki::Plugin::po::istranslatable('test3'), "test3 is not translatable");
66 ok(! IkiWiki::Plugin::po::istranslation('test3'), "test3 is not a translation");
67 ok(! IkiWiki::Plugin::po::istranslation('test3'), "test3 is not a translation");
68
69 ### targetpage
70 $config{usedirs}=0;
71 $msgprefix="targetpage (usedirs=0)";
72 is(targetpage('test1', 'html'), 'test1.en.html', "$msgprefix test1");
73 is(targetpage('test1.fr', 'html'), 'test1.fr.html', "$msgprefix test1.fr");
74 $config{usedirs}=1;
75 $msgprefix="targetpage (usedirs=1)";
76 is(targetpage('test1', 'html'), 'test1/index.en.html', "$msgprefix test1");
77 is(targetpage('test1.fr', 'html'), 'test1/index.fr.html', "$msgprefix test1.fr");
78 is(targetpage('test3', 'html'), 'test3/index.html', "$msgprefix test3 (non-translatable page)");
79 is(targetpage('test3.es', 'html'), 'test3.es/index.html', "$msgprefix test3.es (non-translatable page)");
80
81 ### bestlink
82 $config{po_link_to}='current';
83 $msgprefix="bestlink (po_link_to=current)";
84 is(bestlink('test1.fr', 'test2'), 'test2.fr', "$msgprefix test1.fr -> test2");
85 is(bestlink('test1.fr', 'test2.es'), 'test2.es', "$msgprefix test1.fr -> test2.es");
86 $config{po_link_to}='negotiated';
87 $msgprefix="bestlink (po_link_to=negotiated)";
88 is(bestlink('test1.fr', 'test2'), 'test2', "$msgprefix test1.fr -> test2");
89 is(bestlink('test1.fr', 'test2.es'), 'test2.es', "$msgprefix test1.fr -> test2.es");
90
91 ### beautify_urlpath
92 $config{po_link_to}='default';
93 $msgprefix="beautify_urlpath (po_link_to=default)";
94 is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/index.en.html', "$msgprefix test1/index.en.html");
95 is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html");
96 $config{po_link_to}='negotiated';
97 $msgprefix="beautify_urlpath (po_link_to=negotiated)";
98 is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/', "$msgprefix test1/index.en.html");
99 is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html");