1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Translation\Bundle\Tests\Unit\Catalogue; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
15
|
|
|
use Symfony\Component\Translation\MessageCatalogue; |
16
|
|
|
use Translation\Bundle\Catalogue\CatalogueManager; |
17
|
|
|
use Translation\Bundle\Model\CatalogueMessage; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Tobias Nyholm <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class CatalogueManagerTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
public function testGetMessages(): void |
25
|
|
|
{ |
26
|
|
|
$manager = new CatalogueManager(); |
27
|
|
|
$catA = new MessageCatalogue('en', ['messages' => ['a' => 'aTrans', 'b' => 'bTrans']]); |
28
|
|
|
$catB = new MessageCatalogue('fr', ['messages' => ['a' => 'aTransFr', 'c' => 'cTransFr', 'd' => 'dTransFr']]); |
29
|
|
|
$manager->load([$catA, $catB]); |
30
|
|
|
$messages = $manager->getMessages('en', 'messages'); |
31
|
|
|
|
32
|
|
|
$this->assertCount(2, $messages); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testFindMessagesNoMetadata(): void |
36
|
|
|
{ |
37
|
|
|
$manager = new CatalogueManager(); |
38
|
|
|
$catA = new MessageCatalogue('en', ['messages' => ['a' => 'aTrans', 'b' => 'bTrans']]); |
39
|
|
|
$catB = new MessageCatalogue('fr', ['messages' => ['a' => 'aTransFr', 'c' => 'cTransFr']]); |
40
|
|
|
$manager->load([$catA, $catB]); |
41
|
|
|
$messages = $manager->findMessages(['locale' => 'en']); |
42
|
|
|
|
43
|
|
|
$this->assertCount(2, $messages); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testFindMessages(): void |
47
|
|
|
{ |
48
|
|
|
$manager = new CatalogueManager(); |
49
|
|
|
$catA = new MessageCatalogue('en', ['messages' => ['a' => 'aTrans', 'b' => 'bTrans', 'c' => 'cTrans', 'd' => 'dTrans']]); |
50
|
|
|
$catA->setMetadata('a', ['notes' => [['category' => 'state', 'content' => 'new']]]); |
51
|
|
|
$catA->setMetadata('b', ['notes' => [['category' => 'state', 'content' => 'obsolete']]]); |
52
|
|
|
$catA->setMetadata('d', ['notes' => [['category' => 'approved', 'content' => 'true']]]); |
53
|
|
|
|
54
|
|
|
$catB = new MessageCatalogue('fr', ['messages' => ['a' => 'aTransFr', 'c' => 'cTransFr', 'e' => 'eTransFr']]); |
55
|
|
|
$catB->setMetadata('c', ['notes' => [['category' => 'approved', 'content' => 'true']]]); |
56
|
|
|
$catB->setMetadata('e', ['notes' => [['category' => 'approved', 'content' => 'true']]]); |
57
|
|
|
|
58
|
|
|
$manager->load([$catA, $catB]); |
59
|
|
|
|
60
|
|
|
// Only one approved en message |
61
|
|
|
$messages = $manager->findMessages(['locale' => 'en', 'isApproved' => true]); |
62
|
|
|
$this->assertCount(1, $messages); |
63
|
|
|
$messages = \array_values($messages); |
64
|
|
|
$this->assertEquals('d', $messages[0]->getKey()); |
65
|
|
|
|
66
|
|
|
$messages = $manager->findMessages(['isApproved' => true]); |
67
|
|
|
$this->assertCount(3, $messages); |
68
|
|
|
$keys = \array_map(function (CatalogueMessage $message) { |
69
|
|
|
return $message->getKey(); |
70
|
|
|
}, $messages); |
71
|
|
|
$this->assertContains('c', $keys); |
72
|
|
|
$this->assertContains('d', $keys); |
73
|
|
|
$this->assertContains('e', $keys); |
74
|
|
|
|
75
|
|
|
$messages = $manager->findMessages(['isNew' => true]); |
76
|
|
|
$this->assertCount(1, $messages); |
77
|
|
|
$messages = \array_values($messages); |
78
|
|
|
$this->assertEquals('a', $messages[0]->getKey()); |
79
|
|
|
|
80
|
|
|
$messages = $manager->findMessages(['isObsolete' => true]); |
81
|
|
|
$this->assertCount(1, $messages); |
82
|
|
|
$messages = \array_values($messages); |
83
|
|
|
$this->assertEquals('b', $messages[0]->getKey()); |
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