Completed
Push — master ( 659b14...17b09c )
by Tobias
07:00
created

XliffLoaderTest::testXliff12()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
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\SymfonyStorage\Tests\Unit\Loader;
13
14
use PHPUnit\Framework\TestCase;
15
use Symfony\Component\HttpKernel\Kernel;
16
use Symfony\Component\Translation\Exception\InvalidResourceException;
17
use Symfony\Component\Translation\MessageCatalogue;
18
use Translation\SymfonyStorage\Loader\XliffLoader;
19
20
/**
21
 * @author Tobias Nyholm <[email protected]>
22
 */
23
class XliffLoaderTest extends TestCase
24
{
25
    /**
26
     * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
27
     */
28
    public function testEmptyContent()
29
    {
30
        $loader = new XliffLoader();
31
        $loader->extractFromContent(' ', new MessageCatalogue('en'), 'messages');
32
    }
33
34
    public function testInvalidContent()
35
    {
36
        $loader = new XliffLoader();
37
38
        try {
39
            $loader->extractFromContent('Foobar', new MessageCatalogue('en'), 'messages');
40
        } catch (InvalidResourceException $e) {
41
            $invalidArgument = $e->getPrevious();
42
            $this->assertNotNull($invalidArgument);
43
            $this->assertContains('[ERROR 4] Start tag expected', $invalidArgument->getMessage());
44
45
            return;
46
        }
47
        $this->fail('XliffLoader must throw exception on invalid XML');
48
    }
49
50 View Code Duplication
    public function testXliff12()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        if (Kernel::VERSION_ID < 20800) {
53
            $this->markTestSkipped('Symfony <2.8 is not supported. ');
54
        }
55
56
        $content = file_get_contents(__DIR__.'/../../Fixtures/single-file/messages.en.xlf');
57
        $catalogue = new MessageCatalogue('en');
58
        (new XliffLoader())->extractFromContent($content, $catalogue, 'messages');
59
        $this->assertTrue($catalogue->defines('test_0'));
60
        $this->assertTrue($catalogue->defines('test_1'));
61
    }
62
63 View Code Duplication
    public function testXliff20()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        if (Kernel::VERSION_ID < 20800) {
66
            $this->markTestSkipped('Symfony <2.8 is not supported. ');
67
        }
68
69
        $content = <<<'XML'
70
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0"
71
 srcLang="en-US" trgLang="sv">
72
 <file id="f1" original="Example">
73
  <skeleton href="Example"/>
74
  <unit id="1">
75
   <segment>
76
    <source>key0</source>
77
    <target>Foo</target>
78
   </segment>
79
  </unit>
80
  <unit id="2">
81
   <segment>
82
    <source>key1</source>
83
    <target>Bar</target>
84
   </segment>
85
  </unit>
86
 </file>
87
</xliff>
88
XML;
89
90
        $catalogue = new MessageCatalogue('en');
91
        (new XliffLoader())->extractFromContent($content, $catalogue, 'messages');
92
        $this->assertTrue($catalogue->defines('key0'));
93
        $this->assertTrue($catalogue->defines('key1'));
94
    }
95
}
96