From 63d170647cfbeebf39b9b53f6f134e58e3da5b12 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 19 Apr 2018 14:28:00 +0800 Subject: [PATCH] MDL-62049 core_privacy: use correct lang string for date --- privacy/classes/local/request/transform.php | 2 +- privacy/tests/request_transform_test.php | 27 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/privacy/classes/local/request/transform.php b/privacy/classes/local/request/transform.php index 34a3bd15ad9..48c38658b3f 100644 --- a/privacy/classes/local/request/transform.php +++ b/privacy/classes/local/request/transform.php @@ -64,7 +64,7 @@ class transform { * @return string The translated string. */ public static function date($date) { - return userdate($date, get_string('strftimetime', 'langconfig')); + return userdate($date, get_string('strftimedate', 'langconfig')); } /** diff --git a/privacy/tests/request_transform_test.php b/privacy/tests/request_transform_test.php index 15876adc19b..3926f5f1aed 100644 --- a/privacy/tests/request_transform_test.php +++ b/privacy/tests/request_transform_test.php @@ -53,14 +53,37 @@ class request_transform_test extends advanced_testcase { * Test that the datetime is translated into a string. */ public function test_datetime() { - $this->assertInternalType('string', transform::datetime(1)); + $time = 1; + + $datestr = transform::datetime($time); + + // Assert it is a string. + $this->assertInternalType('string', $datestr); + + // To prevent failures on MAC where we are returned with a lower-case 'am' we want to convert this to 'AM'. + $datestr = str_replace('am', 'AM', $datestr); + + // Assert the formatted date is correct. + $dateobj = new DateTime(); + $dateobj->setTimestamp($time); + $this->assertEquals($dateobj->format('l, j F Y, g:i A'), $datestr); } /** * Test that the date is translated into a string. */ public function test_date() { - $this->assertInternalType('string', transform::date(1)); + $time = 1; + + $datestr = transform::date($time); + + // Assert it is a string. + $this->assertInternalType('string', $datestr); + + // Assert the formatted date is correct. + $dateobj = new DateTime(); + $dateobj->setTimestamp($time); + $this->assertEquals($dateobj->format('j F Y'), $datestr); } /** -- 2.17.1