You are here

public function TwigExtensionTest::testFormatDate in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php \Drupal\Tests\Core\Template\TwigExtensionTest::testFormatDate()
  2. 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 150

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public function testFormatDate() {
  $this->dateFormatter
    ->expects($this
    ->exactly(1))
    ->method('format')
    ->will($this
    ->returnCallback(function ($timestamp) {
    return date('Y-m-d', $timestamp);
  }));
  $loader = new StringLoader();
  $twig = new \Twig_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);
}