1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Translation\Tests\Catalogue;
13
14use Symfony\Component\Translation\Catalogue\TargetOperation;
15use Symfony\Component\Translation\MessageCatalogue;
16use Symfony\Component\Translation\MessageCatalogueInterface;
17
18class TargetOperationTest extends AbstractOperationTest
19{
20    public function testGetMessagesFromSingleDomain()
21    {
22        $operation = $this->createOperation(
23            new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]),
24            new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'c' => 'new_c']])
25        );
26
27        $this->assertEquals(
28            ['a' => 'old_a', 'c' => 'new_c'],
29            $operation->getMessages('messages')
30        );
31
32        $this->assertEquals(
33            ['c' => 'new_c'],
34            $operation->getNewMessages('messages')
35        );
36
37        $this->assertEquals(
38            ['b' => 'old_b'],
39            $operation->getObsoleteMessages('messages')
40        );
41    }
42
43    public function testGetResultFromSingleDomain()
44    {
45        $this->assertEquals(
46            new MessageCatalogue('en', [
47                'messages' => ['a' => 'old_a', 'c' => 'new_c'],
48            ]),
49            $this->createOperation(
50                new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]),
51                new MessageCatalogue('en', ['messages' => ['a' => 'new_a', 'c' => 'new_c']])
52            )->getResult()
53        );
54    }
55
56    public function testGetResultWithMetadata()
57    {
58        $leftCatalogue = new MessageCatalogue('en', ['messages' => ['a' => 'old_a', 'b' => 'old_b']]);
59        $leftCatalogue->setMetadata('a', 'foo', 'messages');
60        $leftCatalogue->setMetadata('b', 'bar', 'messages');
61        $rightCatalogue = new MessageCatalogue('en', ['messages' => ['b' => 'new_b', 'c' => 'new_c']]);
62        $rightCatalogue->setMetadata('b', 'baz', 'messages');
63        $rightCatalogue->setMetadata('c', 'qux', 'messages');
64
65        $diffCatalogue = new MessageCatalogue('en', ['messages' => ['b' => 'old_b', 'c' => 'new_c']]);
66        $diffCatalogue->setMetadata('b', 'bar', 'messages');
67        $diffCatalogue->setMetadata('c', 'qux', 'messages');
68
69        $this->assertEquals(
70            $diffCatalogue,
71            $this->createOperation(
72                $leftCatalogue,
73                $rightCatalogue
74            )->getResult()
75        );
76    }
77
78    protected function createOperation(MessageCatalogueInterface $source, MessageCatalogueInterface $target)
79    {
80        return new TargetOperation($source, $target);
81    }
82}
83