Tests using entity fields of the field field type.
public function testShapeItem() {
// Verify entity creation.
$entity = entity_create('entity_test', array());
$shape = 'cube';
$color = 'blue';
$entity->field_shape->shape = $shape;
$entity->field_shape->color = $color;
$entity->name->value = $this
->randomName();
$entity
->save();
// Verify entity has been created properly.
$id = $entity
->id();
$entity = entity_load('entity_test', $id);
$this
->assertTrue($entity->field_shape instanceof FieldInterface, 'Field implements interface.');
$this
->assertTrue($entity->field_shape[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this
->assertEqual($entity->field_shape->shape, $shape);
$this
->assertEqual($entity->field_shape->color, $color);
$this
->assertEqual($entity->field_shape[0]->shape, $shape);
$this
->assertEqual($entity->field_shape[0]->color, $color);
// Verify changing the field value.
$new_shape = 'circle';
$new_color = 'red';
$entity->field_shape->shape = $new_shape;
$entity->field_shape->color = $new_color;
$this
->assertEqual($entity->field_shape->shape, $new_shape);
$this
->assertEqual($entity->field_shape->color, $new_color);
// Read changed entity and assert changed values.
$entity
->save();
$entity = entity_load('entity_test', $id);
$this
->assertEqual($entity->field_shape->shape, $new_shape);
$this
->assertEqual($entity->field_shape->color, $new_color);
}