Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

Application modulaire fonctionnelle !

Emmanuel ROY authored on 12/08/2019 15:10:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,331 +0,0 @@
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
-
12
-namespace Symfony\Component\Translation\Tests\Loader;
13
-
14
-use PHPUnit\Framework\TestCase;
15
-use Symfony\Component\Config\Resource\FileResource;
16
-use Symfony\Component\Translation\Loader\XliffFileLoader;
17
-
18
-class XliffFileLoaderTest extends TestCase
19
-{
20
-    public function testLoad()
21
-    {
22
-        $loader = new XliffFileLoader();
23
-        $resource = __DIR__.'/../fixtures/resources.xlf';
24
-        $catalogue = $loader->load($resource, 'en', 'domain1');
25
-
26
-        $this->assertEquals('en', $catalogue->getLocale());
27
-        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
28
-        $this->assertSame([], libxml_get_errors());
29
-        $this->assertContainsOnly('string', $catalogue->all('domain1'));
30
-    }
31
-
32
-    public function testLoadWithInternalErrorsEnabled()
33
-    {
34
-        $internalErrors = libxml_use_internal_errors(true);
35
-
36
-        $this->assertSame([], libxml_get_errors());
37
-
38
-        $loader = new XliffFileLoader();
39
-        $resource = __DIR__.'/../fixtures/resources.xlf';
40
-        $catalogue = $loader->load($resource, 'en', 'domain1');
41
-
42
-        $this->assertEquals('en', $catalogue->getLocale());
43
-        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
44
-        $this->assertSame([], libxml_get_errors());
45
-
46
-        libxml_clear_errors();
47
-        libxml_use_internal_errors($internalErrors);
48
-    }
49
-
50
-    public function testLoadWithExternalEntitiesDisabled()
51
-    {
52
-        $disableEntities = libxml_disable_entity_loader(true);
53
-
54
-        $loader = new XliffFileLoader();
55
-        $resource = __DIR__.'/../fixtures/resources.xlf';
56
-        $catalogue = $loader->load($resource, 'en', 'domain1');
57
-
58
-        libxml_disable_entity_loader($disableEntities);
59
-
60
-        $this->assertEquals('en', $catalogue->getLocale());
61
-        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
62
-    }
63
-
64
-    public function testLoadWithResname()
65
-    {
66
-        $loader = new XliffFileLoader();
67
-        $catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1');
68
-
69
-        $this->assertEquals(['foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'], $catalogue->all('domain1'));
70
-    }
71
-
72
-    public function testIncompleteResource()
73
-    {
74
-        $loader = new XliffFileLoader();
75
-        $catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
76
-
77
-        $this->assertEquals(['foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'], $catalogue->all('domain1'));
78
-    }
79
-
80
-    public function testEncoding()
81
-    {
82
-        $loader = new XliffFileLoader();
83
-        $catalogue = $loader->load(__DIR__.'/../fixtures/encoding.xlf', 'en', 'domain1');
84
-
85
-        $this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1'));
86
-        $this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1'));
87
-        $this->assertEquals(
88
-            [
89
-                'source' => 'foo',
90
-                'notes' => [['content' => utf8_decode('bäz')]],
91
-                'id' => '1',
92
-                'file' => [
93
-                    'original' => 'file.ext',
94
-                ],
95
-            ],
96
-            $catalogue->getMetadata('foo', 'domain1')
97
-        );
98
-    }
99
-
100
-    public function testTargetAttributesAreStoredCorrectly()
101
-    {
102
-        $loader = new XliffFileLoader();
103
-        $catalogue = $loader->load(__DIR__.'/../fixtures/with-attributes.xlf', 'en', 'domain1');
104
-
105
-        $metadata = $catalogue->getMetadata('foo', 'domain1');
106
-        $this->assertEquals('translated', $metadata['target-attributes']['state']);
107
-    }
108
-
109
-    /**
110
-     * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
111
-     */
112
-    public function testLoadInvalidResource()
113
-    {
114
-        $loader = new XliffFileLoader();
115
-        $loader->load(__DIR__.'/../fixtures/resources.php', 'en', 'domain1');
116
-    }
117
-
118
-    /**
119
-     * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
120
-     */
121
-    public function testLoadResourceDoesNotValidate()
122
-    {
123
-        $loader = new XliffFileLoader();
124
-        $loader->load(__DIR__.'/../fixtures/non-valid.xlf', 'en', 'domain1');
125
-    }
126
-
127
-    /**
128
-     * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
129
-     */
130
-    public function testLoadNonExistingResource()
131
-    {
132
-        $loader = new XliffFileLoader();
133
-        $resource = __DIR__.'/../fixtures/non-existing.xlf';
134
-        $loader->load($resource, 'en', 'domain1');
135
-    }
136
-
137
-    /**
138
-     * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
139
-     */
140
-    public function testLoadThrowsAnExceptionIfFileNotLocal()
141
-    {
142
-        $loader = new XliffFileLoader();
143
-        $resource = 'http://example.com/resources.xlf';
144
-        $loader->load($resource, 'en', 'domain1');
145
-    }
146
-
147
-    /**
148
-     * @expectedException        \Symfony\Component\Translation\Exception\InvalidResourceException
149
-     * @expectedExceptionMessage Document types are not allowed.
150
-     */
151
-    public function testDocTypeIsNotAllowed()
152
-    {
153
-        $loader = new XliffFileLoader();
154
-        $loader->load(__DIR__.'/../fixtures/withdoctype.xlf', 'en', 'domain1');
155
-    }
156
-
157
-    public function testParseEmptyFile()
158
-    {
159
-        $loader = new XliffFileLoader();
160
-        $resource = __DIR__.'/../fixtures/empty.xlf';
161
-
162
-        if (method_exists($this, 'expectException')) {
163
-            $this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException');
164
-            $this->expectExceptionMessage(sprintf('Unable to load "%s":', $resource));
165
-        } else {
166
-            $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s":', $resource));
167
-        }
168
-
169
-        $loader->load($resource, 'en', 'domain1');
170
-    }
171
-
172
-    public function testLoadNotes()
173
-    {
174
-        $loader = new XliffFileLoader();
175
-        $catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1');
176
-
177
-        $this->assertEquals(
178
-            [
179
-                'source' => 'foo',
180
-                'notes' => [['priority' => 1, 'content' => 'foo']],
181
-                'id' => '1',
182
-                'file' => [
183
-                    'original' => 'file.ext',
184
-                ],
185
-            ],
186
-            $catalogue->getMetadata('foo', 'domain1')
187
-        );
188
-        // message without target
189
-        $this->assertEquals(
190
-            [
191
-                'source' => 'extrasource',
192
-                'notes' => [['content' => 'bar', 'from' => 'foo']],
193
-                'id' => '2',
194
-                'file' => [
195
-                    'original' => 'file.ext',
196
-                ],
197
-            ],
198
-            $catalogue->getMetadata('extra', 'domain1')
199
-        );
200
-        // message with empty target
201
-        $this->assertEquals(
202
-            [
203
-                'source' => 'key',
204
-                'notes' => [
205
-                    ['content' => 'baz'],
206
-                    ['priority' => 2, 'from' => 'bar', 'content' => 'qux'],
207
-                ],
208
-                'id' => '123',
209
-                'file' => [
210
-                    'original' => 'file.ext',
211
-                ],
212
-            ],
213
-            $catalogue->getMetadata('key', 'domain1')
214
-        );
215
-    }
216
-
217
-    public function testLoadVersion2()
218
-    {
219
-        $loader = new XliffFileLoader();
220
-        $resource = __DIR__.'/../fixtures/resources-2.0.xlf';
221
-        $catalogue = $loader->load($resource, 'en', 'domain1');
222
-
223
-        $this->assertEquals('en', $catalogue->getLocale());
224
-        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
225
-        $this->assertSame([], libxml_get_errors());
226
-
227
-        $domains = $catalogue->all();
228
-        $this->assertCount(3, $domains['domain1']);
229
-        $this->assertContainsOnly('string', $catalogue->all('domain1'));
230
-
231
-        // target attributes
232
-        $this->assertEquals(['target-attributes' => ['order' => 1]], $catalogue->getMetadata('bar', 'domain1'));
233
-    }
234
-
235
-    public function testLoadVersion2WithNoteMeta()
236
-    {
237
-        $loader = new XliffFileLoader();
238
-        $resource = __DIR__.'/../fixtures/resources-notes-meta.xlf';
239
-        $catalogue = $loader->load($resource, 'en', 'domain1');
240
-
241
-        $this->assertEquals('en', $catalogue->getLocale());
242
-        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
243
-        $this->assertSame([], libxml_get_errors());
244
-
245
-        // test for "foo" metadata
246
-        $this->assertTrue($catalogue->defines('foo', 'domain1'));
247
-        $metadata = $catalogue->getMetadata('foo', 'domain1');
248
-        $this->assertNotEmpty($metadata);
249
-        $this->assertCount(3, $metadata['notes']);
250
-
251
-        $this->assertEquals('state', $metadata['notes'][0]['category']);
252
-        $this->assertEquals('new', $metadata['notes'][0]['content']);
253
-
254
-        $this->assertEquals('approved', $metadata['notes'][1]['category']);
255
-        $this->assertEquals('true', $metadata['notes'][1]['content']);
256
-
257
-        $this->assertEquals('section', $metadata['notes'][2]['category']);
258
-        $this->assertEquals('1', $metadata['notes'][2]['priority']);
259
-        $this->assertEquals('user login', $metadata['notes'][2]['content']);
260
-
261
-        // test for "baz" metadata
262
-        $this->assertTrue($catalogue->defines('baz', 'domain1'));
263
-        $metadata = $catalogue->getMetadata('baz', 'domain1');
264
-        $this->assertNotEmpty($metadata);
265
-        $this->assertCount(2, $metadata['notes']);
266
-
267
-        $this->assertEquals('x', $metadata['notes'][0]['id']);
268
-        $this->assertEquals('x_content', $metadata['notes'][0]['content']);
269
-
270
-        $this->assertEquals('target', $metadata['notes'][1]['appliesTo']);
271
-        $this->assertEquals('quality', $metadata['notes'][1]['category']);
272
-        $this->assertEquals('Fuzzy', $metadata['notes'][1]['content']);
273
-    }
274
-
275
-    public function testLoadVersion2WithMultiSegmentUnit()
276
-    {
277
-        $loader = new XliffFileLoader();
278
-        $resource = __DIR__.'/../fixtures/resources-2.0-multi-segment-unit.xlf';
279
-        $catalog = $loader->load($resource, 'en', 'domain1');
280
-
281
-        $this->assertSame('en', $catalog->getLocale());
282
-        $this->assertEquals([new FileResource($resource)], $catalog->getResources());
283
-        $this->assertFalse(libxml_get_last_error());
284
-
285
-        // test for "foo" metadata
286
-        $this->assertTrue($catalog->defines('foo', 'domain1'));
287
-        $metadata = $catalog->getMetadata('foo', 'domain1');
288
-        $this->assertNotEmpty($metadata);
289
-        $this->assertCount(1, $metadata['notes']);
290
-
291
-        $this->assertSame('processed', $metadata['notes'][0]['category']);
292
-        $this->assertSame('true', $metadata['notes'][0]['content']);
293
-
294
-        // test for "bar" metadata
295
-        $this->assertTrue($catalog->defines('bar', 'domain1'));
296
-        $metadata = $catalog->getMetadata('bar', 'domain1');
297
-        $this->assertNotEmpty($metadata);
298
-        $this->assertCount(1, $metadata['notes']);
299
-
300
-        $this->assertSame('processed', $metadata['notes'][0]['category']);
301
-        $this->assertSame('true', $metadata['notes'][0]['content']);
302
-    }
303
-
304
-    public function testLoadWithMultipleFileNodes()
305
-    {
306
-        $loader = new XliffFileLoader();
307
-        $catalogue = $loader->load(__DIR__.'/../fixtures/resources-multi-files.xlf', 'en', 'domain1');
308
-
309
-        $this->assertEquals(
310
-            [
311
-                'source' => 'foo',
312
-                'id' => '1',
313
-                'file' => [
314
-                    'original' => 'file.ext',
315
-                ],
316
-            ],
317
-            $catalogue->getMetadata('foo', 'domain1')
318
-        );
319
-        $this->assertEquals(
320
-            [
321
-                'source' => 'test',
322
-                'notes' => [['content' => 'note']],
323
-                'id' => '4',
324
-                'file' => [
325
-                    'original' => 'otherfile.ext',
326
-                ],
327
-            ],
328
-            $catalogue->getMetadata('test', 'domain1')
329
-        );
330
-    }
331
-}
Browse code

