function DateTimeTest::testEnteringDateTimeViaSelectors
Same name in other branches
- 8.9.x 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()
Tests handling case with invalid data in selectors (like February, 31st).
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ DateTimeTest.php, line 207
Class
- DateTimeTest
- 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->drupalGet('admin/structure/types/manage/page_with_date/fields/add-field');
$this->submitForm($edit, 'Save and continue');
// Check that the new datetime field was created, and process is now set
// to continue for configuration.
$this->assertSession()
->pageTextContains('These settings apply to the');
$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->drupalGet('admin/structure/types/manage/page_with_date/fields/node.page_with_date.field_dt/storage');
$this->submitForm($edit, 'Save field settings');
$this->drupalGet('admin/structure/types/manage/page_with_date/fields');
$this->assertSession()
->pageTextContains('field_dt');
$this->drupalGet('admin/structure/types/manage/page_with_date/form-display');
$edit = [
'fields[field_dt][type]' => 'datetime_datelist',
'fields[field_dt][region]' => 'content',
];
$this->drupalGet('admin/structure/types/manage/page_with_date/form-display');
$this->submitForm($edit, '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->drupalGet('node/add/page_with_date');
$this->submitForm($edit, 'Save');
$this->assertSession()
->pageTextContains('Selected combination of day and month is not valid.');
$edit['field_dt[0][value][day]'] = '29';
$this->drupalGet('node/add/page_with_date');
$this->submitForm($edit, 'Save');
$this->assertSession()
->pageTextNotContains('Selected combination of day and month is not valid.');
$this->drupalGet('node/1');
$this->assertSession()
->pageTextContains('Mon, 02/29/2016 - 01:30');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.