function DateTimeTest::testEnteringDateTimeViaSelectors
Same name in other branches
- 9 core/modules/system/tests/src/Functional/System/DateTimeTest.php \Drupal\Tests\system\Functional\System\DateTimeTest::testEnteringDateTimeViaSelectors()
- 10 core/modules/system/tests/src/Functional/System/DateTimeTest.php \Drupal\Tests\system\Functional\System\DateTimeTest::testEnteringDateTimeViaSelectors()
- 11.x core/modules/system/tests/src/Functional/System/DateTimeTest.php \Drupal\Tests\system\Functional\System\DateTimeTest::testEnteringDateTimeViaSelectors()
Test handling case with invalid data in selectors (like February, 31st).
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ DateTimeTest.php, line 184
Class
- DateTimeTest
- Configure date and time settings. Test date formatting and time zone handling, including daylight saving time.
Namespace
Drupal\Tests\system\Functional\SystemCode
public function testEnteringDateTimeViaSelectors() {
$this->drupalCreateContentType([
'type' => 'page_with_date',
'name' => 'Page with date',
]);
$this->drupalGet('admin/structure/types/manage/page_with_date');
$this->assertSession()
->statusCodeEquals(200);
$this->drupalGet('admin/structure/types/manage/page_with_date/fields/add-field');
$edit = [
'new_storage_type' => 'datetime',
'label' => 'dt',
'field_name' => 'dt',
];
$this->drupalPostForm('admin/structure/types/manage/page_with_date/fields/add-field', $edit, t('Save and continue'));
$this->assertText(t('These settings apply to the'), 'New datetime field created, now configuring');
$this->drupalGet('admin/structure/types/manage/page_with_date/fields/node.page_with_date.field_dt/storage');
$edit = [
'settings[datetime_type]' => 'datetime',
'cardinality' => 'number',
'cardinality_number' => '1',
];
$this->drupalPostForm('admin/structure/types/manage/page_with_date/fields/node.page_with_date.field_dt/storage', $edit, t('Save field settings'));
$this->drupalGet('admin/structure/types/manage/page_with_date/fields');
$this->assertText('field_dt', 'New field is in place');
$this->drupalGet('admin/structure/types/manage/page_with_date/form-display');
$edit = [
'fields[field_dt][type]' => 'datetime_datelist',
'fields[field_dt][region]' => 'content',
];
$this->drupalPostForm('admin/structure/types/manage/page_with_date/form-display', $edit, t('Save'));
$this->drupalLogout();
// Now log in as a regular editor.
$this->drupalLogin($this->drupalCreateUser([
'create page_with_date content',
]));
$this->drupalGet('node/add/page_with_date');
$edit = [
'title[0][value]' => 'sample doc',
'field_dt[0][value][year]' => '2016',
'field_dt[0][value][month]' => '2',
'field_dt[0][value][day]' => '31',
'field_dt[0][value][hour]' => '1',
'field_dt[0][value][minute]' => '30',
];
$this->drupalPostForm('node/add/page_with_date', $edit, t('Save'));
$this->assertText(t('Selected combination of day and month is not valid.'), 'Inorrect date failed validation');
$edit['field_dt[0][value][day]'] = '29';
$this->drupalPostForm('node/add/page_with_date', $edit, t('Save'));
$this->assertNoText(t('Selected combination of day and month is not valid.'), 'Correct date passed validation.');
$this->drupalGet('node/1');
$this->assertText(t('Mon, 02/29/2016 - 01:30'), 'Node successfully created with valid date.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.