Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 164 lines (142 sloc) 5.002 kb
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
1 <?php
ef3ab85 @pornel Trying to follow PEAR code formatting standard
authored
2 /**
3 * PHPTAL templating engine
4 *
5 * PHP Version 5
6 *
7 * @category HTML
8 * @package PHPTAL
9 * @author Laurent Bedubourg <lbedubourg@motion-twin.com>
10 * @author Kornel Lesiński <kornel@aardvarkmedia.co.uk>
11 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
12 * @version SVN: $Id$
3eb98a7 @pornel Change links and namespace from phptal.motion-twin.com to phptal.org
authored
13 * @link http://phptal.org/
ef3ab85 @pornel Trying to follow PEAR code formatting standard
authored
14 */
f592681 @pornel Annihilate trailing whitespace
authored
15
ff708cf @pornel Remove PHPTAL_DIR. For performance and PEAR compliance use set_include_p...
authored
16
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
17
2de422e @pornel Rename PHPTAL's DOM classes, methods and properties to be more W3CDOM-li...
authored
18 class GetTextTest extends PHPTAL_TestCase
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
19 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
20 private function getTextTranslator()
21 {
22 try
23 {
bc7c9d1 @pornel Fixed PHPTAL_FORCE_REPARSE gotcha
authored
24 return new PHPTAL_GetTextTranslator();
be953af @pornel (Note to self: first run tests THEN commit)
authored
25 }
26 catch(PHPTAL_Exception $e)
f592681 @pornel Annihilate trailing whitespace
authored
27 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
28 $this->markTestSkipped($e->getMessage());
29 }
30 }
f592681 @pornel Annihilate trailing whitespace
authored
31
32
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
33 function testSimple()
34 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
35 $gettext = $this->getTextTranslator();
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
36 $gettext->setLanguage('en_GB', 'en_GB.utf8');
37 $gettext->addDomain('test');
38 $gettext->useDomain('test');
f592681 @pornel Annihilate trailing whitespace
authored
39
74b94b4 @pornel Improve tests to properly force reparsing
authored
40 $tpl = $this->newPHPTAL('input/gettext.01.html');
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
41 $tpl->setTranslator($gettext);
eca3743 @pornel Renamed trim_string to normalize_html
authored
42 $res = normalize_html($tpl->execute());
43 $exp = normalize_html_file('output/gettext.01.html');
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
44 $this->assertEquals($exp, $res);
45 }
46
47 function testLang()
48 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
49 $gettext = $this->getTextTranslator();
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
50 $gettext->setLanguage('fr_FR', 'fr_FR@euro', 'fr_FR.utf8');
51 $gettext->addDomain('test');
52 $gettext->useDomain('test');
f592681 @pornel Annihilate trailing whitespace
authored
53
74b94b4 @pornel Improve tests to properly force reparsing
authored
54 $tpl = $this->newPHPTAL('input/gettext.02.html');
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
55 $tpl->setTranslator($gettext);
eca3743 @pornel Renamed trim_string to normalize_html
authored
56 $res = normalize_html($tpl->execute());
57 $exp = normalize_html_file('output/gettext.02.html');
f592681 @pornel Annihilate trailing whitespace
authored
58 $this->assertEquals($exp, $res);
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
59 }
60
61 function testInterpol()
62 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
63 $gettext = $this->getTextTranslator();
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
64 $gettext->setLanguage('fr_FR', 'fr_FR@euro', 'fr_FR.utf8');
65 $gettext->setEncoding('UTF-8');
66 $gettext->addDomain('test');
67 $gettext->useDomain('test');
f592681 @pornel Annihilate trailing whitespace
authored
68
74b94b4 @pornel Improve tests to properly force reparsing
authored
69 $tpl = $this->newPHPTAL('input/gettext.03.html');
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
70 $tpl->setTranslator($gettext);
71 $tpl->login = 'john';
72 $tpl->lastCxDate = '2004-12-25';
eca3743 @pornel Renamed trim_string to normalize_html
authored
73 $res = normalize_html($tpl->execute());
74 $exp = normalize_html_file('output/gettext.03.html');
f592681 @pornel Annihilate trailing whitespace
authored
75 $this->assertEquals($exp, $res);
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
76 }
77
78 function testDomainChange()
79 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
80 $gettext = $this->getTextTranslator();
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
81 $gettext->setEncoding('UTF-8');
82 $gettext->setLanguage('fr_FR', 'fr_FR@euro', 'fr_FR.utf8');
83 $gettext->addDomain('test');
84 $gettext->addDomain('test2');
85 $gettext->useDomain('test');
f592681 @pornel Annihilate trailing whitespace
authored
86
74b94b4 @pornel Improve tests to properly force reparsing
authored
87 $tpl = $this->newPHPTAL('input/gettext.04.html');
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
88 $tpl->setEncoding('UTF-8');
89 $tpl->setTranslator($gettext);
90 $tpl->login = 'john';
91 $tpl->lastCxDate = '2004-12-25';
eca3743 @pornel Renamed trim_string to normalize_html
authored
92 $res = normalize_html($tpl->execute());
93 $exp = normalize_html_file('output/gettext.04.html');
f592681 @pornel Annihilate trailing whitespace
authored
94 $this->assertEquals($exp, $res);
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
95 }
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
96
97 function testSpaces()
98 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
99 $gettext = $this->getTextTranslator();
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
100 $gettext->setLanguage('en_GB', 'en_GB.utf8');
101 $gettext->addDomain('test');
102 $gettext->useDomain('test');
f592681 @pornel Annihilate trailing whitespace
authored
103
74b94b4 @pornel Improve tests to properly force reparsing
authored
104 $tpl = $this->newPHPTAL('input/gettext.05.html');
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
105 $tpl->login = 'john smith';
106 $tpl->setTranslator($gettext);
eca3743 @pornel Renamed trim_string to normalize_html
authored
107 $res = normalize_html($tpl->execute());
108 $exp = normalize_html_file('output/gettext.05.html');
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
109 $this->assertEquals($exp, $res);
110 }
111
112 function testAccentuateKey()
113 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
114 $gettext = $this->getTextTranslator();
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
115 $gettext->setLanguage('en_GB', 'en_GB.utf8');
116 $gettext->addDomain('test');
117 $gettext->useDomain('test');
2254e81 @pornel Fixed encoding problems in gettext keys. Bugfix also breaks backwards co...
authored
118 $gettext->setCanonicalize(true);
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
119
74b94b4 @pornel Improve tests to properly force reparsing
authored
120 $tpl = $this->newPHPTAL('input/gettext.06.html');
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
121 $tpl->setTranslator($gettext);
122 $res = $tpl->execute();
eca3743 @pornel Renamed trim_string to normalize_html
authored
123 $res = normalize_html($res);
124 $exp = normalize_html_file('output/gettext.06.html');
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
125 $this->assertEquals($exp, $res);
126 }
f592681 @pornel Annihilate trailing whitespace
authored
127
2254e81 @pornel Fixed encoding problems in gettext keys. Bugfix also breaks backwards co...
authored
128 function testAccentuateKeyNonCanonical()
129 {
130 $gettext = $this->getTextTranslator();
131 $gettext->setLanguage('en_GB', 'en_GB.utf8');
132 $gettext->addDomain('test');
133 $gettext->useDomain('test');
134
74b94b4 @pornel Improve tests to properly force reparsing
authored
135 $tpl = $this->newPHPTAL('input/gettext.06.html');
2254e81 @pornel Fixed encoding problems in gettext keys. Bugfix also breaks backwards co...
authored
136 $tpl->setTranslator($gettext);
137 $res = $tpl->execute();
eca3743 @pornel Renamed trim_string to normalize_html
authored
138 $res = normalize_html($res);
139 $exp = normalize_html('<root>
2254e81 @pornel Fixed encoding problems in gettext keys. Bugfix also breaks backwards co...
authored
140 <span>Not accentuated</span>
141 <span>Accentuated key without canonicalization</span>
142 <span>Accentuated key without canonicalization</span>
143 </root>
144 ');
145 $this->assertEquals($exp, $res);
146 }
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
147
148 function testQuote()
149 {
be953af @pornel (Note to self: first run tests THEN commit)
authored
150 $gettext = $this->getTextTranslator();
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
151 $gettext->setLanguage('en_GB', 'en_GB.utf8');
152 $gettext->addDomain('test');
153 $gettext->useDomain('test');
154
74b94b4 @pornel Improve tests to properly force reparsing
authored
155 $tpl = $this->newPHPTAL('input/gettext.07.html');
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
156 $tpl->setTranslator($gettext);
157 $res = $tpl->execute();
eca3743 @pornel Renamed trim_string to normalize_html
authored
158 $res = normalize_html($res);
159 $exp = normalize_html_file('output/gettext.07.html');
6e48d2d integration of the 1.1.x branch (see changelog for a full resume of chan...
Laurent Bedubourg authored
160 $this->assertEquals($exp, $res);
161 }
59f2d83 Added GetText support (requires php gettext extension)
Laurent Bedubourg authored
162 }
163
Something went wrong with that request. Please try again.