initial commit

Emmanuel ROY authored on 09/08/2019 08:39:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,331 @@
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
+
12
+namespace Symfony\Component\Translation\Tests\Loader;
13
+
14
+use PHPUnit\Framework\TestCase;
15
+use Symfony\Component\Config\Resource\FileResource;
16
+use Symfony\Component\Translation\Loader\XliffFileLoader;
17
+
18
+class XliffFileLoaderTest extends TestCase
19
+{
20
+    public function testLoad()
21
+    {
22
+        $loader = new XliffFileLoader();
23
+        $resource = __DIR__.'/../fixtures/resources.xlf';
24
+        $catalogue = $loader->load($resource, 'en', 'domain1');
25
+
26
+        $this->assertEquals('en', $catalogue->getLocale());
27
+        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
28
+        $this->assertSame([], libxml_get_errors());
29
+        $this->assertContainsOnly('string', $catalogue->all('domain1'));
30
+    }
31
+
32
+    public function testLoadWithInternalErrorsEnabled()
33
+    {
34
+        $internalErrors = libxml_use_internal_errors(true);
35
+
36
+        $this->assertSame([], libxml_get_errors());
37
+
38
+        $loader = new XliffFileLoader();
39
+        $resource = __DIR__.'/../fixtures/resources.xlf';
40
+        $catalogue = $loader->load($resource, 'en', 'domain1');
41
+
42
+        $this->assertEquals('en', $catalogue->getLocale());
43
+        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
44
+        $this->assertSame([], libxml_get_errors());
45
+
46
+        libxml_clear_errors();
47
+        libxml_use_internal_errors($internalErrors);
48
+    }
49
+
50
+    public function testLoadWithExternalEntitiesDisabled()
51
+    {
52
+        $disableEntities = libxml_disable_entity_loader(true);
53
+
54
+        $loader = new XliffFileLoader();
55
+        $resource = __DIR__.'/../fixtures/resources.xlf';
56
+        $catalogue = $loader->load($resource, 'en', 'domain1');
57
+
58
+        libxml_disable_entity_loader($disableEntities);
59
+
60
+        $this->assertEquals('en', $catalogue->getLocale());
61
+        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
62
+    }
63
+
64
+    public function testLoadWithResname()
65
+    {
66
+        $loader = new XliffFileLoader();
67
+        $catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1');
68
+
69
+        $this->assertEquals(['foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo', 'qux' => 'qux source'], $catalogue->all('domain1'));
70
+    }
71
+
72
+    public function testIncompleteResource()
73
+    {
74
+        $loader = new XliffFileLoader();
75
+        $catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');
76
+
77
+        $this->assertEquals(['foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'], $catalogue->all('domain1'));
78
+    }
79
+
80
+    public function testEncoding()
81
+    {
82
+        $loader = new XliffFileLoader();
83
+        $catalogue = $loader->load(__DIR__.'/../fixtures/encoding.xlf', 'en', 'domain1');
84
+
85
+        $this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1'));
86
+        $this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1'));
87
+        $this->assertEquals(
88
+            [
89
+                'source' => 'foo',
90
+                'notes' => [['content' => utf8_decode('bäz')]],
91
+                'id' => '1',
92
+                'file' => [
93
+                    'original' => 'file.ext',
94
+                ],
95
+            ],
96
+            $catalogue->getMetadata('foo', 'domain1')
97
+        );
98
+    }
99
+
100
+    public function testTargetAttributesAreStoredCorrectly()
101
+    {
102
+        $loader = new XliffFileLoader();
103
+        $catalogue = $loader->load(__DIR__.'/../fixtures/with-attributes.xlf', 'en', 'domain1');
104
+
105
+        $metadata = $catalogue->getMetadata('foo', 'domain1');
106
+        $this->assertEquals('translated', $metadata['target-attributes']['state']);
107
+    }
108
+
109
+    /**
110
+     * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
111
+     */
112
+    public function testLoadInvalidResource()
113
+    {
114
+        $loader = new XliffFileLoader();
115
+        $loader->load(__DIR__.'/../fixtures/resources.php', 'en', 'domain1');
116
+    }
117
+
118
+    /**
119
+     * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
120
+     */
121
+    public function testLoadResourceDoesNotValidate()
122
+    {
123
+        $loader = new XliffFileLoader();
124
+        $loader->load(__DIR__.'/../fixtures/non-valid.xlf', 'en', 'domain1');
125
+    }
126
+
127
+    /**
128
+     * @expectedException \Symfony\Component\Translation\Exception\NotFoundResourceException
129
+     */
130
+    public function testLoadNonExistingResource()
131
+    {
132
+        $loader = new XliffFileLoader();
133
+        $resource = __DIR__.'/../fixtures/non-existing.xlf';
134
+        $loader->load($resource, 'en', 'domain1');
135
+    }
136
+
137
+    /**
138
+     * @expectedException \Symfony\Component\Translation\Exception\InvalidResourceException
139
+     */
140
+    public function testLoadThrowsAnExceptionIfFileNotLocal()
141
+    {
142
+        $loader = new XliffFileLoader();
143
+        $resource = 'http://example.com/resources.xlf';
144
+        $loader->load($resource, 'en', 'domain1');
145
+    }
146
+
147
+    /**
148
+     * @expectedException        \Symfony\Component\Translation\Exception\InvalidResourceException
149
+     * @expectedExceptionMessage Document types are not allowed.
150
+     */
151
+    public function testDocTypeIsNotAllowed()
152
+    {
153
+        $loader = new XliffFileLoader();
154
+        $loader->load(__DIR__.'/../fixtures/withdoctype.xlf', 'en', 'domain1');
155
+    }
156
+
157
+    public function testParseEmptyFile()
158
+    {
159
+        $loader = new XliffFileLoader();
160
+        $resource = __DIR__.'/../fixtures/empty.xlf';
161
+
162
+        if (method_exists($this, 'expectException')) {
163
+            $this->expectException('Symfony\Component\Translation\Exception\InvalidResourceException');
164
+            $this->expectExceptionMessage(sprintf('Unable to load "%s":', $resource));
165
+        } else {
166
+            $this->setExpectedException('Symfony\Component\Translation\Exception\InvalidResourceException', sprintf('Unable to load "%s":', $resource));
167
+        }
168
+
169
+        $loader->load($resource, 'en', 'domain1');
170
+    }
171
+
172
+    public function testLoadNotes()
173
+    {
174
+        $loader = new XliffFileLoader();
175
+        $catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1');
176
+
177
+        $this->assertEquals(
178
+            [
179
+                'source' => 'foo',
180
+                'notes' => [['priority' => 1, 'content' => 'foo']],
181
+                'id' => '1',
182
+                'file' => [
183
+                    'original' => 'file.ext',
184
+                ],
185
+            ],
186
+            $catalogue->getMetadata('foo', 'domain1')
187
+        );
188
+        // message without target
189
+        $this->assertEquals(
190
+            [
191
+                'source' => 'extrasource',
192
+                'notes' => [['content' => 'bar', 'from' => 'foo']],
193
+                'id' => '2',
194
+                'file' => [
195
+                    'original' => 'file.ext',
196
+                ],
197
+            ],
198
+            $catalogue->getMetadata('extra', 'domain1')
199
+        );
200
+        // message with empty target
201
+        $this->assertEquals(
202
+            [
203
+                'source' => 'key',
204
+                'notes' => [
205
+                    ['content' => 'baz'],
206
+                    ['priority' => 2, 'from' => 'bar', 'content' => 'qux'],
207
+                ],
208
+                'id' => '123',
209
+                'file' => [
210
+                    'original' => 'file.ext',
211
+                ],
212
+            ],
213
+            $catalogue->getMetadata('key', 'domain1')
214
+        );
215
+    }
216
+
217
+    public function testLoadVersion2()
218
+    {
219
+        $loader = new XliffFileLoader();
220
+        $resource = __DIR__.'/../fixtures/resources-2.0.xlf';
221
+        $catalogue = $loader->load($resource, 'en', 'domain1');
222
+
223
+        $this->assertEquals('en', $catalogue->getLocale());
224
+        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
225
+        $this->assertSame([], libxml_get_errors());
226
+
227
+        $domains = $catalogue->all();
228
+        $this->assertCount(3, $domains['domain1']);
229
+        $this->assertContainsOnly('string', $catalogue->all('domain1'));
230
+
231
+        // target attributes
232
+        $this->assertEquals(['target-attributes' => ['order' => 1]], $catalogue->getMetadata('bar', 'domain1'));
233
+    }
234
+
235
+    public function testLoadVersion2WithNoteMeta()
236
+    {
237
+        $loader = new XliffFileLoader();
238
+        $resource = __DIR__.'/../fixtures/resources-notes-meta.xlf';
239
+        $catalogue = $loader->load($resource, 'en', 'domain1');
240
+
241
+        $this->assertEquals('en', $catalogue->getLocale());
242
+        $this->assertEquals([new FileResource($resource)], $catalogue->getResources());
243
+        $this->assertSame([], libxml_get_errors());
244
+
245
+        // test for "foo" metadata
246
+        $this->assertTrue($catalogue->defines('foo', 'domain1'));
247
+        $metadata = $catalogue->getMetadata('foo', 'domain1');
248
+        $this->assertNotEmpty($metadata);
249
+        $this->assertCount(3, $metadata['notes']);
250
+
251
+        $this->assertEquals('state', $metadata['notes'][0]['category']);
252
+        $this->assertEquals('new', $metadata['notes'][0]['content']);
253
+
254
+        $this->assertEquals('approved', $metadata['notes'][1]['category']);
255
+        $this->assertEquals('true', $metadata['notes'][1]['content']);
256
+
257
+        $this->assertEquals('section', $metadata['notes'][2]['category']);
258
+        $this->assertEquals('1', $metadata['notes'][2]['priority']);
259
+        $this->assertEquals('user login', $metadata['notes'][2]['content']);
260
+
261
+        // test for "baz" metadata
262
+        $this->assertTrue($catalogue->defines('baz', 'domain1'));
263
+        $metadata = $catalogue->getMetadata('baz', 'domain1');
264
+        $this->assertNotEmpty($metadata);
265
+        $this->assertCount(2, $metadata['notes']);
266
+
267
+        $this->assertEquals('x', $metadata['notes'][0]['id']);
268
+        $this->assertEquals('x_content', $metadata['notes'][0]['content']);
269
+
270
+        $this->assertEquals('target', $metadata['notes'][1]['appliesTo']);
271
+        $this->assertEquals('quality', $metadata['notes'][1]['category']);
272
+        $this->assertEquals('Fuzzy', $metadata['notes'][1]['content']);
273
+    }
274
+
275
+    public function testLoadVersion2WithMultiSegmentUnit()
276
+    {
277
+        $loader = new XliffFileLoader();
278
+        $resource = __DIR__.'/../fixtures/resources-2.0-multi-segment-unit.xlf';
279
+        $catalog = $loader->load($resource, 'en', 'domain1');
280
+
281
+        $this->assertSame('en', $catalog->getLocale());
282
+        $this->assertEquals([new FileResource($resource)], $catalog->getResources());
283
+        $this->assertFalse(libxml_get_last_error());
284
+
285
+        // test for "foo" metadata
286
+        $this->assertTrue($catalog->defines('foo', 'domain1'));
287
+        $metadata = $catalog->getMetadata('foo', 'domain1');
288
+        $this->assertNotEmpty($metadata);
289
+        $this->assertCount(1, $metadata['notes']);
290
+
291
+        $this->assertSame('processed', $metadata['notes'][0]['category']);
292
+        $this->assertSame('true', $metadata['notes'][0]['content']);
293
+
294
+        // test for "bar" metadata
295
+        $this->assertTrue($catalog->defines('bar', 'domain1'));
296
+        $metadata = $catalog->getMetadata('bar', 'domain1');
297
+        $this->assertNotEmpty($metadata);
298
+        $this->assertCount(1, $metadata['notes']);
299
+
300
+        $this->assertSame('processed', $metadata['notes'][0]['category']);
301
+        $this->assertSame('true', $metadata['notes'][0]['content']);
302
+    }
303
+
304
+    public function testLoadWithMultipleFileNodes()
305
+    {
306
+        $loader = new XliffFileLoader();
307
+        $catalogue = $loader->load(__DIR__.'/../fixtures/resources-multi-files.xlf', 'en', 'domain1');
308
+
309
+        $this->assertEquals(
310
+            [
311
+                'source' => 'foo',
312
+                'id' => '1',
313
+                'file' => [
314
+                    'original' => 'file.ext',
315
+                ],
316
+            ],
317
+            $catalogue->getMetadata('foo', 'domain1')
318
+        );
319
+        $this->assertEquals(
320
+            [
321
+                'source' => 'test',
322
+                'notes' => [['content' => 'note']],
323
+                'id' => '4',
324
+                'file' => [
325
+                    'original' => 'otherfile.ext',
326
+                ],
327
+            ],
328
+            $catalogue->getMetadata('test', 'domain1')
329
+        );
330
+    }
331
+}