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
|
<?php
/**
* General tests for the translation plugin
*
* @group plugin_translation
* @group plugins
*/
class basic_plugin_translation_test extends DokuWikiTest {
protected $pluginsEnabled = array('translation');
public static function buildTransID_testdata() {
return array(
array(
'en',
'ns:page',
'de es',
array(':ns:page', 'en'),
),
array(
'',
'ns:page',
'de es',
array(':ns:page', 'en'),
),
array(
'de',
'ns:page',
'de es',
array(':de:ns:page', 'de'),
),
);
}
/**
* @dataProvider buildTransID_testdata
*
* @param $inputLang
* @param $inputID
* @param $translationsOption
* @param $expected
*/
public function test_buildTransID($inputLang, $inputID, $translationsOption, $expected) {
global $conf;
$conf['plugin']['translation']['translations'] = $translationsOption;
/** @var helper_plugin_translation $helper */
$helper = plugin_load('helper', 'translation', true);
$actual_result = $helper->buildTransID($inputLang, $inputID);
$this->assertEquals($expected, $actual_result);
}
public static function redirectStart_testdata() {
return array(
array(
'start',
'de es',
'de,en-US;q=0.8,en;q=0.5,fr;q=0.3',
':de:start',
'redirect to translated page',
),
array(
'start',
'de es',
'en-US,de;q=0.8,en;q=0.5,fr;q=0.3',
array(),
'do not redirect if basic namespace is correct lang',
),
array(
'de:start',
'en de es',
'en-US,en;q=0.8,fr;q=0.5',
array(),
'do not redirect anything other than exactly $conf[\'start\']',
),
);
}
/**
* @dataProvider redirectStart_testdata
*
* @param $input
* @param $translationsOption
* @param $httpAcceptHeader
* @param $expected
*/
public function test_redirectStart($input, $translationsOption, $httpAcceptHeader, $expected, $msg) {
global $conf;
$conf['plugin']['translation']['translations'] = $translationsOption;
$conf['plugin']['translation']['redirectstart'] = 1;
/** @var helper_plugin_translation $helper */
$helper = plugin_load('helper', 'translation');
$helper->loadTranslationNamespaces();
$request = new TestRequest();
$request->setServer('HTTP_ACCEPT_LANGUAGE', $httpAcceptHeader);
$response = $request->get(array('id' => $input));
$actual = $response->getHeader('Location');
if (is_string($actual)) {
list(, $actual) = explode('doku.php?id=', $actual);
}
$this->assertEquals($expected, $actual, $msg);
}
}
|