-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Translator::setLocale() takes precedence over $GLOBALS['lang']. This makes possible to deprecate the usage of the $GLOBALS['lang']. Signed-off-by: Maurício Meneghini Fauth <[email protected]>
- Loading branch information
1 parent
0923ebf
commit d34538c
Showing
4 changed files
with
135 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?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; | ||
|
||
/** @covers \PhpMyAdmin\SqlParser\Translator */ | ||
final class TranslatorTest extends TestCase | ||
{ | ||
public static function tearDownAfterClass(): void | ||
{ | ||
$loaderProperty = new ReflectionProperty(Translator::class, 'loader'); | ||
$loaderProperty->setAccessible(true); | ||
$loaderProperty->setValue(null, null); | ||
$translatorProperty = new ReflectionProperty(Translator::class, 'translator'); | ||
$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'); | ||
$loaderProperty->setAccessible(true); | ||
$loaderProperty->setValue(null, null); | ||
$translatorProperty = new ReflectionProperty(Translator::class, 'translator'); | ||
$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'); | ||
$localeProperty->setAccessible(true); | ||
self::assertSame($expectedLocale, $localeProperty->getValue($loader)); | ||
$defaultDomainProperty = $loaderClass->getProperty('defaultDomain'); | ||
$defaultDomainProperty->setAccessible(true); | ||
self::assertSame('sqlparser', $defaultDomainProperty->getValue($loader)); | ||
$pathsProperty = $loaderClass->getProperty('paths'); | ||
$pathsProperty->setAccessible(true); | ||
self::assertSame( | ||
['' => './', 'sqlparser' => realpath(__DIR__ . '/../../src/') . '/../locale/'], | ||
$pathsProperty->getValue($loader) | ||
); | ||
} | ||
|
||
public function testGettext(): void | ||
{ | ||
$loaderProperty = new ReflectionProperty(Translator::class, 'loader'); | ||
$loaderProperty->setAccessible(true); | ||
$loaderProperty->setValue(null, null); | ||
$translatorProperty = new ReflectionProperty(Translator::class, 'translator'); | ||
$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'); | ||
$loaderProperty->setAccessible(true); | ||
$loaderProperty->setValue(null, null); | ||
$translatorProperty = new ReflectionProperty(Translator::class, 'translator'); | ||
$translatorProperty->setAccessible(true); | ||
$translatorProperty->setValue(null, null); | ||
Translator::setLocale('en'); | ||
self::assertSame( | ||
'Unexpected beginning of statement.', | ||
Translator::gettext('Unexpected beginning of statement.') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters