function FieldItemTest::assertSavedFieldItemValue

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php \Drupal\KernelTests\Core\Field\FieldItemTest::assertSavedFieldItemValue()
  2. 10 core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php \Drupal\KernelTests\Core\Field\FieldItemTest::assertSavedFieldItemValue()
  3. 11.x core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php \Drupal\KernelTests\Core\Field\FieldItemTest::assertSavedFieldItemValue()

Checks that the saved field item value matches the expected one.

@internal

Parameters

\Drupal\entity_test\Entity\EntityTest $entity: The test entity.

string $expected_value: The expected field item value.

1 call to FieldItemTest::assertSavedFieldItemValue()
FieldItemTest::testSaveWorkflow in core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php
Tests the field item save workflow.

File

core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php, line 91

Class

FieldItemTest
Test field item methods.

Namespace

Drupal\KernelTests\Core\Field

Code

protected function assertSavedFieldItemValue(EntityTest $entity, string $expected_value) : void {
    $entity->setNewRevision(TRUE);
    $entity->save();
    $base_field_expected_value = str_replace($this->fieldName, 'field_test_item', $expected_value);
    $this->assertEquals($base_field_expected_value, $entity->field_test_item->value);
    $this->assertEquals($expected_value, $entity->{$this->fieldName}->value);
    $entity = $this->reloadEntity($entity);
    $this->assertEquals($base_field_expected_value, $entity->field_test_item->value);
    $this->assertEquals($expected_value, $entity->{$this->fieldName}->value);
}

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