mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 10:44:26 +00:00
I18N: Introduce a user-specific language setting.
By enabling the user to select their preferred locale when editing the profile, we allow for greater personalization of the WordPress admin and therefore a better user experience. The back end will be displayed in the user's individual locale while the locale used on the front end equals the one set for the whole site. If the user didn't specify a locale, the site's locale will be used as a fallback. The new `locale` property of the `WP_User` class can be used to retrieve the user's locale setting. Props ocean90, ipm-frommen, swissspidy. Fixes #29783. git-svn-id: https://develop.svn.wordpress.org/trunk@38705 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
78
tests/phpunit/tests/l10n/getUserLocale.php
Normal file
78
tests/phpunit/tests/l10n/getUserLocale.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group l10n
|
||||
* @group i18n
|
||||
*/
|
||||
class Tests_Get_User_Locale extends WP_UnitTestCase {
|
||||
protected $user_id;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->user_id = $this->factory()->user->create( array(
|
||||
'role' => 'administrator',
|
||||
'locale' => 'de_DE',
|
||||
) );
|
||||
|
||||
wp_set_current_user( $this->user_id );
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
delete_user_meta( $this->user_id, 'locale' );
|
||||
set_current_screen( 'front' );
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_user_locale_property() {
|
||||
set_current_screen( 'dashboard' );
|
||||
$this->assertSame( 'de_DE', get_user_locale() );
|
||||
$this->assertSame( get_user_by( 'id', $this->user_id )->locale, get_user_locale() );
|
||||
}
|
||||
|
||||
public function test_update_user_locale() {
|
||||
set_current_screen( 'dashboard' );
|
||||
update_user_meta( $this->user_id, 'locale', 'fr_FR' );
|
||||
$this->assertSame( 'fr_FR', get_user_locale() );
|
||||
}
|
||||
|
||||
public function test_returns_site_locale_if_empty() {
|
||||
set_current_screen( 'dashboard' );
|
||||
update_user_meta( $this->user_id, 'locale', '' );
|
||||
$this->assertSame( get_locale(), get_user_locale() );
|
||||
}
|
||||
|
||||
public function test_returns_correct_user_locale() {
|
||||
set_current_screen( 'dashboard' );
|
||||
$this->assertSame( 'de_DE', get_user_locale() );
|
||||
}
|
||||
|
||||
public function test_returns_correct_user_locale_on_frontend() {
|
||||
$this->assertSame( 'de_DE', get_user_locale() );
|
||||
}
|
||||
|
||||
public function test_site_locale_is_not_affected() {
|
||||
set_current_screen( 'dashboard' );
|
||||
$this->assertSame( 'en_US', get_locale() );
|
||||
}
|
||||
|
||||
public function test_site_locale_is_not_affected_on_frontend() {
|
||||
$this->assertSame( 'en_US', get_locale() );
|
||||
}
|
||||
|
||||
public function test_user_locale_is_same_across_network() {
|
||||
if ( ! is_multisite() ) {
|
||||
$this->markTestSkipped( __METHOD__ . ' requires multisite' );
|
||||
}
|
||||
|
||||
$user_locale = get_user_locale();
|
||||
|
||||
switch_to_blog( self::factory()->blog->create() );
|
||||
$user_locale_2 = get_user_locale();
|
||||
restore_current_blog();
|
||||
|
||||
$this->assertSame( 'de_DE', $user_locale );
|
||||
$this->assertSame( $user_locale, $user_locale_2 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user