You are here

protected function FieldKernelTestBase::entityValidateAndSave in Drupal 8

Same name and namespace in other branches
  1. 9 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 151

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