1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5/**
6 * @group plugin_struct
7 * @group plugins
8 */
9class Type_AbstractBase_struct_test extends StructTest
10{
11
12    protected $preset = array(
13        'label' => array(
14            'de' => 'german label',
15            'zh' => 'chinese label' // always stripped
16        ),
17        'hint' => array(
18            'en' => 'english hint',
19            'de' => 'german hint',
20            'zh' => 'chinese hint' // always stripped
21        )
22    );
23
24    /**
25     * Translation Init: empty config, no translation plugin
26     */
27    public function test_trans_empty_noplugin()
28    {
29        global $conf;
30        $conf['lang'] = 'en';
31
32        $type = new mock\BaseType(null, 'A Label');
33        $this->assertEquals(
34            array(
35                'label' => array(
36                    'en' => ''
37                ),
38                'hint' => array(
39                    'en' => ''
40                ),
41                'visibility' => array('inpage' => true, 'ineditor' => true)
42            ),
43            $type->getConfig()
44        );
45        $this->assertEquals('A Label', $type->getTranslatedLabel());
46        $this->assertEquals('', $type->getTranslatedHint());
47    }
48
49    /**
50     * Translation Init: preset config, no translation plugin
51     */
52    public function test_trans_preset_noplugin()
53    {
54        global $conf;
55        $conf['lang'] = 'en';
56
57        $type = new mock\BaseType($this->preset, 'A Label');
58        $this->assertEquals(
59            array(
60                'label' => array(
61                    'en' => ''
62                ),
63                'hint' => array(
64                    'en' => 'english hint'
65                ),
66                'visibility' => array('inpage' => true, 'ineditor' => true)
67            ),
68            $type->getConfig()
69        );
70        $this->assertEquals('A Label', $type->getTranslatedLabel());
71        $this->assertEquals('english hint', $type->getTranslatedHint());
72    }
73
74    /**
75     * Translation Init: empty config, translation plugin
76     */
77    public function test_trans_empty_plugin()
78    {
79        global $conf;
80        $conf['lang'] = 'en';
81        $conf['plugin']['translation']['translations'] = 'fr tr it de';
82
83        $type = new mock\BaseType(null, 'A Label');
84        $this->assertEquals(
85            array(
86                'label' => array(
87                    'en' => '',
88                    'fr' => '',
89                    'tr' => '',
90                    'it' => '',
91                    'de' => '',
92                ),
93                'hint' => array(
94                    'en' => '',
95                    'fr' => '',
96                    'tr' => '',
97                    'it' => '',
98                    'de' => '',
99                ),
100                'visibility' => array('inpage' => true, 'ineditor' => true)
101            ),
102            $type->getConfig()
103        );
104        $this->assertEquals('A Label', $type->getTranslatedLabel());
105        $this->assertEquals('', $type->getTranslatedHint());
106        $conf['lang'] = 'de';
107        $this->assertEquals('A Label', $type->getTranslatedLabel());
108        $this->assertEquals('', $type->getTranslatedHint());
109        $conf['lang'] = 'zh';
110        $this->assertEquals('A Label', $type->getTranslatedLabel());
111        $this->assertEquals('', $type->getTranslatedHint());
112        $conf['lang'] = 'en';
113    }
114
115    /**
116     * Translation Init: preset config, translation plugin
117     */
118    public function test_trans_preset_plugin()
119    {
120        global $conf;
121        $conf['lang'] = 'en';
122        $conf['plugin']['translation']['translations'] = 'fr tr it de';
123
124        $type = new mock\BaseType($this->preset, 'A Label');
125        $this->assertEquals(
126            array(
127                'label' => array(
128                    'en' => '',
129                    'fr' => '',
130                    'tr' => '',
131                    'it' => '',
132                    'de' => 'german label',
133                ),
134                'hint' => array(
135                    'en' => 'english hint',
136                    'fr' => '',
137                    'tr' => '',
138                    'it' => '',
139                    'de' => 'german hint',
140                ),
141                'visibility' => array('inpage' => true, 'ineditor' => true)
142            ),
143            $type->getConfig()
144        );
145        $this->assertEquals('A Label', $type->getTranslatedLabel());
146        $this->assertEquals('english hint', $type->getTranslatedHint());
147        $conf['lang'] = 'de';
148        $this->assertEquals('german label', $type->getTranslatedLabel());
149        $this->assertEquals('german hint', $type->getTranslatedHint());
150        $conf['lang'] = 'zh';
151        $this->assertEquals('A Label', $type->getTranslatedLabel()); # falls back to column
152        $this->assertEquals('english hint', $type->getTranslatedHint());  # falls back to english
153        $conf['lang'] = 'fr';
154        $this->assertEquals('A Label', $type->getTranslatedLabel()); # falls back to column
155        $this->assertEquals('english hint', $type->getTranslatedHint());  # falls back to english
156        $conf['lang'] = 'en';
157    }
158}
159