mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-25 06:44:33 +02:00
parent
1145fc118e
commit
e27e538bd9
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Util;
|
namespace Icinga\Util;
|
||||||
|
|
||||||
use \Exception;
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to ease internationalization when using gettext
|
* Helper class to ease internationalization when using gettext
|
||||||
|
78
test/php/library/Icinga/Util/TranslatorTest.php
Normal file
78
test/php/library/Icinga/Util/TranslatorTest.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Tests\Icinga\Util;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Icinga\Test\BaseTestCase;
|
||||||
|
use Icinga\Util\Translator;
|
||||||
|
|
||||||
|
class TranslatorTest extends BaseTestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Translator::registerDomain('icingatest', BaseTestCase::$testDir . '/res/locale');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWhetherGetAvailableLocaleCodesReturnsAllAvailableLocaleCodes()
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
array('de_DE', 'fr_FR'),
|
||||||
|
Translator::getAvailableLocaleCodes(),
|
||||||
|
'Translator::getAvailableLocaleCodes does not return all available locale codes'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWhetherSetupLocaleSetsUpTheGivenLocale()
|
||||||
|
{
|
||||||
|
Translator::setupLocale('de_DE');
|
||||||
|
$this->assertContains(
|
||||||
|
setlocale(LC_ALL, 0),
|
||||||
|
array('de_DE', 'de_DE.UTF-8'),
|
||||||
|
'Translator::setupLocale does not properly set up a given locale'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Exception
|
||||||
|
*/
|
||||||
|
public function testWhetherSetupLocaleThrowsAnExceptionWhenGivenAnInvalidLocale()
|
||||||
|
{
|
||||||
|
Translator::setupLocale('foobar');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWhetherSetupLocaleSetsCAsLocaleWhenGivenAnInvalidLocale()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Translator::setupLocale('foobar');
|
||||||
|
$this->fail('Translator::setupLocale does not throw an exception when given an invalid locale');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->assertEquals(
|
||||||
|
'C',
|
||||||
|
setlocale(LC_ALL, 0),
|
||||||
|
'Translator::setupLocale does not set C as locale in case the given one is invalid'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWhetherTranslateReturnsTheCorrectMessageForTheCurrentLocale()
|
||||||
|
{
|
||||||
|
Translator::setupLocale('de_DE');
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'Lorem ipsum dolor sit amet!',
|
||||||
|
Translator::translate('Lorem ipsum dolor sit amet', 'icingatest'),
|
||||||
|
'Translator::translate does not translate the given message correctly to German'
|
||||||
|
);
|
||||||
|
|
||||||
|
Translator::setupLocale('fr_FR');
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'Lorem ipsum dolor sit amet?',
|
||||||
|
Translator::translate('Lorem ipsum dolor sit amet', 'icingatest'),
|
||||||
|
'Translator::translate does not translate the given message correctly to French'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
BIN
test/php/res/locale/de_DE/LC_MESSAGES/icingatest.mo
Normal file
BIN
test/php/res/locale/de_DE/LC_MESSAGES/icingatest.mo
Normal file
Binary file not shown.
2
test/php/res/locale/de_DE/LC_MESSAGES/icingatest.po
Normal file
2
test/php/res/locale/de_DE/LC_MESSAGES/icingatest.po
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
msgid "Lorem ipsum dolor sit amet"
|
||||||
|
msgstr "Lorem ipsum dolor sit amet!"
|
BIN
test/php/res/locale/fr_FR/LC_MESSAGES/icingatest.mo
Normal file
BIN
test/php/res/locale/fr_FR/LC_MESSAGES/icingatest.mo
Normal file
Binary file not shown.
2
test/php/res/locale/fr_FR/LC_MESSAGES/icingatest.po
Normal file
2
test/php/res/locale/fr_FR/LC_MESSAGES/icingatest.po
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
msgid "Lorem ipsum dolor sit amet"
|
||||||
|
msgstr "Lorem ipsum dolor sit amet?"
|
Loading…
x
Reference in New Issue
Block a user