function FieldTestCase::assertFieldValues

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

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

Parameters

$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.

7 calls to FieldTestCase::assertFieldValues()
FieldFormTestCase::testFieldFormMultipleWidget in modules/field/tests/field.test
Tests widgets handling multiple values.
FieldFormTestCase::testNestedFieldForm in modules/field/tests/field.test
Tests Field API form integration within a subform.
OptionsWidgetsTestCase::testCheckBoxes in modules/field/modules/options/options.test
Tests the 'options_buttons' widget (multiple select).
OptionsWidgetsTestCase::testOnOffCheckbox in modules/field/modules/options/options.test
Tests the 'options_onoff' widget.
OptionsWidgetsTestCase::testRadioButtons in modules/field/modules/options/options.test
Tests the 'options_buttons' widget (single select).

... See full list

File

modules/field/tests/field.test, line 63

Class

FieldTestCase
Parent class for Field API tests.

Code

function assertFieldValues($entity, $field_name, $langcode, $expected_values, $column = 'value') {
    $e = clone $entity;
    field_attach_load('test_entity', array(
        $e->ftid => $e,
    ));
    $values = isset($e->{$field_name}[$langcode]) ? $e->{$field_name}[$langcode] : array();
    $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,
        )));
    }
}

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