function FieldItemTest::testSaveWorkflow

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

Tests the field item save workflow.

File

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

Class

FieldItemTest
Test field item methods.

Namespace

Drupal\KernelTests\Core\Field

Code

public function testSaveWorkflow() {
    $entity = EntityTestMulRev::create([
        'name' => $this->randomString(),
        'field_test_item' => $this->randomString(),
        $this->fieldName => $this->randomString(),
    ]);
    // Save a new entity and verify that the initial field value is overwritten
    // with a value containing the entity id, which implies a resave. Check that
    // the entity data structure and the stored values match.
    $this->assertSavedFieldItemValue($entity, "field_test:{$this->fieldName}:1:1");
    // Update the entity and verify that the field value is overwritten on
    // presave if it is not resaved.
    $this->assertSavedFieldItemValue($entity, 'overwritten');
    // Flag the field value as needing to be resaved and verify it actually is.
    $entity->field_test_item->value = $entity->{$this->fieldName}->value = 'resave';
    $this->assertSavedFieldItemValue($entity, "field_test:{$this->fieldName}:1:3");
}

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