function DateTest::testFormattedDateDiff
Same name in other branches
- 9 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()
- 11.x 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 403
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->assertArrayEquals($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']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.