I18NAttributesTest.php
3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* PHPTAL templating engine
*
* PHP Version 5
*
* @category HTML
* @package PHPTAL
* @author Laurent Bedubourg <lbedubourg@motion-twin.com>
* @author Kornel Lesiński <kornel@aardvarkmedia.co.uk>
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @version SVN: $Id: I18NAttributesTest.php 579 2009-04-25 23:14:46Z kornel $
* @link http://phptal.org/
*/
require_once dirname(__FILE__)."/config.php";
require_once 'I18NDummyTranslator.php';
class I18NAttributesTest extends PHPTAL_TestCase
{
function testSingle()
{
$t = new DummyTranslator();
$t->setTranslation('my-title', 'mon titre');
$tpl = $this->newPHPTAL('input/i18n-attributes-01.html');
$tpl->setTranslator($t);
$res = trim_string($tpl->execute());
$exp = trim_file('output/i18n-attributes-01.html');
$this->assertEquals($exp, $res);
}
function testTranslateDefault()
{
$t = new DummyTranslator();
$t->setTranslation('my-title', 'mon titre');
$tpl = $this->newPHPTAL('input/i18n-attributes-02.html');
$tpl->setTranslator($t);
$res = trim_string($tpl->execute());
$exp = trim_file('output/i18n-attributes-02.html');
$this->assertEquals($exp, $res);
}
function testTranslateTalAttribute()
{
$t = new DummyTranslator();
$t->setTranslation('my-title', 'mon titre');
$tpl = $this->newPHPTAL('input/i18n-attributes-03.html');
$tpl->sometitle = 'my-title';
$tpl->setTranslator($t);
$res = trim_string($tpl->execute());
$exp = trim_file('output/i18n-attributes-03.html');
$this->assertEquals($exp, $res, $tpl->getCodePath());
}
function testTranslateDefaultAttributeEscape()
{
$t = new DummyTranslator();
$t->setTranslation('my\'title', 'mon\'titre');
$tpl = $this->newPHPTAL();
$tpl->setSource('<div><a title="my\'title" class="my'title" i18n:attributes="class;title">test</a></div>');
$tpl->sometitle = 'my-title';
$tpl->setTranslator($t);
$this->assertEquals('<div><a title="mon'titre" class="mon'titre">test</a></div>', $tpl->execute(), $tpl->getCodePath());
}
function testTranslateTalAttributeEscape()
{
$this->markTestSkipped("Hard to fix bug");
$t = new DummyTranslator();
$t->setTranslation('my\'title', 'mon\'titre');
$tpl = $this->newPHPTAL();
$tpl->setSource('<div><a title="foo" tal:attributes="title sometitle; class php:sometitle" i18n:attributes="class;title">test</a></div>');
$tpl->sometitle = 'my\'title';
$tpl->setTranslator($t);
$this->assertEquals('<div><a title="mon'titre" class="mon'titre">test</a></div>', $tpl->execute(), $tpl->getCodePath());
}
function testMultiple()
{
$t = new DummyTranslator();
$t->setTranslation('my-title', 'mon titre');
$t->setTranslation('my-dummy', 'mon machin');
$tpl = $this->newPHPTAL('input/i18n-attributes-04.html');
$tpl->sometitle = 'my-title';
$tpl->setTranslator($t);
$res = trim_string($tpl->execute());
$exp = trim_file('output/i18n-attributes-04.html');
$this->assertEquals($exp, $res);
}
function testInterpolation()
{
$t = new DummyTranslator();
$t->setTranslation('foo ${someObject/method} bar ${otherObject/method} buz','ok ${someObject/method} ok ${otherObject/method} ok');
$tpl = $this->newPHPTAL('input/i18n-attributes-05.html');
$tpl->setTranslator($t);
$tpl->someObject = array('method' => 'good');
$tpl->otherObject = array('method' => 'great');
$res = trim_string($tpl->execute());
$exp = trim_file('output/i18n-attributes-05.html');
$this->assertEquals($exp, $res);
}
}