1 field.test | FieldTestCase::assertFieldValues($entity, $field_name, $langcode, $expected_values, $column = 'value') |
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.
File
- core/
modules/ field/ tests/ field.test, line 44 - Tests for field.module.
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)));
}
}