From b22261f781b03c7f7e82b51152a0bcd7a310bbd6 Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Thu, 15 Jul 2010 00:07:22 +0000 Subject: [PATCH] BUGFIX: tests now pass when the locale is set to something other than 'en_US' in the mysite's _config.php file git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@107940 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- tests/i18n/i18nTextCollectorTest.php | 8 ++++++++ tests/model/MoneyTest.php | 5 +++++ tests/security/MemberTest.php | 19 +++++++++++++++++-- tests/security/SecurityTest.php | 5 +++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/i18n/i18nTextCollectorTest.php b/tests/i18n/i18nTextCollectorTest.php index 46ccfa9e6..f7c98374d 100644 --- a/tests/i18n/i18nTextCollectorTest.php +++ b/tests/i18n/i18nTextCollectorTest.php @@ -407,6 +407,11 @@ PHP; } function testCollectFromFilesystemAndWriteMasterTables() { + $defaultlocal = i18n::default_locale(); + $local = i18n::get_locale(); + i18n::set_locale('en_US'); //set the locale to the US locale expected in the asserts + i18n::set_default_locale('en_US'); + $c = new i18nTextCollector(); $c->basePath = $this->alternateBasePath; $c->baseSavePath = $this->alternateBaseSavePath; @@ -466,6 +471,9 @@ PHP; "\$lang['en_US']['i18nOtherModule']['MAINTEMPLATE'] = 'Main Template Other Module';", $otherModuleLangFileContent ); + + i18n::set_locale($local); //set the locale to the US locale expected in the asserts ++ i18n::set_default_locale($defaultlocal); } function testCollectFromEntityProvidersInCustomObject() { diff --git a/tests/model/MoneyTest.php b/tests/model/MoneyTest.php index 4018503a5..55fa413a3 100644 --- a/tests/model/MoneyTest.php +++ b/tests/model/MoneyTest.php @@ -74,6 +74,9 @@ class MoneyTest extends SapphireTest { * is re-read properly. */ function testGettingWrittenDataObject() { + $local = i18n::get_locale(); + i18n::set_locale('en_US'); //make sure that the $ amount is not prefixed by US$, as it would be in non-US locale + $obj = new MoneyTest_DataObject(); $m = new Money(); @@ -93,6 +96,8 @@ class MoneyTest extends SapphireTest { $this->assertEquals("$987.65", $moneyTest->MyMoney->Nice(), "Money field not added to data object properly when read." ); + + i18n::set_locale($local); } public function testToCurrency() { diff --git a/tests/security/MemberTest.php b/tests/security/MemberTest.php index a8f921cdf..1456c5f04 100644 --- a/tests/security/MemberTest.php +++ b/tests/security/MemberTest.php @@ -7,7 +7,22 @@ class MemberTest extends FunctionalTest { static $fixture_file = 'sapphire/tests/security/MemberTest.yml'; protected $orig = array(); - + protected $local = null; + + function __construct() { + parent::__construct(); + + //Setting the locale has to happen in the constructor (using the setUp and tearDown methods doesn't work) + //This is because the test relies on the yaml file being interpreted according to a particular date format + //and this setup occurs before the setUp method is run + $this->local = i18n::default_locale(); + i18n::set_default_locale('en_US'); + } + + function __destruct() { + i18n::set_default_locale($this->local); + } + function setUp() { parent::setUp(); @@ -18,7 +33,7 @@ class MemberTest extends FunctionalTest { function tearDown() { Member::set_unique_identifier_field($this->orig['Member_unique_identifier_field']); - + parent::tearDown(); } diff --git a/tests/security/SecurityTest.php b/tests/security/SecurityTest.php index e3b5c84dd..6e1b058ea 100644 --- a/tests/security/SecurityTest.php +++ b/tests/security/SecurityTest.php @@ -183,6 +183,9 @@ class SecurityTest extends FunctionalTest { } function testRepeatedLoginAttemptsLockingPeopleOut() { + $local = i18n::get_locale(); + i18n::set_locale('en_US'); + Member::lock_out_after_incorrect_logins(5); /* LOG IN WITH A BAD PASSWORD 7 TIMES */ @@ -239,6 +242,8 @@ class SecurityTest extends FunctionalTest { $this->doTestLoginForm('sam@silverstripe.com' , '1nitialPassword'); $this->assertEquals($this->session()->inst_get('loggedInAs'), $member->ID); + + i18n::set_locale($local); } function testAlternatingRepeatedLoginAttempts() {