public function TwigExtensionTest::testFormatDate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 110 - Contains \Drupal\Tests\Core\Template\TwigExtensionTest.
Class
- TwigExtensionTest
- Tests the twig extension.
Namespace
Drupal\Tests\Core\TemplateCode
public function testFormatDate() {
$date_formatter = $this
->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatter')
->disableOriginalConstructor()
->getMock();
$date_formatter
->expects($this
->exactly(2))
->method('format')
->willReturn('1978-11-19');
$renderer = $this
->getMock('\\Drupal\\Core\\Render\\RendererInterface');
$extension = new TwigExtension($renderer);
$extension
->setDateFormatter($date_formatter);
$loader = new StringLoader();
$twig = new \Twig_Environment($loader);
$twig
->addExtension($extension);
$result = $twig
->render('{{ time|format_date("html_date") }}');
$this
->assertEquals($date_formatter
->format('html_date'), $result);
}