diff --git a/tests/php/Forms/DateFieldDisabledTest.php b/tests/php/Forms/DateFieldDisabledTest.php index 207c9b652ae..3cb107b183c 100644 --- a/tests/php/Forms/DateFieldDisabledTest.php +++ b/tests/php/Forms/DateFieldDisabledTest.php @@ -12,7 +12,8 @@ class DateFieldDisabledTest extends SapphireTest protected function setUp(): void { parent::setUp(); - i18n::set_locale('en_NZ'); + // Set to an explicit locale so project-level locale swapping doesn't affect tests + i18n::set_locale('en_US'); DBDatetime::set_mock_now('2011-02-01 8:34:00'); } @@ -22,7 +23,7 @@ public function testFieldToday() $actual = DateField_Disabled::create('Test') ->setValue('2011-02-01') ->Field(); - $expected = '1/02/2011 (today)'; + $expected = 'Feb 1, 2011 (today)'; $this->assertEquals($expected, $actual); // Test today's date with time @@ -38,14 +39,14 @@ public function testFieldWithDifferentDay() $actual = DateField_Disabled::create('Test') ->setValue('2011-01-27') ->Field(); - $expected = '27/01/2011, 5 days ago'; + $expected = 'Jan 27, 2011, 5 days ago'; $this->assertEquals($expected, $actual); // Test future $actual = DateField_Disabled::create('Test') ->setValue('2011-02-06') ->Field(); - $expected = '6/02/2011, in 5 days'; + $expected = 'Feb 6, 2011, in 5 days'; $this->assertEquals($expected, $actual); } diff --git a/tests/php/Forms/DatetimeFieldTest.php b/tests/php/Forms/DatetimeFieldTest.php index 3f28a251557..8e5c9f1c368 100644 --- a/tests/php/Forms/DatetimeFieldTest.php +++ b/tests/php/Forms/DatetimeFieldTest.php @@ -148,7 +148,7 @@ public function testSetValueWithLocalised() // Some localisation packages exclude the ',' in default medium format $this->assertMatchesRegularExpression( - '#29/03/2003(,)? 11:00:00 (PM|pm)#', + '#29/03/2003(,)? 11:00:00\h(PM|pm)#u', $datetimeField->Value(), 'User value is formatted, and in user timezone' ); diff --git a/tests/php/ORM/DBDateTest.php b/tests/php/ORM/DBDateTest.php index d91360155cc..0f729cc949c 100644 --- a/tests/php/ORM/DBDateTest.php +++ b/tests/php/ORM/DBDateTest.php @@ -20,7 +20,8 @@ protected function setUp(): void $this->oldError = error_reporting(); // Validate setup assert(date_default_timezone_get() === 'UTC'); - i18n::set_locale('en_NZ'); + // Set to an explicit locale so project-level locale swapping doesn't affect tests + i18n::set_locale('en_US'); } protected function tearDown(): void @@ -48,42 +49,42 @@ protected function restoreNotices() public function testNiceDate() { $this->assertEquals( - '31/03/2008', + 'Mar 31, 2008', DBField::create_field('Date', 1206968400)->Nice(), "Date->Nice() works with timestamp integers" ); $this->assertEquals( - '30/03/2008', + 'Mar 30, 2008', DBField::create_field('Date', 1206882000)->Nice(), "Date->Nice() works with timestamp integers" ); $this->assertEquals( - '31/03/2008', + 'Mar 31, 2008', DBField::create_field('Date', '1206968400')->Nice(), "Date->Nice() works with timestamp strings" ); $this->assertEquals( - '30/03/2008', + 'Mar 30, 2008', DBField::create_field('Date', '1206882000')->Nice(), "Date->Nice() works with timestamp strings" ); $this->assertEquals( - '4/03/2003', + 'Mar 4, 2003', DBField::create_field('Date', '4.3.2003')->Nice(), "Date->Nice() works with D.M.YYYY format" ); $this->assertEquals( - '4/03/2003', + 'Mar 4, 2003', DBField::create_field('Date', '04.03.2003')->Nice(), "Date->Nice() works with DD.MM.YYYY format" ); $this->assertEquals( - '4/03/2003', + 'Mar 4, 2003', DBField::create_field('Date', '2003-3-4')->Nice(), "Date->Nice() works with YYYY-M-D format" ); $this->assertEquals( - '4/03/2003', + 'Mar 4, 2003', DBField::create_field('Date', '2003-03-04')->Nice(), "Date->Nice() works with YYYY-MM-DD format" ); @@ -107,7 +108,7 @@ public function testInvertedYearCorrection() { // iso8601 expects year first, but support year last $this->assertEquals( - '4/03/2003', + 'Mar 4, 2003', DBField::create_field('Date', '04-03-2003')->Nice(), "Date->Nice() works with DD-MM-YYYY format" ); @@ -152,32 +153,32 @@ public function testShortMonth() public function testLongDate() { $this->assertEquals( - '31 March 2008', + 'March 31, 2008', DBField::create_field('Date', 1206968400)->Long(), "Date->Long() works with numeric timestamp" ); $this->assertEquals( - '31 March 2008', + 'March 31, 2008', DBField::create_field('Date', '1206968400')->Long(), "Date->Long() works with string timestamp" ); $this->assertEquals( - '30 March 2008', + 'March 30, 2008', DBField::create_field('Date', 1206882000)->Long(), "Date->Long() works with numeric timestamp" ); $this->assertEquals( - '30 March 2008', + 'March 30, 2008', DBField::create_field('Date', '1206882000')->Long(), "Date->Long() works with numeric timestamp" ); $this->assertEquals( - '3 April 2003', + 'April 3, 2003', DBField::create_field('Date', '2003-4-3')->Long(), "Date->Long() works with YYYY-M-D" ); $this->assertEquals( - '3 April 2003', + 'April 3, 2003', DBField::create_field('Date', '3.4.2003')->Long(), "Date->Long() works with D.M.YYYY" ); @@ -186,7 +187,7 @@ public function testLongDate() public function testFull() { $this->assertEquals( - 'Monday, 31 March 2008', + 'Monday, March 31, 2008', DBField::create_field('Date', 1206968400)->Full(), "Date->Full() works with timestamp integers" ); diff --git a/tests/php/ORM/DBDatetimeTest.php b/tests/php/ORM/DBDatetimeTest.php index 71b24be225b..7229e5922e9 100644 --- a/tests/php/ORM/DBDatetimeTest.php +++ b/tests/php/ORM/DBDatetimeTest.php @@ -14,7 +14,8 @@ class DBDatetimeTest extends SapphireTest protected function setUp(): void { parent::setUp(); - i18n::set_locale('en_NZ'); + // Set to an explicit locale so project-level locale swapping doesn't affect tests + i18n::set_locale('en_US'); } public function testNowWithSystemDate() @@ -127,22 +128,22 @@ public function testNice() // note: Some localisation packages exclude the ',' in default medium format i18n::set_locale('en_NZ'); - $this->assertMatchesRegularExpression('#11/12/2001(,)? 10:10 PM#i', $date->Nice()); + $this->assertMatchesRegularExpression('#11/12/2001(,)? 10:10\hPM#iu', $date->Nice()); i18n::set_locale('en_US'); - $this->assertMatchesRegularExpression('#Dec 11(,)? 2001(,)? 10:10 PM#i', $date->Nice()); + $this->assertMatchesRegularExpression('#Dec 11(,)? 2001(,)? 10:10\hPM#iu', $date->Nice()); } public function testDate() { $date = DBDatetime::create_field('Datetime', '2001-12-31 22:10:59'); - $this->assertEquals('31/12/2001', $date->Date()); + $this->assertEquals('Dec 31, 2001', $date->Date()); } public function testTime() { $date = DBDatetime::create_field('Datetime', '2001-12-31 22:10:59'); - $this->assertMatchesRegularExpression('#10:10:59 PM#i', $date->Time()); + $this->assertMatchesRegularExpression('#10:10:59\hPM#iu', $date->Time()); } public function testTime24()