Tests a simple entity type, with two different simple fields.
function testSimpleEntityType() {
$field_1_name = 'field_text';
$field_1_label = 'Simple text field';
$this
->createFieldWithInstance($field_1_name, 'text', 1, $field_1_label, array(
'text_processing' => 0,
), 'text_textfield', array(
'size' => 42,
), 'text_default', array());
$field_2_name = 'field_nr';
$field_2_label = 'Simple number field';
$this
->createFieldWithInstance($field_2_name, 'number_integer', 1, $field_2_label, array(), 'number', array(), 'number_integer', array());
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->is_new = TRUE;
$this->entity->{$field_1_name}->value = 'Test';
$this->entity->{$field_2_name}->value = 42;
$this->entity
->save();
$entity = entity_load('entity_test', $this->entity
->id());
// Verify metadata for field 1.
$instance_1 = field_info_instance($entity
->entityType(), $field_1_name, $entity
->bundle());
$metadata_1 = $this->metadataGenerator
->generate($entity, $instance_1, Language::LANGCODE_NOT_SPECIFIED, 'default');
$expected_1 = array(
'access' => TRUE,
'label' => 'Simple text field',
'editor' => 'direct',
'aria' => 'Entity entity_test 1, field Simple text field',
);
$this
->assertEqual($expected_1, $metadata_1, 'The correct metadata is generated for the first field.');
// Verify metadata for field 2.
$instance_2 = field_info_instance($entity
->entityType(), $field_2_name, $entity
->bundle());
$metadata_2 = $this->metadataGenerator
->generate($entity, $instance_2, Language::LANGCODE_NOT_SPECIFIED, 'default');
$expected_2 = array(
'access' => TRUE,
'label' => 'Simple number field',
'editor' => 'form',
'aria' => 'Entity entity_test 1, field Simple number field',
);
$this
->assertEqual($expected_2, $metadata_2, 'The correct metadata is generated for the second field.');
}