function DateTimeItemTest::testDateOnlyValidation

Same name in other branches
  1. 9 core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php \Drupal\Tests\datetime\Kernel\DateTimeItemTest::testDateonlyValidation()
  2. 8.9.x core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php \Drupal\Tests\datetime\Kernel\DateTimeItemTest::testDateonlyValidation()
  3. 11.x core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php \Drupal\Tests\datetime\Kernel\DateTimeItemTest::testDateOnlyValidation()

Tests the constraint validations for fields with date only.

@dataProvider dateOnlyValidationProvider

File

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

Class

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

Namespace

Drupal\Tests\datetime\Kernel

Code

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

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