wiki.pl: Port some fixes from upstream
[Orgmuse.git] / t / translation-links.t
blob6d4fa3299576310d81015597e6949c16dcf2c151
1 # Copyright (C) 2008  Alex Schroeder <alex@gnu.org>
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.
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.
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/>.
16 require 't/test.pl';
17 package OddMuse;
18 use Test::More tests => 33;
19 use utf8; # tests contain UTF-8 characters and it matters
21 clear_pages();
23 add_module('translation-links.pl');
25 AppendStringToFile($ConfigFile, q{
26 use utf8;
27 %Languages = ('de' => '\b(der|die|das|und|oder)\b',
28               'en' => '\b(the|he|she|that|this)\b');
29 $Translate{de} = 'Deutsch';
30 $Translate{en} = 'English';
31 });
33 $page = update_page('HomePage', 'This is the homepage. [[de:HauptSeite]] [[fr:PagePrincipale]]');
34 # the page is not autoidentified as English, therefore English must be missing!
35 test_page($page, 'This is the homepage.', 'fr:PagePrincipale',
36           'action=translate;id=HomePage;missing=en', 'Add Translation');
37 test_page_negative($page, 'de:HauptSeite');
38 xpath_test($page, '//div[@class="footer"]/span[@class="translation bar"]/a[@class="translation de"][@href="http://localhost/wiki.pl/HauptSeite"][text()="Deutsch"]');
40 AppendStringToFile($ConfigFile, q{
41 %Languages = ('de' => '\b(der|die|das|und|oder)\b',
42               'fr' => '\b(le|la|un|une|de|en)\b',
43               'en' => '\b(the|he|she|that|this)\b');
44 $Translate{de} = 'Deutsch';
45 $Translate{fr} = 'Français';
46 $Translate{en} = 'English';
47 });
49 xpath_test(update_page('HomePage', 'Simple test. [[de:HauptSeite]]'),
50            '//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"]');
52 $page = get_page('action=translate id=HomePage missing=en_fr');
53 test_page($page, 'Français', 'English');
54 test_page_negative($page, 'Deutsch');
56 # the page is now autoidentified as English, therefore French is the only one that is missing!
57 xpath_test(update_page('HomePage', 'The the the the test. [[de:HauptSeite]]'),
58            '//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"]');
60 test_page(get_page('action=translate id=HomePage target=PagePrincipale translation=fr'),
61           'Editing PagePrincipale');
63 test_page(get_page('action=browse raw=1 id=HomePage'),
64           '\[\[de:HauptSeite\]\]', '\[\[fr:PagePrincipale\]\]');
66 test_page_negative(get_page('HomePage'), 'Translate');
68 test_page(get_page('action=translate id=HomePage target= translation=fr'),
69           'Translate HomePage', 'Page name is missing');
71 test_page(get_page('action=translate id=HomePage target=a:b translation=fr'),
72           'Invalid Page a:b');
74 test_page(get_page('action=translate id=HomePage target=abc'),
75           'Language is missing');
77 test_page(get_page('action=translate id=HomePage target=abc translation=fr'),
78           'Editing abc');
80 # encoding issues
82 # first check the from ASCII to something that can be encoded in Latin-1
83 test_page(update_page('SiteMap', 'Hello'), 'Hello');
84 test_page(get_page('action=translate id=SiteMap target=Übersicht translation=de'),
85           'Editing Übersicht');
86 xpath_test(get_page('SiteMap'),
87            '//a[@class="translation de"][text()="Deutsch"]');
88 xpath_test(get_page('action=rc showedit=1'),
89            '//li/a[@class="local"][text()="SiteMap"]/following-sibling::strong[text()="Added translation: Übersicht (Deutsch)"]');
91 # now check the other way around
92 test_page(get_page('action=translate id=Übersicht target=SiteMap translation=en'),
93           'Editing SiteMap');
94 xpath_test(get_page('Übersicht'),
95            '//a[@class="translation en"][text()="English"]');
96 xpath_test(get_page('action=rc showedit=1'),
97            '//li/a[@class="local"][text()="Übersicht"]/following-sibling::strong[text()="Added translation: SiteMap (English)"]');
99 AppendStringToFile($ConfigFile, q{
100 $Languages{ja} = '(ま|す|ん|し|ょ|う|の|は)';
101 $Translate{ja} = '日本語';
104 # Repeat it with Unicode!
105 test_page(get_page('action=translate id=SiteMap target=サイトマップ translation=ja'),
106           'Editing サイトマップ');
107 xpath_test(get_page('SiteMap'),
108            '//a[@class="translation ja"][text()="日本語"]');
109 xpath_test(get_page('action=rc showedit=1'),
110            '//li/a[@class="local"][text()="SiteMap"]/following-sibling::strong[text()="Added translation: サイトマップ (日本語)"]');
112 # and again,  check the other way around
113 test_page(get_page('action=translate id=サイトマップ target=SiteMap translation=en'),
114           'Editing SiteMap');
115 xpath_test(get_page('サイトマップ'),
116            '//a[@class="translation en"][text()="English"]');
117 xpath_test(get_page('action=rc showedit=1'),
118            '//li/a[@class="local"][text()="サイトマップ"]/following-sibling::strong[text()="Added translation: SiteMap (English)"]');