function TwigExtensionTest::testFormatDate
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testFormatDate()
- 8.9.x core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testFormatDate()
- 10 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testFormatDate()
Tests the format_date filter.
File
-
core/
tests/ Drupal/ Tests/ Core/ Template/ TwigExtensionTest.php, line 172
Class
- TwigExtensionTest
- Tests the twig extension.
Namespace
Drupal\Tests\Core\TemplateCode
public function testFormatDate() : void {
$this->dateFormatter
->expects($this->exactly(1))
->method('format')
->willReturnCallback(function ($timestamp) {
return date('Y-m-d', $timestamp);
});
$loader = new StringLoader();
$twig = new Environment($loader);
$twig->addExtension($this->systemUnderTest);
$timestamp = strtotime('1978-11-19');
$result = $twig->render('{{ time|format_date("html_date") }}', [
'time' => $timestamp,
]);
$this->assertEquals('1978-11-19', $result);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.