public function DateTimeDayFieldTest::testDateStorageSettings in Date time day 8
Tests that field storage setting form is disabled if field has data.
File
- tests/
src/ Functional/ DateTimeDayFieldTest.php, line 200
Class
- DateTimeDayFieldTest
- Tests date_time_day field functionality.
Namespace
Drupal\Tests\date_time_day\FunctionalCode
public function testDateStorageSettings() {
// Create a test content type.
$this
->drupalCreateContentType([
'type' => 'date_content',
]);
// Create a field storage with settings to validate.
$field_name = mb_strtolower($this
->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'datetimeday',
'settings' => [
'datetime_type' => DateTimeItem::DATETIME_TYPE_DATE,
'time_type' => DateTimeDayItem::DATEDAY_TIME_DEFAULT_TYPE_FORMAT,
],
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'field_name' => $field_name,
'bundle' => 'date_content',
]);
$field
->save();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
$display_repository
->getFormDisplay('node', 'date_content', 'default')
->setComponent($field_name, [
'type' => 'datetimeday_default',
])
->save();
$edit = [
'title[0][value]' => $this
->randomString(),
'body[0][value]' => $this
->randomString(),
$field_name . '[0][value][date]' => '2016-04-01',
$field_name . '[0][start_time_value]' => '10:00',
$field_name . '[0][end_time_value]' => '19:00',
];
$this
->drupalPostForm('node/add/date_content', $edit, t('Save'));
$this
->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name . '/storage');
$result = $this
->xpath("//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]");
$this
->assertEqual(count($result), 1, "Changing datetime setting is disabled.");
$this
->assertSession()
->pageTextContains('There is data for this field in the database. The field settings can no longer be changed.');
}