forked from GlotPress/GlotPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_format_json_pretty_print.php
52 lines (41 loc) · 1.73 KB
/
test_format_json_pretty_print.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
<?php
class GP_Test_JSON_Pretty_Print extends GP_UnitTestCase {
/**
* @var GP_Translation_Set
*/
protected $translation_set;
/**
* @var GP_Locale
*/
protected $locale;
public function setUp(): void {
parent::setUp();
$this->translation_set = $this->factory->translation_set->create_with_project_and_locale( array(), array( 'name' => 'foo_project' ) );
$this->locale = new GP_Locale( array(
'slug' => $this->translation_set->locale,
'nplurals' => 2,
'plural_expression' => 'n != 1',
) );
}
public function test_jed1x_print_exported_file_pretty_print() {
$entries = array(
new Translation_Entry( array( 'singular' => 'foo', 'translations' => array( 'bar' ) ) ),
);
add_filter( 'gp_json_export_pretty_print', '__return_true' );
$actual = GP::$formats['jed1x']->print_exported_file( $this->translation_set->project, $this->locale, $this->translation_set, $entries );
remove_filter( 'gp_json_export_pretty_print', '__return_true' );
// The pretty-printed output has 15 lines in total.
$this->assertSame( 16, substr_count( $actual, "\n" ) );
}
public function test_print_exported_file_pretty_print() {
$entries = array(
new Translation_Entry( array( 'singular' => 'foo', 'translations' => array( 'bar' ) ) ),
new Translation_Entry( array( 'singular' => 'bar', 'translations' => array( 'baz' ) ) ),
);
add_filter( 'gp_json_export_pretty_print', '__return_true' );
$actual = GP::$formats['json']->print_exported_file( $this->translation_set->project, $this->locale, $this->translation_set, $entries );
remove_filter( 'gp_json_export_pretty_print', '__return_true' );
// The pretty-printed output has 8 lines in total.
$this->assertSame( 7, substr_count( $actual, "\n" ) );
}
}