function DateTimeTest::testEnteringDateTimeViaSelectors

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/System/DateTimeTest.php \Drupal\Tests\system\Functional\System\DateTimeTest::testEnteringDateTimeViaSelectors()
  2. 8.9.x core/modules/system/tests/src/Functional/System/DateTimeTest.php \Drupal\Tests\system\Functional\System\DateTimeTest::testEnteringDateTimeViaSelectors()
  3. 10 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 210

Class

DateTimeTest
Test date formatting and time zone handling, including daylight saving time.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testEnteringDateTimeViaSelectors() : void {
    $this->drupalCreateContentType([
        'type' => 'page_with_date',
        'name' => 'Page with date',
    ]);
    $this->drupalGet('admin/structure/types/manage/page_with_date');
    $this->assertSession()
        ->statusCodeEquals(200);
    $storage_edit = [
        'field_storage[subform][settings][datetime_type]' => 'datetime',
        'field_storage[subform][cardinality]' => 'number',
        'field_storage[subform][cardinality_number]' => '1',
    ];
    $this->fieldUIAddNewField('admin/structure/types/manage/page_with_date', 'dt', 'dt', 'datetime', $storage_edit);
    $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, 29 Feb 2016 - 01:30');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.