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