public function FieldTest::testDatetimeRangeFieldTokens in Token 8
Tests support for a daterange fields.
File
- tests/
src/ Kernel/ FieldTest.php, line 712
Class
- FieldTest
- Tests field tokens.
Namespace
Drupal\Tests\token\KernelCode
public function testDatetimeRangeFieldTokens() {
/** @var \Drupal\node\NodeInterface $node */
$node = Node::create([
'title' => 'Node for daterange field',
'type' => 'article',
]);
$node
->get('field_daterange')->value = '2013-12-22T00:00:00';
$node
->get('field_daterange')->end_value = '2016-08-26T00:00:00';
$node
->get('field_daterange')
->appendItem([
'value' => '2014-08-22T00:00:00',
'end_value' => '2017-12-20T00:00:00',
]);
$node
->get('field_daterange')->value = '2013-12-22T00:00:00';
$node
->get('field_daterange')->end_value = '2016-08-26T00:00:00';
$node
->save();
$this
->assertTokens('node', [
'node' => $node,
], [
'field_daterange:start_date:html_month' => '2013-12',
'field_daterange:start_date:custom:Y' => '2013',
'field_daterange:end_date:custom:Y' => '2016',
'field_daterange:start_date' => $node
->get('field_daterange')->start_date
->getTimestamp(),
'field_daterange:0:start_date:html_month' => '2013-12',
'field_daterange:0:start_date:custom:Y' => '2013',
'field_daterange:0:end_date:custom:Y' => '2016',
'field_daterange:0:start_date' => $node
->get('field_daterange')->start_date
->getTimestamp(),
'field_daterange:1:start_date:html_month' => '2014-08',
'field_daterange:1:start_date:custom:Y' => '2014',
'field_daterange:1:end_date:custom:Y' => '2017',
'field_daterange:1:end_date' => $node
->get('field_daterange')
->get(1)->end_date
->getTimestamp(),
]);
}