public function DateTest::testFormattedDateDiff in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::testFormattedDateDiff()
- 10 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::testFormattedDateDiff()
Tests FormattedDateDiff.
@covers \Drupal\Core\Datetime\FormattedDateDiff::toRenderable @covers \Drupal\Core\Datetime\FormattedDateDiff::getString @covers \Drupal\Core\Datetime\FormattedDateDiff::getCacheMaxAge
File
- core/
tests/ Drupal/ Tests/ Core/ Datetime/ DateTest.php, line 395
Class
- DateTest
- @coversDefaultClass \Drupal\Core\Datetime\DateFormatter @group Datetime
Namespace
Drupal\Tests\Core\DatetimeCode
public function testFormattedDateDiff() {
$string = '10 minutes';
$max_age = 60;
$object = new FormattedDateDiff($string, $max_age);
// Test conversion to a render array.
$expected = [
'#markup' => $string,
'#cache' => [
'max-age' => $max_age,
],
];
$this
->assertEquals($expected, $object
->toRenderable());
// Test retrieving the formatted time difference string.
$this
->assertEquals($string, $object
->getString());
// Test applying cacheability data to an existing build.
$build = [];
CacheableMetadata::createFromObject($object)
->applyTo($build);
$this
->assertEquals($max_age, $build['#cache']['max-age']);
}