From b1cf4cbbd5a5eae51b034e5f14f14abea493af1b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 24 Sep 2022 14:22:27 +0200 Subject: [PATCH] Changes: - added unit-test for `Temporal::getRelativeDate()` method --- tests/src/Util/TemporalTest.php | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/src/Util/TemporalTest.php diff --git a/tests/src/Util/TemporalTest.php b/tests/src/Util/TemporalTest.php new file mode 100644 index 0000000000..a2f76114d3 --- /dev/null +++ b/tests/src/Util/TemporalTest.php @@ -0,0 +1,59 @@ +. + * + */ + +namespace Friendica\Test\src\Util; + +use Friendica\DI; +use Friendica\Util\Temporal; +use PHPUnit\Framework\TestCase; + +/** + * Temporal utility test class + */ +class TemporalTest extends TestCase +{ + /** + * Checks for getRelativeDate() + */ + public function testGetRelativeDate() + { + // "never" would should be returned + self::assertEquals( + Temporal::getRelativeDate(''), + DI::l10n()->t('never') + ); + + // Format current date/time into "MySQL" format + $now = date('Y-m-d H:i:s'); + self::assertEquals( + Temporal::getRelativeDate($now), + DI::l10n()->t('less than a second ago') + ); + + // Format current date/time - 1 minute into "MySQL" format + $minuteAgo = date('Y-m-d H:i:s', time() - 60); + $format = DI::l10n()->t('%1$d %2$s ago'); + self::assertEquals( + Temporal::getRelativeDate($minuteAgo), + sprintf($format, 1, DI::l10n()->t('minute')) + ); + } +} -- 2.39.5