Skip to content

Commit 9e16f53

Browse files
committed
test: fix test case
1 parent 44b5f23 commit 9e16f53

File tree

2 files changed

+20
-44
lines changed

2 files changed

+20
-44
lines changed

tests/phpunit-legacy/test-basic.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,21 @@ function register_widgets() {
6767
* @group basic
6868
*/
6969
public function load_textdomain() {
70+
global $wp_version;
7071
$loaded = $this->custom_post_type_widgets->load_textdomain();
71-
$this->assertTrue( $loaded );
72-
}
73-
74-
/**
75-
* @test
76-
* @group basic
77-
*/
78-
public function load_textdomain_switch_to_locale() {
79-
$this->assertTrue( switch_to_locale( 'ja_JP' ) );
80-
81-
$loaded = $this->custom_post_type_widgets->load_textdomain();
82-
$this->assertTrue( $loaded );
83-
84-
switch_to_locale( 'en_US' );
72+
if ( version_compare( (string) $wp_version, '6.7', '>=' ) ) {
73+
$this->assertTrue( $loaded );
74+
}
75+
else {
76+
$this->assertFalse( $loaded );
77+
}
8578
}
8679

8780
/**
8881
* @test
8982
* @group basic
9083
*/
9184
public function load_textdomain_change() {
92-
$loaded = $this->custom_post_type_widgets->load_textdomain();
93-
$this->assertTrue( $loaded );
94-
9585
unload_textdomain( 'custom-post-type-widgets' );
9686
$this->assertFalse( isset( $l10n[ 'custom-post-type-widgets' ] ) );
9787

@@ -101,27 +91,25 @@ public function load_textdomain_change() {
10191
$loaded = $this->custom_post_type_widgets->load_textdomain();
10292
$this->assertTrue( $loaded );
10393

104-
$this->assertSame( 'ja_JP', get_locale() );
94+
$this->assertSame( 'ja', get_locale() );
10595

10696
remove_filter( 'load_textdomain_mofile', [ $this, '_change_textdomain_mofile' ] );
10797
remove_filter( 'locale', [ $this, '_change_locale' ] );
10898

10999
unload_textdomain( 'custom-post-type-widgets' );
110100
$this->assertFalse( isset( $l10n[ 'custom-post-type-widgets' ] ) );
111-
112-
switch_to_locale( 'en_US' );
113101
}
114102

115103
/**
116104
* hook for load_textdomain
117105
*/
118106
function _change_locale( $locale ) {
119-
return 'ja_JP';
107+
return 'ja';
120108
}
121109

122110
function _change_textdomain_mofile( $mofile, $domain ) {
123111
if ( $domain === 'custom-post-type-widgets' ) {
124-
$locale = determine_locale();
112+
$locale = get_locale();
125113
$mofile = plugin_dir_path( __CUSTOM_POST_TYPE_WIDGETS__ ) . 'languages/custom-post-type-widgets-' . $locale . '.mo';
126114

127115
$this->assertSame( $locale, get_locale() );

tests/phpunit/test-basic.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,21 @@ function register_widgets() {
6868
* @group basic
6969
*/
7070
public function load_textdomain() {
71+
global $wp_version;
7172
$loaded = $this->custom_post_type_widgets->load_textdomain();
72-
$this->assertTrue( $loaded );
73-
}
74-
75-
/**
76-
* @test
77-
* @group basic
78-
*/
79-
public function load_textdomain_switch_to_locale() {
80-
$this->assertTrue( switch_to_locale( 'ja_JP' ) );
81-
82-
$loaded = $this->custom_post_type_widgets->load_textdomain();
83-
$this->assertTrue( $loaded );
84-
85-
switch_to_locale( 'en_US' );
73+
if ( version_compare( (string) $wp_version, '6.7', '>=' ) ) {
74+
$this->assertTrue( $loaded );
75+
}
76+
else {
77+
$this->assertFalse( $loaded );
78+
}
8679
}
8780

8881
/**
8982
* @test
9083
* @group basic
9184
*/
9285
public function load_textdomain_change() {
93-
$loaded = $this->custom_post_type_widgets->load_textdomain();
94-
$this->assertTrue( $loaded );
95-
9686
unload_textdomain( 'custom-post-type-widgets' );
9787
$this->assertFalse( isset( $l10n[ 'custom-post-type-widgets' ] ) );
9888

@@ -102,27 +92,25 @@ public function load_textdomain_change() {
10292
$loaded = $this->custom_post_type_widgets->load_textdomain();
10393
$this->assertTrue( $loaded );
10494

105-
$this->assertSame( 'ja_JP', get_locale() );
95+
$this->assertSame( 'ja', get_locale() );
10696

10797
remove_filter( 'load_textdomain_mofile', [ $this, '_change_textdomain_mofile' ] );
10898
remove_filter( 'locale', [ $this, '_change_locale' ] );
10999

110100
unload_textdomain( 'custom-post-type-widgets' );
111101
$this->assertFalse( isset( $l10n[ 'custom-post-type-widgets' ] ) );
112-
113-
switch_to_locale( 'en_US' );
114102
}
115103

116104
/**
117105
* hook for load_textdomain
118106
*/
119107
function _change_locale( $locale ) {
120-
return 'ja_JP';
108+
return 'ja';
121109
}
122110

123111
function _change_textdomain_mofile( $mofile, $domain ) {
124112
if ( $domain === 'custom-post-type-widgets' ) {
125-
$locale = determine_locale();
113+
$locale = get_locale();
126114
$mofile = plugin_dir_path( __CUSTOM_POST_TYPE_WIDGETS__ ) . 'languages/custom-post-type-widgets-' . $locale . '.mo';
127115

128116
$this->assertSame( $locale, get_locale() );

0 commit comments

Comments
 (0)