FIX New members now receive the configured default locale, not the current locale

This commit is contained in:
Robbie Averill 2018-09-28 16:25:10 +02:00
parent f01473f1b3
commit 231d6d9a9f
2 changed files with 24 additions and 6 deletions

View File

@ -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
*/

View File

@ -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');
}
}