From 231d6d9a9f388e10cf77149aec22e947db648644 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 28 Sep 2018 16:25:10 +0200 Subject: [PATCH] FIX New members now receive the configured default locale, not the current locale --- src/Security/Member.php | 12 ++++++------ tests/php/Security/MemberTest.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Security/Member.php b/src/Security/Member.php index 164f995ee..356c2c1d8 100644 --- a/src/Security/Member.php +++ b/src/Security/Member.php @@ -268,7 +268,7 @@ class Member extends DataObject public function populateDefaults() { parent::populateDefaults(); - $this->Locale = i18n::get_locale(); + $this->Locale = i18n::config()->get('default_locale'); } public function requireDefaultRecords() @@ -929,7 +929,7 @@ class Member extends DataObject // save locale if (!$this->Locale) { - $this->Locale = i18n::get_locale(); + $this->Locale = i18n::config()->get('default_locale'); } parent::onBeforeWrite(); @@ -1228,7 +1228,7 @@ class Member extends DataObject /** * Return the date format based on the user's chosen locale, - * falling back to the default format defined by the {@link i18n.get_locale()} setting. + * falling back to the default format defined by the i18n::config()->get('default_locale') config setting. * * @return string ISO date format */ @@ -1247,7 +1247,7 @@ class Member extends DataObject } /** - * Get user locale + * Get user locale, falling back to the configured default locale */ public function getLocale() { @@ -1256,12 +1256,12 @@ class Member extends DataObject return $locale; } - return i18n::get_locale(); + return i18n::config()->get('default_locale'); } /** * Return the time format based on the user's chosen locale, - * falling back to the default format defined by the {@link i18n.get_locale()} setting. + * falling back to the default format defined by the i18n::config()->get('default_locale') config setting. * * @return string ISO date format */ diff --git a/tests/php/Security/MemberTest.php b/tests/php/Security/MemberTest.php index 942b732b0..bdf664c1f 100644 --- a/tests/php/Security/MemberTest.php +++ b/tests/php/Security/MemberTest.php @@ -56,6 +56,8 @@ class MemberTest extends FunctionalTest Member::config()->set('unique_identifier_field', 'Email'); Member::set_password_validator(null); + + i18n::set_locale('en_US'); } public function testPasswordEncryptionUpdatedOnChangedPassword() @@ -1533,4 +1535,20 @@ class MemberTest extends FunctionalTest $this->assertInstanceOf(ValidationResult::class, $result); $this->assertFalse($result->isValid()); } + + public function testNewMembersReceiveTheDefaultLocale() + { + // Set a different current locale to the default + i18n::set_locale('de_DE'); + + $newMember = Member::create(); + $newMember->update([ + 'FirstName' => 'Leslie', + 'Surname' => 'Longly', + 'Email' => 'longly.leslie@example.com', + ]); + $newMember->write(); + + $this->assertSame('en_US', $newMember->Locale, 'New members receive the default locale'); + } }