translation-links.t 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright (C) 2008 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. require 't/test.pl';
  16. package OddMuse;
  17. use Test::More tests => 33;
  18. use utf8; # tests contain UTF-8 characters and it matters
  19. add_module('translation-links.pl');
  20. AppendStringToFile($ConfigFile, q{
  21. use utf8;
  22. %Languages = ('de' => '\b(der|die|das|und|oder)\b',
  23. 'en' => '\b(the|he|she|that|this)\b');
  24. $Translate{de} = 'Deutsch';
  25. $Translate{en} = 'English';
  26. });
  27. $page = update_page('HomePage', 'This is the homepage. [[de:HauptSeite]] [[fr:PagePrincipale]]');
  28. # the page is not autoidentified as English, therefore English must be missing!
  29. test_page($page, 'This is the homepage.', 'fr:PagePrincipale',
  30. 'action=translate;id=HomePage;missing=en', 'Add Translation');
  31. test_page_negative($page, 'de:HauptSeite');
  32. xpath_test($page, '//div[@class="footer"]/span[@class="translation bar"]/a[@class="translation de"][@href="http://localhost/wiki.pl/HauptSeite"][text()="Deutsch"]');
  33. AppendStringToFile($ConfigFile, q{
  34. %Languages = ('de' => '\b(der|die|das|und|oder)\b',
  35. 'fr' => '\b(le|la|un|une|de|en)\b',
  36. 'en' => '\b(the|he|she|that|this)\b');
  37. $Translate{de} = 'Deutsch';
  38. $Translate{fr} = 'Français';
  39. $Translate{en} = 'English';
  40. });
  41. xpath_test(update_page('HomePage', 'Simple test. [[de:HauptSeite]]'),
  42. '//div[@class="footer"]/span[@class="translation bar"]/a[@class="translation new"][text()="Add Translation"][@href="http://localhost/wiki.pl?action=translate;id=HomePage;missing=en_fr"]');
  43. $page = get_page('action=translate id=HomePage missing=en_fr');
  44. test_page($page, 'Français', 'English');
  45. test_page_negative($page, 'Deutsch');
  46. # the page is now autoidentified as English, therefore French is the only one that is missing!
  47. xpath_test(update_page('HomePage', 'The the the the test. [[de:HauptSeite]]'),
  48. '//div[@class="footer"]/span[@class="translation bar"]/a[@class="translation new"][text()="Add Translation"][@href="http://localhost/wiki.pl?action=translate;id=HomePage;missing=fr"]');
  49. test_page(get_page('action=translate id=HomePage target=PagePrincipale translation=fr'),
  50. 'Editing PagePrincipale');
  51. test_page(get_page('action=browse raw=1 id=HomePage'),
  52. '\[\[de:HauptSeite\]\]', '\[\[fr:PagePrincipale\]\]');
  53. test_page_negative(get_page('HomePage'), 'Translate');
  54. test_page(get_page('action=translate id=HomePage target= translation=fr'),
  55. 'Translate HomePage', 'Page name is missing');
  56. test_page(get_page('action=translate id=HomePage target=a:b translation=fr'),
  57. 'Invalid Page a:b');
  58. test_page(get_page('action=translate id=HomePage target=abc'),
  59. 'Language is missing');
  60. test_page(get_page('action=translate id=HomePage target=abc translation=fr'),
  61. 'Editing abc');
  62. # encoding issues
  63. # first check the from ASCII to something that can be encoded in Latin-1
  64. test_page(update_page('SiteMap', 'Hello'), 'Hello');
  65. test_page(get_page('action=translate id=SiteMap target=Übersicht translation=de'),
  66. 'Editing Übersicht');
  67. xpath_test(get_page('SiteMap'),
  68. '//a[@class="translation de"][text()="Deutsch"]');
  69. xpath_test(get_page('action=rc showedit=1'),
  70. '//li/a[@class="local"][text()="SiteMap"]/following-sibling::strong[text()="Added translation: Übersicht (Deutsch)"]');
  71. # now check the other way around
  72. test_page(get_page('action=translate id=Übersicht target=SiteMap translation=en'),
  73. 'Editing SiteMap');
  74. xpath_test(get_page('Übersicht'),
  75. '//a[@class="translation en"][text()="English"]');
  76. xpath_test(get_page('action=rc showedit=1'),
  77. '//li/a[@class="local"][text()="Übersicht"]/following-sibling::strong[text()="Added translation: SiteMap (English)"]');
  78. AppendStringToFile($ConfigFile, q{
  79. $Languages{ja} = '(ま|す|ん|し|ょ|う|の|は)';
  80. $Translate{ja} = '日本語';
  81. });
  82. # Repeat it with Unicode!
  83. test_page(get_page('action=translate id=SiteMap target=サイトマップ translation=ja'),
  84. 'Editing サイトマップ');
  85. xpath_test(get_page('SiteMap'),
  86. '//a[@class="translation ja"][text()="日本語"]');
  87. xpath_test(get_page('action=rc showedit=1'),
  88. '//li/a[@class="local"][text()="SiteMap"]/following-sibling::strong[text()="Added translation: サイトマップ (日本語)"]');
  89. # and again, check the other way around
  90. test_page(get_page('action=translate id=サイトマップ target=SiteMap translation=en'),
  91. 'Editing SiteMap');
  92. xpath_test(get_page('サイトマップ'),
  93. '//a[@class="translation en"][text()="English"]');
  94. xpath_test(get_page('action=rc showedit=1'),
  95. '//li/a[@class="local"][text()="サイトマップ"]/following-sibling::strong[text()="Added translation: SiteMap (English)"]');