blob: 825cf5b749d873f66aa7b890bc824c23ce073dc1 (
plain)
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
|
<?php
namespace Engelsystem\Test\Unit\Helpers\Translation;
use Engelsystem\Helpers\Translation\GettextTranslator;
use Engelsystem\Helpers\Translation\TranslationNotFound;
use Engelsystem\Test\Unit\ServiceProviderTest;
use Gettext\Translation;
use Gettext\Translations;
class GettextTranslatorTest extends ServiceProviderTest
{
/**
* @covers \Engelsystem\Helpers\Translation\GettextTranslator::assertHasTranslation()
*/
public function testNoTranslation()
{
$translations = $this->getTranslations();
$translator = new GettextTranslator();
$translator->loadTranslations($translations);
$this->assertEquals('Translation!', $translator->gettext('test.value'));
$this->expectException(TranslationNotFound::class);
$this->expectExceptionMessage('//foo.bar');
$translator->gettext('foo.bar');
}
/**
* @covers \Engelsystem\Helpers\Translation\GettextTranslator::dpgettext()
*/
public function testDpgettext()
{
$translations = $this->getTranslations();
$translator = new GettextTranslator();
$translator->loadTranslations($translations);
$this->assertEquals('Translation!', $translator->dpgettext(null, null, 'test.value'));
}
/**
* @covers \Engelsystem\Helpers\Translation\GettextTranslator::dnpgettext()
*/
public function testDnpgettext()
{
$translations = $this->getTranslations();
$translator = new GettextTranslator();
$translator->loadTranslations($translations);
$this->assertEquals('Translations!', $translator->dnpgettext(null, null, 'test.value', 'test.values', 2));
}
protected function getTranslations(): Translations
{
$translations = new Translations();
$translations[] =
(new Translation(null, 'test.value', 'test.values'))
->setTranslation('Translation!')
->setPluralTranslations(['Translations!']);
return $translations;
}
}
|