diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-09-25 11:28:56 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-09-25 18:09:24 +0200 |
commit | 459c62b3399a4e276fb96e97cbbdbd70bd1676b7 (patch) | |
tree | e2e937b3e792d872fbbc1f8529040455ea49d6a6 | |
parent | 85bc9b69aebe438ace75aaafc2e04fcf9b08a9d9 (diff) | |
download | forums-459c62b3399a4e276fb96e97cbbdbd70bd1676b7.tar forums-459c62b3399a4e276fb96e97cbbdbd70bd1676b7.tar.gz forums-459c62b3399a4e276fb96e97cbbdbd70bd1676b7.tar.bz2 forums-459c62b3399a4e276fb96e97cbbdbd70bd1676b7.tar.xz forums-459c62b3399a4e276fb96e97cbbdbd70bd1676b7.zip |
[ticket/13105] Add a test for relative dates
PHPBB3-13105
-rw-r--r-- | tests/datetime/from_format_test.php | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php index 5f155adbbd..0f87abc180 100644 --- a/tests/datetime/from_format_test.php +++ b/tests/datetime/from_format_test.php @@ -37,8 +37,6 @@ class phpbb_datetime_from_format_test extends phpbb_test_case */ public function test_from_format($timezone, $format, $expected) { - global $user; - $user = new \phpbb\user('\phpbb\datetime'); $user->timezone = new DateTimeZone($timezone); $user->lang['datetime'] = array( @@ -55,4 +53,74 @@ class phpbb_datetime_from_format_test extends phpbb_test_case $timestamp = $user->get_timestamp_from_format($format, $expected, new DateTimeZone($timezone)); $this->assertEquals($expected, $user->format_date($timestamp, $format, true)); } + + + public function relative_format_date_data() + { + // If the current time is too close to the testing time, + // the relative time will use "x minutes ago" instead of "today ..." + // So we use 18:01 in the morning and 06:01 in the afternoon. + $testing_time = date('H') <= 12 ? '06:01' : '18:01'; + + return array( + array( + date('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time, false, + date('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time, + ), + + array( + date('Y-m-d', time() + 86400) . ' ' . $testing_time, false, + 'Tomorrow ' . $testing_time, + ), + array( + date('Y-m-d', time() + 86400) . ' ' . $testing_time, true, + date('Y-m-d', time() + 86400) . ' ' . $testing_time, + ), + + array( + date('Y-m-d') . ' ' . $testing_time, false, + 'Today ' . $testing_time, + ), + array( + date('Y-m-d') . ' ' . $testing_time, true, + date('Y-m-d') . ' ' . $testing_time, + ), + + array( + date('Y-m-d', time() - 86400) . ' ' . $testing_time, false, + 'Yesterday ' . $testing_time, + ), + array( + date('Y-m-d', time() - 86400) . ' ' . $testing_time, true, + date('Y-m-d', time() - 86400) . ' ' . $testing_time, + ), + + array( + date('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, false, + date('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, + ), + ); + } + + /** + * @dataProvider relative_format_date_data() + */ + public function test_relative_format_date($timestamp, $forcedate, $expected) + { + $user = new \phpbb\user('\phpbb\datetime'); + $user->timezone = new DateTimeZone('UTC'); + $user->lang['datetime'] = array( + 'TODAY' => 'Today', + 'TOMORROW' => 'Tomorrow', + 'YESTERDAY' => 'Yesterday', + 'AGO' => array( + 0 => 'less than a minute ago', + 1 => '%d minute ago', + 2 => '%d minutes ago', + ), + ); + + $timestamp = $user->get_timestamp_from_format('Y-m-d H:i', $timestamp, new DateTimeZone('UTC')); + $this->assertEquals($expected, $user->format_date($timestamp, '|Y-m-d| H:i', $forcedate)); + } } |