summaryrefslogtreecommitdiff
path: root/tests/Unit/Helpers
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-18 23:34:18 +0200
committermsquare <msquare@notrademark.de>2018-10-30 22:50:22 +0100
commitb443b53919f50bd0176e7b67dfd1efc28276a770 (patch)
treedf4d089d9d431f5223a71e6b40f9d87361705929 /tests/Unit/Helpers
parent90e1a949623ead173c0952f802d7b5c5487251b1 (diff)
Translation: added pluralization support
Diffstat (limited to 'tests/Unit/Helpers')
-rw-r--r--tests/Unit/Helpers/TranslatorTest.php43
1 files changed, 33 insertions, 10 deletions
diff --git a/tests/Unit/Helpers/TranslatorTest.php b/tests/Unit/Helpers/TranslatorTest.php
index 396d2b65..34050e42 100644
--- a/tests/Unit/Helpers/TranslatorTest.php
+++ b/tests/Unit/Helpers/TranslatorTest.php
@@ -10,12 +10,12 @@ 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()
+ * @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()
{
@@ -47,7 +47,8 @@ class TranslatorTest extends ServiceProviderTest
}
/**
- * @covers \Engelsystem\Helpers\Translator::translate()
+ * @covers \Engelsystem\Helpers\Translator::translate
+ * @covers \Engelsystem\Helpers\Translator::replaceText
*/
public function testTranslate()
{
@@ -56,14 +57,36 @@ class TranslatorTest extends ServiceProviderTest
->setConstructorArgs(['de_DE.UTF-8', ['de_DE.UTF-8' => 'Deutsch']])
->setMethods(['translateGettext'])
->getMock();
- $translator->expects($this->once())
+ $translator->expects($this->exactly(2))
->method('translateGettext')
- ->with('My favourite number is %u!')
- ->willReturn('Meine Lieblingszahl ist die %u!');
+ ->withConsecutive(['Hello!'], ['My favourite number is %u!'])
+ ->willReturnOnConsecutiveCalls('Hallo!', 'Meine Lieblingszahl ist die %u!');
+
+ $return = $translator->translate('Hello!');
+ $this->assertEquals('Hallo!', $return);
$return = $translator->translate('My favourite number is %u!', [3]);
$this->assertEquals('Meine Lieblingszahl ist die 3!', $return);
}
+
+ /**
+ * @covers \Engelsystem\Helpers\Translator::translatePlural
+ */
+ public function testTranslatePlural()
+ {
+ /** @var Translator|MockObject $translator */
+ $translator = $this->getMockBuilder(Translator::class)
+ ->setConstructorArgs(['de_DE.UTF-8', ['de_DE.UTF-8' => 'Deutsch']])
+ ->setMethods(['translateGettextPlural'])
+ ->getMock();
+ $translator->expects($this->once())
+ ->method('translateGettextPlural')
+ ->with('%s apple', '%s apples', 2)
+ ->willReturn('2 Äpfel');
+
+ $return = $translator->translatePlural('%s apple', '%s apples', 2, [2]);
+ $this->assertEquals('2 Äpfel', $return);
+ }
}