|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Efabrica\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
8
|
|
|
use Efabrica\Translatte\Translator; |
|
9
|
|
|
use Efabrica\Translatte\Resource\NeonDirectoryResource; |
|
10
|
|
|
|
|
11
|
|
|
class TranslatorTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testLanguage(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$translator = new Translator('sk_SK'); |
|
16
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
|
17
|
|
|
$this->assertSame("Akcie", $translator->translate('dictionary.app.article.actions')); |
|
18
|
|
|
$this->assertSame("Actions", $translator->translate('dictionary.app.article.actions', 1, [], 'en_US')); |
|
19
|
|
|
$this->assertSame("Actions", $translator->translate('dictionary.app.article.actions', [], 'en_US')); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testParams(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$translator = new Translator('sk_SK'); |
|
25
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
|
26
|
|
|
$this->assertSame( |
|
27
|
|
|
"Naozaj chcete odstrániť článok <strong>Article no.1</strong>?", |
|
28
|
|
|
$translator->translate('dictionary.app.article.are_you_sure_you_want_to_delete_article', ['articleTitle' => 'Article no.1']) |
|
29
|
|
|
); |
|
30
|
|
|
$this->assertSame( |
|
31
|
|
|
"Are you sure you want to delete the article <strong>Article no.1</strong>?", |
|
32
|
|
|
$translator->translate('dictionary.app.article.are_you_sure_you_want_to_delete_article', 1, ['articleTitle' => 'Article no.1'], 'en_US') |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testCount(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$translator = new Translator('sk_SK'); |
|
39
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
|
40
|
|
|
$this->assertSame("článok", $translator->translate('dictionary.app.article.articles_count')); |
|
41
|
|
|
$this->assertSame("články", $translator->translate('dictionary.app.article.articles_count', 4)); |
|
42
|
|
|
$this->assertSame("článkov", $translator->translate('dictionary.app.article.articles_count', 100)); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertSame("article", $translator->translate('dictionary.app.article.articles_count', 1, [], 'en_US')); |
|
45
|
|
|
$this->assertSame("articles", $translator->translate('dictionary.app.article.articles_count', 4, [], 'en_US')); |
|
46
|
|
|
$this->assertSame("articles", $translator->translate('dictionary.app.article.articles_count', 99, [], 'en_US')); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testCountWithPlaceholder(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$translator = new Translator('sk_SK'); |
|
52
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
|
53
|
|
|
$this->assertSame("1 článok", $translator->translate('dictionary.app.article.articles_count_with_placeholder')); |
|
54
|
|
|
$this->assertSame("4 články", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 4)); |
|
55
|
|
|
$this->assertSame("100 článkov", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 100)); |
|
56
|
|
|
$this->assertSame("4 články", $translator->translate('dictionary.app.article.articles_count_with_placeholder', ['count' => 4])); |
|
57
|
|
|
$this->assertSame("100 článkov", $translator->translate('dictionary.app.article.articles_count_with_placeholder', ['count' => 100])); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertSame("1 article", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 1, [], 'en_US')); |
|
60
|
|
|
$this->assertSame("4 articles", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 4, [], 'en_US')); |
|
61
|
|
|
$this->assertSame("99 articles", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 99, [], 'en_US')); |
|
62
|
|
|
$this->assertSame("4 articles", $translator->translate('dictionary.app.article.articles_count_with_placeholder', ['count' => 4], 'en_US')); |
|
63
|
|
|
$this->assertSame("99 articles", $translator->translate('dictionary.app.article.articles_count_with_placeholder', ['count' => 99], 'en_US')); |
|
64
|
|
|
|
|
65
|
|
|
// Count has higher priority for plural form as parameter count (but dont replace count parameter in params array) |
|
66
|
|
|
$this->assertSame("100 články", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 3, ['count' => 100])); |
|
67
|
|
|
$this->assertSame("4 article", $translator->translate('dictionary.app.article.articles_count_with_placeholder', 1, ['count' => 4], 'en_US')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testAll(): void |
|
71
|
|
|
{ |
|
72
|
|
|
$skParams = ['category' => 'Novinky', 'section' => 'Článnky']; |
|
73
|
|
|
$enParams = ['category' => 'News', 'section' => 'Articles']; |
|
74
|
|
|
|
|
75
|
|
|
$translator = new Translator('sk_SK'); |
|
76
|
|
|
$translator->addResource(new NeonDirectoryResource([__DIR__ . '/translations'])); |
|
77
|
|
|
$this->assertSame("článok v kategórii Novinky a sekcii Článnky", $translator->translate('dictionary.app.article.articles_count_with_params', $skParams)); |
|
78
|
|
|
$this->assertSame("články v kategórii Novinky a sekcii Článnky", $translator->translate('dictionary.app.article.articles_count_with_params', 4, $skParams)); |
|
79
|
|
|
$this->assertSame("článkov v kategórii Novinky a sekcii Článnky", $translator->translate('dictionary.app.article.articles_count_with_params', 100, $skParams)); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertSame("article in category News and section Articles", $translator->translate('dictionary.app.article.articles_count_with_params', 1, $enParams, 'en_US')); |
|
82
|
|
|
$this->assertSame("articles in category News and section Articles", $translator->translate('dictionary.app.article.articles_count_with_params', 4, $enParams, 'en_US')); |
|
83
|
|
|
$this->assertSame("articles in category News and section Articles", $translator->translate('dictionary.app.article.articles_count_with_params', 99, $enParams, 'en_US')); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths