-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translator_Atk4Trait_Test.php
executable file
·81 lines (63 loc) · 2.02 KB
/
Translator_Atk4Trait_Test.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace I18Next\Tests;
use atk4\core\AppScopeTrait;
use atk4\core\ContainerTrait;
use atk4\core\Exception;
use atk4\core\InitializerTrait;
use I18Next\atk4\TranslatorI18NextTrait;
class Translator_Atk4Trait_Test extends TranslatorBaseCase
{
public function testBase()
{
$this->setupTranslatorLanguages('it', 'en');
$app = new ATK4AppScopeMock();
$app->setTranslator($this->translator);
$result = $app->_('friend');
$this->assertEquals('Un conoscente', $result);
$app->add($child = new ATK4ChildMock());
$result = $child->_('friend', null, null, 'en');
$this->assertEquals('A friend', $result);
$this->translator->addLanguage('ro');
$result = $child->_('friend', null, null, 'ro');
$this->assertEquals('Un prieten', $result);
}
public function testException()
{
$this->expectException(Exception::class);
$app = new ATK4AppScopeMock();
$app->_('friend');
}
public function testDirect()
{
$this->setupTranslatorLanguages('it', 'en');
$app = new ATK4AppScopeMock();
$app->setTranslator($this->translator);
$result = $app->_('Ho trovato, $t(friend)');
$this->assertEquals('Ho trovato, Un conoscente', $result);
}
}
// @codingStandardsIgnoreStart
class ATK4AppScopeMock
{
use AppScopeTrait;
use ContainerTrait;
use TranslatorI18NextTrait;
public function __construct()
{
$this->app = $this;
}
}
class ATK4ChildMock
{
use AppScopeTrait;
use InitializerTrait;
// simulate the PR TranslatableTrait
public function _($message, ?array $parameters = null, ?string $domain = null, ?string $locale = null): string
{
if (isset($this->app) && method_exists($this->app, '_')) {
return $this->app->_($message, $parameters, $domain, $locale);
}
throw new Exception('App not recognized, something went wrong with simulation of TranslatableTrait');
}
}
// @codingStandardsIgnoreEnd