16
16
17
17
class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
18
18
{
19
+ protected $ tempDir ;
20
+
21
+ protected function setUp ()
22
+ {
23
+ $ this ->tempDir = sys_get_temp_dir ();
24
+ }
25
+
19
26
public function testDump ()
20
27
{
21
28
$ catalogue = new MessageCatalogue ('en_US ' );
@@ -27,50 +34,56 @@ public function testDump()
27
34
$ catalogue ->setMetadata ('foo ' , array ('notes ' => array (array ('priority ' => 1 , 'from ' => 'bar ' , 'content ' => 'baz ' ))));
28
35
$ catalogue ->setMetadata ('key ' , array ('notes ' => array (array ('content ' => 'baz ' ), array ('content ' => 'qux ' ))));
29
36
30
- $ tempDir = sys_get_temp_dir ();
31
37
$ dumper = new XliffFileDumper ();
32
- $ dumper ->dump ($ catalogue , array ('path ' => $ tempDir , 'default_locale ' => 'fr_FR ' ));
38
+ $ dumper ->dump ($ catalogue , array ('path ' => $ this -> tempDir , 'default_locale ' => 'fr_FR ' ));
33
39
34
40
$ this ->assertEquals (
35
41
file_get_contents (__DIR__ .'/../fixtures/resources-clean.xlf ' ),
36
- file_get_contents ($ tempDir .'/messages.en_US.xlf ' )
42
+ file_get_contents ($ this ->tempDir .'/messages.en_US.xlf ' )
43
+ );
44
+
45
+ unlink ($ this ->tempDir .'/messages.en_US.xlf ' );
46
+ }
47
+
48
+ public function testDumpWithCustomToolInfo ()
49
+ {
50
+ $ options = array (
51
+ 'path ' => $ this ->tempDir ,
52
+ 'default_locale ' => 'en_US ' ,
53
+ 'tool_info ' => array ('tool-id ' => 'foo ' , 'tool-name ' => 'foo ' , 'tool-version ' => '0.0 ' , 'tool-company ' => 'Foo ' ),
54
+ );
55
+
56
+ $ catalogue = new MessageCatalogue ('en_US ' );
57
+ $ catalogue ->add (array ('foo ' => 'bar ' ));
58
+
59
+ $ dumper = new XliffFileDumper ();
60
+ $ dumper ->dump ($ catalogue , $ options );
61
+
62
+ $ this ->assertEquals (
63
+ file_get_contents (__DIR__ .'/../fixtures/resources-tool-info.xlf ' ),
64
+ file_get_contents ($ this ->tempDir .'/messages.en_US.xlf ' )
37
65
);
38
66
39
- unlink ($ tempDir .'/messages.en_US.xlf ' );
67
+ unlink ($ this -> tempDir .'/messages.en_US.xlf ' );
40
68
}
41
69
42
- public function testTargetAttributesMetadataIsSetInFile ()
70
+ public function testDumpWithTargetAttributesMetadata ()
43
71
{
44
72
$ catalogue = new MessageCatalogue ('en_US ' );
45
73
$ catalogue ->add (array (
46
74
'foo ' => 'bar ' ,
47
75
));
48
76
$ catalogue ->setMetadata ('foo ' , array ('target-attributes ' => array ('state ' => 'needs-translation ' )));
49
77
50
- $ tempDir = sys_get_temp_dir ();
78
+ $ this -> tempDir = sys_get_temp_dir ();
51
79
$ dumper = new XliffFileDumper ();
52
- $ dumper ->dump ($ catalogue , array ('path ' => $ tempDir , 'default_locale ' => 'fr_FR ' ));
53
-
54
- $ content = <<<EOT
55
- <?xml version="1.0" encoding="utf-8"?>
56
- <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
57
- <file source-language="fr-FR" target-language="en-US" datatype="plaintext" original="file.ext">
58
- <body>
59
- <trans-unit id="acbd18db4cc2f85cedef654fccc4a4d8" resname="foo">
60
- <source>foo</source>
61
- <target state="needs-translation">bar</target>
62
- </trans-unit>
63
- </body>
64
- </file>
65
- </xliff>
66
-
67
- EOT ;
80
+ $ dumper ->dump ($ catalogue , array ('path ' => $ this ->tempDir , 'default_locale ' => 'fr_FR ' ));
68
81
69
82
$ this ->assertEquals (
70
- $ content ,
71
- file_get_contents ($ tempDir .'/messages.en_US.xlf ' )
83
+ file_get_contents ( __DIR__ . ' /../fixtures/resources-target-attributes.xlf ' ) ,
84
+ file_get_contents ($ this -> tempDir .'/messages.en_US.xlf ' )
72
85
);
73
86
74
- unlink ($ tempDir .'/messages.en_US.xlf ' );
87
+ unlink ($ this -> tempDir .'/messages.en_US.xlf ' );
75
88
}
76
89
}
0 commit comments