You are here

public function FieldTest::testDatetimeFieldTokens in Token 8

Tests support for a datetime fields.

File

tests/src/Kernel/FieldTest.php, line 688

Class

FieldTest
Tests field tokens.

Namespace

Drupal\Tests\token\Kernel

Code

public function testDatetimeFieldTokens() {
  $node = Node::create([
    'title' => 'Node for datetime field',
    'type' => 'article',
  ]);
  $node
    ->set('field_datetime', [
    '1925-09-28T00:00:00',
    '1930-10-28T00:00:00',
  ])
    ->save();
  $this
    ->assertTokens('node', [
    'node' => $node,
  ], [
    'field_datetime:date:custom:Y' => '1925',
    'field_datetime:date:html_month' => '1925-09',
    'field_datetime:date' => $node
      ->get('field_datetime')->date
      ->getTimestamp(),
    'field_datetime:0:date:custom:Y' => '1925',
    'field_datetime:0:date:html_month' => '1925-09',
    'field_datetime:0:date' => $node
      ->get('field_datetime')->date
      ->getTimestamp(),
    'field_datetime:1:date:custom:Y' => '1930',
    'field_datetime:1:date:html_month' => '1930-10',
    'field_datetime:1:date' => $node
      ->get('field_datetime')
      ->get(1)->date
      ->getTimestamp(),
  ]);
}