summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit/tests/l10n/getUserLocale.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/tests/l10n/getUserLocale.php')
-rw-r--r--tests/phpunit/tests/l10n/getUserLocale.php53
1 files changed, 36 insertions, 17 deletions
diff --git a/tests/phpunit/tests/l10n/getUserLocale.php b/tests/phpunit/tests/l10n/getUserLocale.php
index 76492b3b70..e4eaf7a260 100644
--- a/tests/phpunit/tests/l10n/getUserLocale.php
+++ b/tests/phpunit/tests/l10n/getUserLocale.php
@@ -9,34 +9,61 @@
class Tests_L10n_GetUserLocale extends WP_UnitTestCase {
protected $user_id;
- public function set_up() {
- parent::set_up();
+ /**
+ * ID of the administrator user with de_DE local.
+ *
+ * @var int
+ */
+ public static $administrator_de_de;
+
+ /**
+ * ID of the user with es_ES local.
+ *
+ * @var int
+ */
+ public static $user_es_es;
- $this->user_id = self::factory()->user->create(
+ /**
+ * Set up the shared fixtures.
+ *
+ * @param WP_UnitTest_Factory $factory Factory instance.
+ */
+ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ self::$administrator_de_de = $factory->user->create(
array(
'role' => 'administrator',
'locale' => 'de_DE',
)
);
- wp_set_current_user( $this->user_id );
+ self::$user_es_es = self::factory()->user->create(
+ array(
+ 'locale' => 'es_ES',
+ )
+ );
+ }
+
+ public function set_up() {
+ parent::set_up();
+
+ wp_set_current_user( self::$administrator_de_de );
}
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() );
+ $this->assertSame( get_user_by( 'id', self::$administrator_de_de )->locale, get_user_locale() );
}
public function test_update_user_locale() {
set_current_screen( 'dashboard' );
- update_user_meta( $this->user_id, 'locale', 'fr_FR' );
+ update_user_meta( self::$administrator_de_de, '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', '' );
+ update_user_meta( self::$administrator_de_de, 'locale', '' );
$this->assertSame( get_locale(), get_user_locale() );
}
@@ -78,11 +105,7 @@ class Tests_L10n_GetUserLocale extends WP_UnitTestCase {
}
public function test_user_id_argument_with_id() {
- $user_id = self::factory()->user->create(
- array(
- 'locale' => 'es_ES',
- )
- );
+ $user_id = self::$user_es_es;
$user_locale1 = get_user_locale( $user_id );
@@ -95,11 +118,7 @@ class Tests_L10n_GetUserLocale extends WP_UnitTestCase {
}
public function test_user_id_argument_with_wp_user_object() {
- $user_id = self::factory()->user->create(
- array(
- 'locale' => 'es_ES',
- )
- );
+ $user_id = self::$user_es_es;
$user = get_user_by( 'id', $user_id );