You are here

public function DateTimeItemTest::testDatetimeValidation in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php \Drupal\Tests\datetime\Kernel\DateTimeItemTest::testDatetimeValidation()
  2. 10 core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php \Drupal\Tests\datetime\Kernel\DateTimeItemTest::testDatetimeValidation()

Tests the constraint validations for fields with date and time.

@dataProvider datetimeValidationProvider

File

core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php, line 258

Class

DateTimeItemTest
Tests the new entity API for the date field type.

Namespace

Drupal\Tests\datetime\Kernel

Code

public function testDatetimeValidation($value) {
  $this
    ->expectException(AssertionFailedError::class);
  $this->fieldStorage
    ->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATETIME);
  $this->fieldStorage
    ->save();
  $entity = EntityTest::create();
  $entity
    ->set('field_datetime', $value);
  $this
    ->entityValidateAndSave($entity);
}