You are here

protected function FieldItemTest::assertSavedFieldItemValue in Drupal 8

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

Parameters

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

$expected_value: The expected field item value.

Return value

bool TRUE if the item value matches expectations, FALSE otherwise.

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 92

Class

FieldItemTest
Test field item methods.

Namespace

Drupal\KernelTests\Core\Field

Code

protected function assertSavedFieldItemValue(EntityTest $entity, $expected_value) {
  $entity
    ->setNewRevision(TRUE);
  $entity
    ->save();
  $base_field_expected_value = str_replace($this->fieldName, 'field_test_item', $expected_value);
  $result = $this
    ->assertEqual($entity->field_test_item->value, $base_field_expected_value);
  $result = $result && $this
    ->assertEqual($entity->{$this->fieldName}->value, $expected_value);
  $entity = $this
    ->reloadEntity($entity);
  $result = $result && $this
    ->assertEqual($entity->field_test_item->value, $base_field_expected_value);
  $result = $result && $this
    ->assertEqual($entity->{$this->fieldName}->value, $expected_value);
  return $result;
}