You are here

public function TwigExtensionTest::testFormatDate in Drupal 10

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

Class

TwigExtensionTest
Tests the twig extension.

Namespace

Drupal\Tests\Core\Template

Code

public function testFormatDate() {
  $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);
}