function FieldTestBase::assertFieldValues

Assert that a field has the expected values in an entity.

This function only checks a single column in the field values.

Parameters

EntityInterface $entity: The entity to test.

$field_name: The name of the field to test

$langcode: The language code for the values.

$expected_values: The array of expected values.

$column: (Optional) the name of the column to check.

5 calls to FieldTestBase::assertFieldValues()
OptionsWidgetsTest::testCheckBoxes in drupal/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
Tests the 'options_buttons' widget (multiple select).
OptionsWidgetsTest::testOnOffCheckbox in drupal/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
Tests the 'options_onoff' widget.
OptionsWidgetsTest::testRadioButtons in drupal/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
Tests the 'options_buttons' widget (single select).
OptionsWidgetsTest::testSelectListMultiple in drupal/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
Tests the 'options_select' widget (multiple select).
OptionsWidgetsTest::testSelectListSingle in drupal/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
Tests the 'options_select' widget (single select).
1 method overrides FieldTestBase::assertFieldValues()
FormTest::assertFieldValues in drupal/core/modules/field/lib/Drupal/field/Tests/FormTest.php
{inheritdoc}

File

drupal/core/modules/field/lib/Drupal/field/Tests/FieldTestBase.php, line 51
Definition of Drupal\field\Tests\FieldTestBase.

Class

FieldTestBase
Parent class for Field API tests.

Namespace

Drupal\field\Tests

Code

function assertFieldValues(EntityInterface $entity, $field_name, $langcode, $expected_values, $column = 'value') {

  // Re-load the entity to make sure we have the latest changes.
  entity_get_controller($entity
    ->entityType())
    ->resetCache(array(
    $entity
      ->id(),
  ));
  $e = entity_load($entity
    ->entityType(), $entity
    ->id());
  $field = $values = $e
    ->getTranslation($langcode, FALSE)->{$field_name};

  // Filter out empty values so that they don't mess with the assertions.
  $field
    ->filterEmptyValues();
  $values = $field
    ->getValue();
  $this
    ->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.');
  foreach ($expected_values as $key => $value) {
    $this
      ->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', array(
      '@value' => $value,
    )));
  }
}