You are here

public function DateTimeTest::testEnteringDateTimeViaSelectors in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/System/DateTimeTest.php \Drupal\Tests\system\Functional\System\DateTimeTest::testEnteringDateTimeViaSelectors()
  2. 9 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 205

Class

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

Namespace

Drupal\Tests\system\Functional\System

Code

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');
}