forked from GlotPress/GlotPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_format_resx.php
73 lines (65 loc) · 3.17 KB
/
test_format_resx.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
class GP_Test_Format_ResX extends GP_UnitTestCase {
function setUp(): void {
parent::setUp();
$this->resx = new GP_Format_ResX;
$this->entries = array(
array('normal_string', 'Normal String', 'Just A Normal String', ''),
array('with_a_quote', 'I\'m with a quote', 'I\'m with a quote', ''),
array('with_newlines', "new\nlines", "I\nhave\nnew\nlines", ''),
array('with_doublequotes', 'double "quotes"', 'I have double "quotes"', ''),
array('with_utf8', 'питка', 'баба ми омеси питка', ''),
array('with_lt', 'you < me', 'ти < аз', ''),
array('with_gt', 'me > you', "аз > ти", ''),
array('with_amps', 'me & you are not &', 'аз & ти не сме &', ''),
array('with_comment', 'baba', 'баба', 'Me, myself & Irene'),
);
}
function test_export() {
$set = $this->factory->translation_set->create_with_project_and_locale();
$project = $set->project;
$locale = $this->factory->locale->create();
$entries_for_export = array();
foreach( $this->entries as $sample ) {
list( $context, $original, $translation, $comment ) = $sample;
$entries_for_export[] = (object)array(
'context' => $context,
'singular' => $original,
'translations' => array($translation),
'extracted_comments' => $comment,
);
}
$file_contents = file_get_contents( GP_DIR_TESTDATA . '/translation.resx.xml' );
$file_contents = str_replace( '[GP VERSION]', GP_VERSION, $file_contents );
$this->assertEquals( $file_contents, $this->resx->print_exported_file( $project, $locale, $set, $entries_for_export ) );
}
function test_read_originals() {
$translations = $this->resx->read_originals_from_file( GP_DIR_TESTDATA . '/originals.resx.xml' );
$this->assertEquals( count($this->entries ), count( $translations->entries ), 'number of read originals is different from the expected' );
foreach( $this->entries as $sample ) {
list( $context, $original, $translation, $comment ) = $sample;
$translatable_entry = new Translation_Entry( array('singular' => $original, 'context' => $context, 'extracted_comments' => $comment ) );
$entry = $translations->translate_entry( $translatable_entry );
$this->assertEquals( $original, $entry->singular );
$this->assertEquals( $context, $entry->context );
$this->assertEquals( $comment, $entry->extracted_comments );
}
}
function test_read_translations() {
$stubbed_originals = array();
foreach( $this->entries as $sample ) {
list( $context, $original, $translation ) = $sample;
$stubbed_originals[] = new GP_Original( array( 'singular' => $original, 'context' => $context ) );
}
GP::$original = $this->getMockBuilder( 'GP_Original' )->setMethods( array('by_project_id') )->getMock();
GP::$original->expects( $this->once() )
->method( 'by_project_id' )
->with( $this->equalTo(2) )
->will( $this->returnValue($stubbed_originals) );
$translations = $this->resx->read_translations_from_file( GP_DIR_TESTDATA . '/translation.resx.xml', (object)array( 'id' => 2 ) );
foreach( $this->entries as $sample ) {
list( $context, $original, $translation ) = $sample;
$this->assertEquals( $translation, $translations->translate( $original, $context ) );
}
}
}