function FieldKernelTestBase::entityValidateAndSave

Same name in other branches
  1. 8.9.x core/modules/field/tests/src/Kernel/FieldKernelTestBase.php \Drupal\Tests\field\Kernel\FieldKernelTestBase::entityValidateAndSave()
  2. 10 core/modules/field/tests/src/Kernel/FieldKernelTestBase.php \Drupal\Tests\field\Kernel\FieldKernelTestBase::entityValidateAndSave()
  3. 11.x core/modules/field/tests/src/Kernel/FieldKernelTestBase.php \Drupal\Tests\field\Kernel\FieldKernelTestBase::entityValidateAndSave()

Validate and save entity. Fail if violations are found.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to save.

20 calls to FieldKernelTestBase::entityValidateAndSave()
BooleanItemTest::testBooleanItem in core/modules/field/tests/src/Kernel/Boolean/BooleanItemTest.php
Tests using entity fields of the boolean field type.
CommentItemTest::testCommentItem in core/modules/comment/tests/src/Kernel/CommentItemTest.php
Tests using entity fields of the comment field type.
DateTimeItemTest::testDateOnly in core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php
Tests using entity fields of the date field type.
DateTimeItemTest::testDateonlyValidation in core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php
Tests the constraint validations for fields with date only.
DateTimeItemTest::testDateTime in core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php
Tests using entity fields of the datetime field type.

... See full list

File

core/modules/field/tests/src/Kernel/FieldKernelTestBase.php, line 156

Class

FieldKernelTestBase
Parent class for Field API unit tests.

Namespace

Drupal\Tests\field\Kernel

Code

protected function entityValidateAndSave(EntityInterface $entity) {
    $violations = $entity->validate();
    if ($violations->count()) {
        $this->fail($violations);
    }
    else {
        $entity->save();
    }
}

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