-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathType_AbstractBase.test.php
157 lines (146 loc) · 5.1 KB
/
Type_AbstractBase.test.php
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
namespace dokuwiki\plugin\struct\test;
/**
* @group plugin_struct
* @group plugins
*/
class Type_AbstractBase_struct_test extends StructTest {
protected $preset = array(
'label' => array(
'de' => 'german label',
'zh' => 'chinese label' // always stripped
),
'hint' => array(
'en' => 'english hint',
'de' => 'german hint',
'zh' => 'chinese hint' // always stripped
)
);
/**
* Translation Init: empty config, no translation plugin
*/
public function test_trans_empty_noplugin() {
global $conf;
$conf['lang'] = 'en';
$type = new mock\BaseType(null, 'A Label');
$this->assertEquals(
array(
'label' => array(
'en' => ''
),
'hint' => array(
'en' => ''
),
'visibility' => array('inpage' => true, 'ineditor' => true),
'default' => ''
),
$type->getConfig()
);
$this->assertEquals('A Label', $type->getTranslatedLabel());
$this->assertEquals('', $type->getTranslatedHint());
}
/**
* Translation Init: preset config, no translation plugin
*/
public function test_trans_preset_noplugin() {
global $conf;
$conf['lang'] = 'en';
$type = new mock\BaseType($this->preset, 'A Label');
$this->assertEquals(
array(
'label' => array(
'en' => ''
),
'hint' => array(
'en' => 'english hint'
),
'visibility' => array('inpage' => true, 'ineditor' => true),
'default' => ''
),
$type->getConfig()
);
$this->assertEquals('A Label', $type->getTranslatedLabel());
$this->assertEquals('english hint', $type->getTranslatedHint());
}
/**
* Translation Init: empty config, translation plugin
*/
public function test_trans_empty_plugin() {
global $conf;
$conf['lang'] = 'en';
$conf['plugin']['translation']['translations'] = 'fr tr it de';
$type = new mock\BaseType(null, 'A Label');
$this->assertEquals(
array(
'label' => array(
'en' => '',
'fr' => '',
'tr' => '',
'it' => '',
'de' => '',
),
'hint' => array(
'en' => '',
'fr' => '',
'tr' => '',
'it' => '',
'de' => '',
),
'visibility' => array('inpage' => true, 'ineditor' => true),
'default' => ''
),
$type->getConfig()
);
$this->assertEquals('A Label', $type->getTranslatedLabel());
$this->assertEquals('', $type->getTranslatedHint());
$conf['lang'] = 'de';
$this->assertEquals('A Label', $type->getTranslatedLabel());
$this->assertEquals('', $type->getTranslatedHint());
$conf['lang'] = 'zh';
$this->assertEquals('A Label', $type->getTranslatedLabel());
$this->assertEquals('', $type->getTranslatedHint());
$conf['lang'] = 'en';
}
/**
* Translation Init: preset config, translation plugin
*/
public function test_trans_preset_plugin() {
global $conf;
$conf['lang'] = 'en';
$conf['plugin']['translation']['translations'] = 'fr tr it de';
$type = new mock\BaseType($this->preset, 'A Label');
$this->assertEquals(
array(
'label' => array(
'en' => '',
'fr' => '',
'tr' => '',
'it' => '',
'de' => 'german label',
),
'hint' => array(
'en' => 'english hint',
'fr' => '',
'tr' => '',
'it' => '',
'de' => 'german hint',
),
'visibility' => array('inpage' => true, 'ineditor' => true),
'default' => ''
),
$type->getConfig()
);
$this->assertEquals('A Label', $type->getTranslatedLabel());
$this->assertEquals('english hint', $type->getTranslatedHint());
$conf['lang'] = 'de';
$this->assertEquals('german label', $type->getTranslatedLabel());
$this->assertEquals('german hint', $type->getTranslatedHint());
$conf['lang'] = 'zh';
$this->assertEquals('A Label', $type->getTranslatedLabel()); # falls back to column
$this->assertEquals('english hint', $type->getTranslatedHint()); # falls back to english
$conf['lang'] = 'fr';
$this->assertEquals('A Label', $type->getTranslatedLabel()); # falls back to column
$this->assertEquals('english hint', $type->getTranslatedHint()); # falls back to english
$conf['lang'] = 'en';
}
}