summaryrefslogtreecommitdiff
path: root/tests/Unit/Helpers/TranslatorTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-08-28 22:23:59 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-08-29 23:46:31 +0200
commit427315195bdd379a0207fc9b2aaf69a5b5b86c79 (patch)
tree678245351333a16c5a5bca129aada4bfd311c23c /tests/Unit/Helpers/TranslatorTest.php
parentdf6360044b5c2396b2bee0dfa9e8d744bfa424d5 (diff)
Moved translation/internationalization to Helpers\Translator class
Diffstat (limited to 'tests/Unit/Helpers/TranslatorTest.php')
-rw-r--r--tests/Unit/Helpers/TranslatorTest.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/Unit/Helpers/TranslatorTest.php b/tests/Unit/Helpers/TranslatorTest.php
new file mode 100644
index 00000000..396d2b65
--- /dev/null
+++ b/tests/Unit/Helpers/TranslatorTest.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers;
+
+use Engelsystem\Helpers\Translator;
+use Engelsystem\Test\Unit\ServiceProviderTest;
+use PHPUnit\Framework\MockObject\MockObject;
+use stdClass;
+
+class TranslatorTest extends ServiceProviderTest
+{
+ /**
+ * @covers \Engelsystem\Helpers\Translator::__construct()
+ * @covers \Engelsystem\Helpers\Translator::setLocale()
+ * @covers \Engelsystem\Helpers\Translator::setLocales()
+ * @covers \Engelsystem\Helpers\Translator::getLocale()
+ * @covers \Engelsystem\Helpers\Translator::getLocales()
+ * @covers \Engelsystem\Helpers\Translator::hasLocale()
+ */
+ public function testInit()
+ {
+ $locales = ['te_ST.ER-01' => 'Tests', 'fo_OO' => 'SomeFOO'];
+ $locale = 'te_ST.ER-01';
+
+ /** @var callable|MockObject $callable */
+ $callable = $this->getMockBuilder(stdClass::class)
+ ->setMethods(['__invoke'])
+ ->getMock();
+ $callable->expects($this->exactly(2))
+ ->method('__invoke')
+ ->withConsecutive(['te_ST.ER-01'], ['fo_OO']);
+
+ $translator = new Translator($locale, $locales, $callable);
+
+ $this->assertEquals($locales, $translator->getLocales());
+ $this->assertEquals($locale, $translator->getLocale());
+
+ $translator->setLocale('fo_OO');
+ $this->assertEquals('fo_OO', $translator->getLocale());
+
+ $newLocales = ['lo_RM' => 'Lorem', 'ip_SU-M' => 'Ipsum'];
+ $translator->setLocales($newLocales);
+ $this->assertEquals($newLocales, $translator->getLocales());
+
+ $this->assertTrue($translator->hasLocale('ip_SU-M'));
+ $this->assertFalse($translator->hasLocale('te_ST.ER-01'));
+ }
+
+ /**
+ * @covers \Engelsystem\Helpers\Translator::translate()
+ */
+ public function testTranslate()
+ {
+ /** @var Translator|MockObject $translator */
+ $translator = $this->getMockBuilder(Translator::class)
+ ->setConstructorArgs(['de_DE.UTF-8', ['de_DE.UTF-8' => 'Deutsch']])
+ ->setMethods(['translateGettext'])
+ ->getMock();
+ $translator->expects($this->once())
+ ->method('translateGettext')
+ ->with('My favourite number is %u!')
+ ->willReturn('Meine Lieblingszahl ist die %u!');
+
+ $return = $translator->translate('My favourite number is %u!', [3]);
+ $this->assertEquals('Meine Lieblingszahl ist die 3!', $return);
+ }
+}
+
+