MDL-81074 core: Simplify strftime tests

This commit is contained in:
Andrew Nicols
2024-03-25 09:51:25 +08:00
parent bd4c8e3a70
commit 054d15a42f
+16 -25
View File
@@ -624,33 +624,33 @@ class date_test extends advanced_testcase {
return [
'string_c' => [
"1708405742",
null,
"20 February 2024 at 6:09pm",
"%c",
"20 February 2024 at 1:09pm",
],
'numeric_c' => [
1708405742,
null,
"20 February 2024 at 6:09pm",
"%c",
"20 February 2024 at 1:09pm",
],
'string_strftimedatetime' => [
"1708405742",
"strftimedatetime",
"20 February 2024, 06:09 PM",
get_string("strftimedatetime", 'langconfig'),
"20 February 2024, 01:09 PM",
],
'numeric_strftimedatetime' => [
1708405742,
"strftimedatetime",
"20 February 2024, 06:09 PM",
get_string("strftimedatetime", 'langconfig'),
"20 February 2024, 01:09 PM",
],
'string_strftimedatetimeshortaccurate' => [
"1708405742",
"strftimedatetimeshortaccurate",
"20/02/24, 18:09:02",
get_string("strftimedatetimeshortaccurate", 'langconfig'),
"20/02/24, 13:09:02",
],
'numeric_strftimedatetimeshortaccurate' => [
1708405742,
"strftimedatetimeshortaccurate",
"20/02/24, 18:09:02",
get_string("strftimedatetimeshortaccurate", 'langconfig'),
"20/02/24, 13:09:02",
],
];
}
@@ -658,21 +658,12 @@ class date_test extends advanced_testcase {
/**
* Test \core_date::strftime function.
*
* @dataProvider get_strftime_provider
* @dataProvider get_strftime_provider
* @param mixed $input Input passed to strftime
* @param string|null $format The date format to pass to strftime, falls back to '%c' if null
* @param string $format The date format to pass to strftime, falls back to '%c' if null
* @param string $expected The output generated by strftime
*
* @covers \core_date::strftime
*/
public function test_core_strftime(mixed $input, string|null $format, string $expected): void {
$this->resetAfterTest();
$this->setTimezone('Pacific/Auckland', 'Pacific/Auckland');
if (!$format) {
$format = "%c";
} else {
$format = get_string($format, 'langconfig');
}
$this->assertSame($expected, core_date::strftime($format, $input));
public function test_strftime(mixed $input, string $format, string $expected): void {
$this->assertEqualsIgnoringWhitespace($expected, core_date::strftime($format, $input));
}
}