-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathTranslatorTest.php
More file actions
142 lines (119 loc) · 4.75 KB
/
Copy pathTranslatorTest.php
File metadata and controls
142 lines (119 loc) · 4.75 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
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
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Misc;
use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\MoTranslator\Translator as MoTranslator;
use PhpMyAdmin\SqlParser\Translator;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionProperty;
use function realpath;
use const PHP_VERSION_ID;
/** @covers \PhpMyAdmin\SqlParser\Translator */
final class TranslatorTest extends TestCase
{
public static function tearDownAfterClass(): void
{
$loaderProperty = new ReflectionProperty(Translator::class, 'loader');
if (PHP_VERSION_ID < 80100) {
$loaderProperty->setAccessible(true);
}
$loaderProperty->setValue(null, null);
$translatorProperty = new ReflectionProperty(Translator::class, 'translator');
if (PHP_VERSION_ID < 80100) {
$translatorProperty->setAccessible(true);
}
$translatorProperty->setValue(null, null);
Translator::setLocale('en');
}
public function testLocale(): void
{
Translator::setLocale('en');
self::assertSame('en', Translator::getLocale());
Translator::setLocale('fr');
self::assertSame('fr', Translator::getLocale());
Translator::setLocale('');
self::assertSame('', Translator::getLocale());
}
/**
* @testWith [null, "en", "en"]
* [null, "fr", "fr"]
* ["en", "", "en"]
* ["fr", "", "fr"]
*/
public function testLoad(?string $globalLang, string $locale, string $expectedLocale): void
{
$loaderProperty = new ReflectionProperty(Translator::class, 'loader');
if (PHP_VERSION_ID < 80100) {
$loaderProperty->setAccessible(true);
}
$loaderProperty->setValue(null, null);
$translatorProperty = new ReflectionProperty(Translator::class, 'translator');
if (PHP_VERSION_ID < 80100) {
$translatorProperty->setAccessible(true);
}
$translatorProperty->setValue(null, null);
$GLOBALS['lang'] = $globalLang;
Translator::setLocale($locale);
Translator::load();
self::assertSame($expectedLocale, Translator::getLocale());
self::assertInstanceOf(MoTranslator::class, $translatorProperty->getValue());
$loader = $loaderProperty->getValue();
self::assertInstanceOf(Loader::class, $loader);
$loaderClass = new ReflectionClass(Loader::class);
$localeProperty = $loaderClass->getProperty('locale');
if (PHP_VERSION_ID < 80100) {
$localeProperty->setAccessible(true);
}
self::assertSame($expectedLocale, $localeProperty->getValue($loader));
// Compatibility with MoTranslator < 5
$defaultDomainProperty = $loaderClass->hasProperty('default_domain')
? $loaderClass->getProperty('default_domain')
: $loaderClass->getProperty('defaultDomain');
if (PHP_VERSION_ID < 80100) {
$defaultDomainProperty->setAccessible(true);
}
self::assertSame('sqlparser', $defaultDomainProperty->getValue($loader));
$pathsProperty = $loaderClass->getProperty('paths');
if (PHP_VERSION_ID < 80100) {
$pathsProperty->setAccessible(true);
}
self::assertSame(
['' => './', 'sqlparser' => realpath(__DIR__ . '/../../src/') . '/../locale/'],
$pathsProperty->getValue($loader)
);
}
public function testGettext(): void
{
$loaderProperty = new ReflectionProperty(Translator::class, 'loader');
if (PHP_VERSION_ID < 80100) {
$loaderProperty->setAccessible(true);
}
$loaderProperty->setValue(null, null);
$translatorProperty = new ReflectionProperty(Translator::class, 'translator');
if (PHP_VERSION_ID < 80100) {
$translatorProperty->setAccessible(true);
}
$translatorProperty->setValue(null, null);
Translator::setLocale('pt_BR');
self::assertSame(
'Início de declaração inesperado.',
Translator::gettext('Unexpected beginning of statement.')
);
$loaderProperty = new ReflectionProperty(Translator::class, 'loader');
if (PHP_VERSION_ID < 80100) {
$loaderProperty->setAccessible(true);
}
$loaderProperty->setValue(null, null);
$translatorProperty = new ReflectionProperty(Translator::class, 'translator');
if (PHP_VERSION_ID < 80100) {
$translatorProperty->setAccessible(true);
}
$translatorProperty->setValue(null, null);
Translator::setLocale('en');
self::assertSame(
'Unexpected beginning of statement.',
Translator::gettext('Unexpected beginning of statement.')
);
}
}