protected function TimestampFormatterTest::testTimestampFormatter in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/Timestamp/TimestampFormatterTest.php \Drupal\field\Tests\Timestamp\TimestampFormatterTest::testTimestampFormatter()
Tests TimestampFormatter.
File
- core/
modules/ field/ src/ Tests/ Timestamp/ TimestampFormatterTest.php, line 107 - Contains \Drupal\field\Tests\Timestamp\TimestampFormatterTest.
Class
- TimestampFormatterTest
- Tests the timestamp formatters.
Namespace
Drupal\field\Tests\TimestampCode
protected function testTimestampFormatter() {
$data = [];
// Test standard formats.
$date_formats = array_keys(\Drupal::entityManager()
->getStorage('date_format')
->loadMultiple());
foreach ($date_formats as $date_format) {
$data[] = [
'date_format' => $date_format,
'custom_date_format' => '',
'timezone' => '',
];
}
$data[] = [
'date_format' => 'custom',
'custom_date_format' => 'r',
'timezone' => '',
];
$data[] = [
'date_format' => 'custom',
'custom_date_format' => 'e',
'timezone' => 'Asia/Tokyo',
];
foreach ($data as $settings) {
list($date_format, $custom_date_format, $timezone) = array_values($settings);
if (empty($timezone)) {
$timezone = NULL;
}
$value = REQUEST_TIME - 87654321;
$expected = \Drupal::service('date.formatter')
->format($value, $date_format, $custom_date_format, $timezone);
$component = $this->display
->getComponent($this->fieldName);
$component['type'] = 'timestamp';
$component['settings'] = $settings;
$this->display
->setComponent($this->fieldName, $component);
$entity = EntityTest::create([]);
$entity->{$this->fieldName}->value = $value;
$this
->renderEntityFields($entity, $this->display);
$this
->assertRaw($expected);
}
}