From 054d15a42f55b54eacd65b640d899fee404b176a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 18 Mar 2024 23:41:10 +0800 Subject: [PATCH] MDL-81074 core: Simplify strftime tests --- lib/tests/date_test.php | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/lib/tests/date_test.php b/lib/tests/date_test.php index c7dc89caef4..ed825e84d4e 100644 --- a/lib/tests/date_test.php +++ b/lib/tests/date_test.php @@ -624,33 +624,33 @@ class date_test extends advanced_testcase { return [ 'string_c' => [ "1708405742", - null, - "20 February 2024 at 6:09 pm", + "%c", + "20 February 2024 at 1:09 pm", ], 'numeric_c' => [ 1708405742, - null, - "20 February 2024 at 6:09 pm", + "%c", + "20 February 2024 at 1:09 pm", ], '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)); } }