Skip to content

Commit 25efc50

Browse files
lancewillettclaude
andauthored
Tests: Cover translation setup in override script tests (#83886)
gutenberg_override_script() calls set_translations() when the script depends on wp-i18n. No test covered that branch. Add one test for each side: with wp-i18n the text domain is set to "default", and without it the text domain stays unset and no wp-i18n dependency is added. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9e4d344 commit 25efc50

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎phpunit/class-override-script-test.php‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,45 @@ public function test_localizes_script() {
5353
);
5454
}
5555

56+
/**
57+
* Tests that translations are set when the script depends on wp-i18n.
58+
*/
59+
public function test_sets_translations_when_depending_on_wp_i18n() {
60+
global $wp_scripts;
61+
62+
gutenberg_override_script(
63+
$wp_scripts,
64+
'gutenberg-dummy-script',
65+
'https://example.com/',
66+
array( 'wp-i18n' ),
67+
'version',
68+
false
69+
);
70+
71+
$script = $wp_scripts->query( 'gutenberg-dummy-script', 'registered' );
72+
$this->assertSame( 'default', $script->textdomain );
73+
}
74+
75+
/**
76+
* Tests that translations are not set when the script does not depend on wp-i18n.
77+
*/
78+
public function test_does_not_set_translations_without_wp_i18n() {
79+
global $wp_scripts;
80+
81+
gutenberg_override_script(
82+
$wp_scripts,
83+
'gutenberg-dummy-script',
84+
'https://example.com/',
85+
array( 'dependency' ),
86+
'version',
87+
false
88+
);
89+
90+
$script = $wp_scripts->query( 'gutenberg-dummy-script', 'registered' );
91+
$this->assertNull( $script->textdomain );
92+
$this->assertSame( array( 'dependency' ), $script->deps );
93+
}
94+
5695
/**
5796
* Tests that script properties are overridden.
5897
*/

0 commit comments

Comments
 (0)