|
@@ -85,12 +85,28 @@ class FieldAttachTestCase extends FieldTestCase {
|
|
|
}
|
|
|
parent::setUp($modules);
|
|
|
|
|
|
- $this->field_name = drupal_strtolower($this->randomName() . '_field_name');
|
|
|
- $this->field = array('field_name' => $this->field_name, 'type' => 'test_field', 'cardinality' => 4);
|
|
|
- $this->field = field_create_field($this->field);
|
|
|
- $this->field_id = $this->field['id'];
|
|
|
- $this->instance = array(
|
|
|
- 'field_name' => $this->field_name,
|
|
|
+ $this->createFieldWithInstance();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Create a field and an instance of it.
|
|
|
+ *
|
|
|
+ * @param string $suffix
|
|
|
+ * (optional) A string that should only contain characters that are valid in
|
|
|
+ * PHP variable names as well.
|
|
|
+ */
|
|
|
+ function createFieldWithInstance($suffix = '') {
|
|
|
+ $field_name = 'field_name' . $suffix;
|
|
|
+ $field = 'field' . $suffix;
|
|
|
+ $field_id = 'field_id' . $suffix;
|
|
|
+ $instance = 'instance' . $suffix;
|
|
|
+
|
|
|
+ $this->$field_name = drupal_strtolower($this->randomName() . '_field_name' . $suffix);
|
|
|
+ $this->$field = array('field_name' => $this->$field_name, 'type' => 'test_field', 'cardinality' => 4);
|
|
|
+ $this->$field = field_create_field($this->$field);
|
|
|
+ $this->$field_id = $this->{$field}['id'];
|
|
|
+ $this->$instance = array(
|
|
|
+ 'field_name' => $this->$field_name,
|
|
|
'entity_type' => 'test_entity',
|
|
|
'bundle' => 'test_bundle',
|
|
|
'label' => $this->randomName() . '_label',
|
|
@@ -107,7 +123,7 @@ class FieldAttachTestCase extends FieldTestCase {
|
|
|
)
|
|
|
)
|
|
|
);
|
|
|
- field_create_instance($this->instance);
|
|
|
+ field_create_instance($this->$instance);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -641,13 +657,18 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
|
|
|
* Test field_attach_view() and field_attach_prepare_view().
|
|
|
*/
|
|
|
function testFieldAttachView() {
|
|
|
+ $this->createFieldWithInstance('_2');
|
|
|
+
|
|
|
$entity_type = 'test_entity';
|
|
|
$entity_init = field_test_create_stub_entity();
|
|
|
$langcode = LANGUAGE_NONE;
|
|
|
+ $options = array('field_name' => $this->field_name_2);
|
|
|
|
|
|
// Populate values to be displayed.
|
|
|
$values = $this->_generateTestFieldValues($this->field['cardinality']);
|
|
|
$entity_init->{$this->field_name}[$langcode] = $values;
|
|
|
+ $values_2 = $this->_generateTestFieldValues($this->field_2['cardinality']);
|
|
|
+ $entity_init->{$this->field_name_2}[$langcode] = $values_2;
|
|
|
|
|
|
// Simple formatter, label displayed.
|
|
|
$entity = clone($entity_init);
|
|
@@ -662,15 +683,47 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
|
|
|
),
|
|
|
);
|
|
|
field_update_instance($this->instance);
|
|
|
+ $formatter_setting_2 = $this->randomName();
|
|
|
+ $this->instance_2['display'] = array(
|
|
|
+ 'full' => array(
|
|
|
+ 'label' => 'above',
|
|
|
+ 'type' => 'field_test_default',
|
|
|
+ 'settings' => array(
|
|
|
+ 'test_formatter_setting' => $formatter_setting_2,
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ field_update_instance($this->instance_2);
|
|
|
+ // View all fields.
|
|
|
field_attach_prepare_view($entity_type, array($entity->ftid => $entity), 'full');
|
|
|
$entity->content = field_attach_view($entity_type, $entity, 'full');
|
|
|
$output = drupal_render($entity->content);
|
|
|
$this->content = $output;
|
|
|
- $this->assertRaw($this->instance['label'], "Label is displayed.");
|
|
|
+ $this->assertRaw($this->instance['label'], "First field's label is displayed.");
|
|
|
foreach ($values as $delta => $value) {
|
|
|
$this->content = $output;
|
|
|
$this->assertRaw("$formatter_setting|{$value['value']}", "Value $delta is displayed, formatter settings are applied.");
|
|
|
}
|
|
|
+ $this->assertRaw($this->instance_2['label'], "Second field's label is displayed.");
|
|
|
+ foreach ($values_2 as $delta => $value) {
|
|
|
+ $this->content = $output;
|
|
|
+ $this->assertRaw("$formatter_setting_2|{$value['value']}", "Value $delta is displayed, formatter settings are applied.");
|
|
|
+ }
|
|
|
+ // View single field (the second field).
|
|
|
+ field_attach_prepare_view($entity_type, array($entity->ftid => $entity), 'full', $langcode, $options);
|
|
|
+ $entity->content = field_attach_view($entity_type, $entity, 'full', $langcode, $options);
|
|
|
+ $output = drupal_render($entity->content);
|
|
|
+ $this->content = $output;
|
|
|
+ $this->assertNoRaw($this->instance['label'], "First field's label is not displayed.");
|
|
|
+ foreach ($values as $delta => $value) {
|
|
|
+ $this->content = $output;
|
|
|
+ $this->assertNoRaw("$formatter_setting|{$value['value']}", "Value $delta is displayed, formatter settings are applied.");
|
|
|
+ }
|
|
|
+ $this->assertRaw($this->instance_2['label'], "Second field's label is displayed.");
|
|
|
+ foreach ($values_2 as $delta => $value) {
|
|
|
+ $this->content = $output;
|
|
|
+ $this->assertRaw("$formatter_setting_2|{$value['value']}", "Value $delta is displayed, formatter settings are applied.");
|
|
|
+ }
|
|
|
|
|
|
// Label hidden.
|
|
|
$entity = clone($entity_init);
|
|
@@ -697,7 +750,7 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
|
|
|
$this->content = $output;
|
|
|
$this->assertNoRaw($this->instance['label'], "Hidden field: label is not displayed.");
|
|
|
foreach ($values as $delta => $value) {
|
|
|
- $this->assertNoRaw($value['value'], "Hidden field: value $delta is not displayed.");
|
|
|
+ $this->assertNoRaw("$formatter_setting|{$value['value']}", "Hidden field: value $delta is not displayed.");
|
|
|
}
|
|
|
|
|
|
// Multiple formatter.
|
|
@@ -907,11 +960,13 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
|
|
|
* hook_field_validate.
|
|
|
*/
|
|
|
function testFieldAttachValidate() {
|
|
|
+ $this->createFieldWithInstance('_2');
|
|
|
+
|
|
|
$entity_type = 'test_entity';
|
|
|
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
|
|
|
$langcode = LANGUAGE_NONE;
|
|
|
|
|
|
- // Set up values to generate errors
|
|
|
+ // Set up all but one values of the first field to generate errors.
|
|
|
$values = array();
|
|
|
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
|
|
|
$values[$delta]['value'] = -1;
|
|
@@ -920,6 +975,14 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
|
|
|
$values[1]['value'] = 1;
|
|
|
$entity->{$this->field_name}[$langcode] = $values;
|
|
|
|
|
|
+ // Set up all values of the second field to generate errors.
|
|
|
+ $values_2 = array();
|
|
|
+ for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) {
|
|
|
+ $values_2[$delta]['value'] = -1;
|
|
|
+ }
|
|
|
+ $entity->{$this->field_name_2}[$langcode] = $values_2;
|
|
|
+
|
|
|
+ // Validate all fields.
|
|
|
try {
|
|
|
field_attach_validate($entity_type, $entity);
|
|
|
}
|
|
@@ -929,26 +992,57 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
|
|
|
|
|
|
foreach ($values as $delta => $value) {
|
|
|
if ($value['value'] != 1) {
|
|
|
- $this->assertIdentical($errors[$this->field_name][$langcode][$delta][0]['error'], 'field_test_invalid', "Error set on value $delta");
|
|
|
- $this->assertEqual(count($errors[$this->field_name][$langcode][$delta]), 1, "Only one error set on value $delta");
|
|
|
+ $this->assertIdentical($errors[$this->field_name][$langcode][$delta][0]['error'], 'field_test_invalid', "Error set on first field's value $delta");
|
|
|
+ $this->assertEqual(count($errors[$this->field_name][$langcode][$delta]), 1, "Only one error set on first field's value $delta");
|
|
|
unset($errors[$this->field_name][$langcode][$delta]);
|
|
|
}
|
|
|
else {
|
|
|
- $this->assertFalse(isset($errors[$this->field_name][$langcode][$delta]), "No error set on value $delta");
|
|
|
+ $this->assertFalse(isset($errors[$this->field_name][$langcode][$delta]), "No error set on first field's value $delta");
|
|
|
}
|
|
|
}
|
|
|
- $this->assertEqual(count($errors[$this->field_name][$langcode]), 0, 'No extraneous errors set');
|
|
|
+ foreach ($values_2 as $delta => $value) {
|
|
|
+ $this->assertIdentical($errors[$this->field_name_2][$langcode][$delta][0]['error'], 'field_test_invalid', "Error set on second field's value $delta");
|
|
|
+ $this->assertEqual(count($errors[$this->field_name_2][$langcode][$delta]), 1, "Only one error set on second field's value $delta");
|
|
|
+ unset($errors[$this->field_name_2][$langcode][$delta]);
|
|
|
+ }
|
|
|
+ $this->assertEqual(count($errors[$this->field_name][$langcode]), 0, 'No extraneous errors set for first field');
|
|
|
+ $this->assertEqual(count($errors[$this->field_name_2][$langcode]), 0, 'No extraneous errors set for second field');
|
|
|
+
|
|
|
+ // Validate a single field.
|
|
|
+ $options = array('field_name' => $this->field_name_2);
|
|
|
+ try {
|
|
|
+ field_attach_validate($entity_type, $entity, $options);
|
|
|
+ }
|
|
|
+ catch (FieldValidationException $e) {
|
|
|
+ $errors = $e->errors;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($values_2 as $delta => $value) {
|
|
|
+ $this->assertIdentical($errors[$this->field_name_2][$langcode][$delta][0]['error'], 'field_test_invalid', "Error set on second field's value $delta");
|
|
|
+ $this->assertEqual(count($errors[$this->field_name_2][$langcode][$delta]), 1, "Only one error set on second field's value $delta");
|
|
|
+ unset($errors[$this->field_name_2][$langcode][$delta]);
|
|
|
+ }
|
|
|
+ $this->assertFalse(isset($errors[$this->field_name]), 'No validation errors are set for the first field, despite it having errors');
|
|
|
+ $this->assertEqual(count($errors[$this->field_name_2][$langcode]), 0, 'No extraneous errors set for second field');
|
|
|
|
|
|
// Check that cardinality is validated.
|
|
|
- $entity->{$this->field_name}[$langcode] = $this->_generateTestFieldValues($this->field['cardinality'] + 1);
|
|
|
+ $entity->{$this->field_name_2}[$langcode] = $this->_generateTestFieldValues($this->field_2['cardinality'] + 1);
|
|
|
+ // When validating all fields.
|
|
|
try {
|
|
|
field_attach_validate($entity_type, $entity);
|
|
|
}
|
|
|
catch (FieldValidationException $e) {
|
|
|
$errors = $e->errors;
|
|
|
}
|
|
|
- $this->assertEqual($errors[$this->field_name][$langcode][0][0]['error'], 'field_cardinality', t('Cardinality validation failed.'));
|
|
|
-
|
|
|
+ $this->assertEqual($errors[$this->field_name_2][$langcode][0][0]['error'], 'field_cardinality', 'Cardinality validation failed.');
|
|
|
+ // When validating a single field (the second field).
|
|
|
+ try {
|
|
|
+ field_attach_validate($entity_type, $entity, $options);
|
|
|
+ }
|
|
|
+ catch (FieldValidationException $e) {
|
|
|
+ $errors = $e->errors;
|
|
|
+ }
|
|
|
+ $this->assertEqual($errors[$this->field_name_2][$langcode][0][0]['error'], 'field_cardinality', 'Cardinality validation failed.');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -958,34 +1052,59 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
|
|
|
* widgets show up.
|
|
|
*/
|
|
|
function testFieldAttachForm() {
|
|
|
+ $this->createFieldWithInstance('_2');
|
|
|
+
|
|
|
$entity_type = 'test_entity';
|
|
|
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
|
|
|
+ $langcode = LANGUAGE_NONE;
|
|
|
|
|
|
+ // When generating form for all fields.
|
|
|
$form = array();
|
|
|
$form_state = form_state_defaults();
|
|
|
field_attach_form($entity_type, $entity, $form, $form_state);
|
|
|
|
|
|
- $langcode = LANGUAGE_NONE;
|
|
|
- $this->assertEqual($form[$this->field_name][$langcode]['#title'], $this->instance['label'], "Form title is {$this->instance['label']}");
|
|
|
+ $this->assertEqual($form[$this->field_name][$langcode]['#title'], $this->instance['label'], "First field's form title is {$this->instance['label']}");
|
|
|
+ $this->assertEqual($form[$this->field_name_2][$langcode]['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}");
|
|
|
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
|
|
|
// field_test_widget uses 'textfield'
|
|
|
- $this->assertEqual($form[$this->field_name][$langcode][$delta]['value']['#type'], 'textfield', "Form delta $delta widget is textfield");
|
|
|
- }
|
|
|
+ $this->assertEqual($form[$this->field_name][$langcode][$delta]['value']['#type'], 'textfield', "First field's form delta $delta widget is textfield");
|
|
|
+ }
|
|
|
+ for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) {
|
|
|
+ // field_test_widget uses 'textfield'
|
|
|
+ $this->assertEqual($form[$this->field_name_2][$langcode][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield");
|
|
|
+ }
|
|
|
+
|
|
|
+ // When generating form for a single field (the second field).
|
|
|
+ $options = array('field_name' => $this->field_name_2);
|
|
|
+ $form = array();
|
|
|
+ $form_state = form_state_defaults();
|
|
|
+ field_attach_form($entity_type, $entity, $form, $form_state, NULL, $options);
|
|
|
+
|
|
|
+ $this->assertFalse(isset($form[$this->field_name]), 'The first field does not exist in the form');
|
|
|
+ $this->assertEqual($form[$this->field_name_2][$langcode]['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}");
|
|
|
+ for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) {
|
|
|
+ // field_test_widget uses 'textfield'
|
|
|
+ $this->assertEqual($form[$this->field_name_2][$langcode][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Test field_attach_submit().
|
|
|
*/
|
|
|
function testFieldAttachSubmit() {
|
|
|
+ $this->createFieldWithInstance('_2');
|
|
|
+
|
|
|
$entity_type = 'test_entity';
|
|
|
- $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
|
|
|
+ $entity_init = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
|
|
|
+ $langcode = LANGUAGE_NONE;
|
|
|
|
|
|
- // Build the form.
|
|
|
+ // Build the form for all fields.
|
|
|
$form = array();
|
|
|
$form_state = form_state_defaults();
|
|
|
- field_attach_form($entity_type, $entity, $form, $form_state);
|
|
|
+ field_attach_form($entity_type, $entity_init, $form, $form_state);
|
|
|
|
|
|
// Simulate incoming values.
|
|
|
+ // First field.
|
|
|
$values = array();
|
|
|
$weights = array();
|
|
|
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
|
|
@@ -999,22 +1118,59 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
|
|
|
}
|
|
|
// Leave an empty value. 'field_test' fields are empty if empty().
|
|
|
$values[1]['value'] = 0;
|
|
|
-
|
|
|
- $langcode = LANGUAGE_NONE;
|
|
|
+ // Second field.
|
|
|
+ $values_2 = array();
|
|
|
+ $weights_2 = array();
|
|
|
+ for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) {
|
|
|
+ $values_2[$delta]['value'] = mt_rand(1, 127);
|
|
|
+ // Assign random weight.
|
|
|
+ do {
|
|
|
+ $weight = mt_rand(0, $this->field_2['cardinality']);
|
|
|
+ } while (in_array($weight, $weights_2));
|
|
|
+ $weights_2[$delta] = $weight;
|
|
|
+ $values_2[$delta]['_weight'] = $weight;
|
|
|
+ }
|
|
|
+ // Leave an empty value. 'field_test' fields are empty if empty().
|
|
|
+ $values_2[1]['value'] = 0;
|
|
|
// Pretend the form has been built.
|
|
|
drupal_prepare_form('field_test_entity_form', $form, $form_state);
|
|
|
drupal_process_form('field_test_entity_form', $form, $form_state);
|
|
|
$form_state['values'][$this->field_name][$langcode] = $values;
|
|
|
+ $form_state['values'][$this->field_name_2][$langcode] = $values_2;
|
|
|
+
|
|
|
+ // Call field_attach_submit() for all fields.
|
|
|
+ $entity = clone($entity_init);
|
|
|
field_attach_submit($entity_type, $entity, $form, $form_state);
|
|
|
|
|
|
asort($weights);
|
|
|
+ asort($weights_2);
|
|
|
$expected_values = array();
|
|
|
+ $expected_values_2 = array();
|
|
|
foreach ($weights as $key => $value) {
|
|
|
if ($key != 1) {
|
|
|
$expected_values[] = array('value' => $values[$key]['value']);
|
|
|
}
|
|
|
}
|
|
|
$this->assertIdentical($entity->{$this->field_name}[$langcode], $expected_values, 'Submit filters empty values');
|
|
|
+ foreach ($weights_2 as $key => $value) {
|
|
|
+ if ($key != 1) {
|
|
|
+ $expected_values_2[] = array('value' => $values_2[$key]['value']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->assertIdentical($entity->{$this->field_name_2}[$langcode], $expected_values_2, 'Submit filters empty values');
|
|
|
+
|
|
|
+ // Call field_attach_submit() for a single field (the second field).
|
|
|
+ $options = array('field_name' => $this->field_name_2);
|
|
|
+ $entity = clone($entity_init);
|
|
|
+ field_attach_submit($entity_type, $entity, $form, $form_state, $options);
|
|
|
+ $expected_values_2 = array();
|
|
|
+ foreach ($weights_2 as $key => $value) {
|
|
|
+ if ($key != 1) {
|
|
|
+ $expected_values_2[] = array('value' => $values_2[$key]['value']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->assertFalse(isset($entity->{$this->field_name}), 'The first field does not exist in the entity object');
|
|
|
+ $this->assertIdentical($entity->{$this->field_name_2}[$langcode], $expected_values_2, 'Submit filters empty values');
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1144,6 +1300,16 @@ class FieldInfoTestCase extends FieldTestCase {
|
|
|
$this->assertIdentical($instances, $expected, "field_info_instances('user') returns " . var_export($expected, TRUE) . '.');
|
|
|
$instances = field_info_instances('user', 'user');
|
|
|
$this->assertIdentical($instances, array(), "field_info_instances('user', 'user') returns an empty array.");
|
|
|
+
|
|
|
+ // Test that querying for invalid entity types does not add entries in the
|
|
|
+ // list returned by field_info_instances().
|
|
|
+ field_info_cache_clear();
|
|
|
+ field_info_instances('invalid_entity', 'invalid_bundle');
|
|
|
+ // Simulate new request by clearing static caches.
|
|
|
+ drupal_static_reset();
|
|
|
+ field_info_instances('invalid_entity', 'invalid_bundle');
|
|
|
+ $instances = field_info_instances();
|
|
|
+ $this->assertFalse(isset($instances['invalid_entity']), 'field_info_instances() does not contain entries for the invalid entity type that was queried before');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1253,6 +1419,80 @@ class FieldInfoTestCase extends FieldTestCase {
|
|
|
$this->assertNull(field_info_instance('comment', 'field', 'comment_node_article'), t('No instances are returned on disabled entity types.'));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test field_info_field_map().
|
|
|
+ */
|
|
|
+ function testFieldMap() {
|
|
|
+ // We will overlook fields created by the 'standard' install profile.
|
|
|
+ $exclude = field_info_field_map();
|
|
|
+
|
|
|
+ // Create a new bundle for 'test_entity' entity type.
|
|
|
+ field_test_create_bundle('test_bundle_2');
|
|
|
+
|
|
|
+ // Create a couple fields.
|
|
|
+ $fields = array(
|
|
|
+ array(
|
|
|
+ 'field_name' => 'field_1',
|
|
|
+ 'type' => 'test_field',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'field_name' => 'field_2',
|
|
|
+ 'type' => 'hidden_test_field',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ foreach ($fields as $field) {
|
|
|
+ field_create_field($field);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Create a couple instances.
|
|
|
+ $instances = array(
|
|
|
+ array(
|
|
|
+ 'field_name' => 'field_1',
|
|
|
+ 'entity_type' => 'test_entity',
|
|
|
+ 'bundle' => 'test_bundle',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'field_name' => 'field_1',
|
|
|
+ 'entity_type' => 'test_entity',
|
|
|
+ 'bundle' => 'test_bundle_2',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'field_name' => 'field_2',
|
|
|
+ 'entity_type' => 'test_entity',
|
|
|
+ 'bundle' => 'test_bundle',
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'field_name' => 'field_2',
|
|
|
+ 'entity_type' => 'test_cacheable_entity',
|
|
|
+ 'bundle' => 'test_bundle',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ foreach ($instances as $instance) {
|
|
|
+ field_create_instance($instance);
|
|
|
+ }
|
|
|
+
|
|
|
+ $expected = array(
|
|
|
+ 'field_1' => array(
|
|
|
+ 'type' => 'test_field',
|
|
|
+ 'bundles' => array(
|
|
|
+ 'test_entity' => array('test_bundle', 'test_bundle_2'),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'field_2' => array(
|
|
|
+ 'type' => 'hidden_test_field',
|
|
|
+ 'bundles' => array(
|
|
|
+ 'test_entity' => array('test_bundle'),
|
|
|
+ 'test_cacheable_entity' => array('test_bundle'),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ // Check that the field map is correct.
|
|
|
+ $map = field_info_field_map();
|
|
|
+ $map = array_diff_key($map, $exclude);
|
|
|
+ $this->assertEqual($map, $expected);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Test that the field_info settings convenience functions work.
|
|
|
*/
|
|
@@ -1277,6 +1517,31 @@ class FieldInfoTestCase extends FieldTestCase {
|
|
|
$this->assertIdentical(field_info_formatter_settings($type), $data['settings'], "field_info_formatter_settings returns {$type}'s formatter settings");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Tests that the field info cache can be built correctly.
|
|
|
+ */
|
|
|
+ function testFieldInfoCache() {
|
|
|
+ // Create a test field and ensure it's in the array returned by
|
|
|
+ // field_info_fields().
|
|
|
+ $field_name = drupal_strtolower($this->randomName());
|
|
|
+ $field = array(
|
|
|
+ 'field_name' => $field_name,
|
|
|
+ 'type' => 'test_field',
|
|
|
+ );
|
|
|
+ field_create_field($field);
|
|
|
+ $fields = field_info_fields();
|
|
|
+ $this->assertTrue(isset($fields[$field_name]), 'The test field is initially found in the array returned by field_info_fields().');
|
|
|
+
|
|
|
+ // Now rebuild the field info cache, and set a variable which will cause
|
|
|
+ // the cache to be cleared while it's being rebuilt; see
|
|
|
+ // field_test_entity_info(). Ensure the test field is still in the returned
|
|
|
+ // array.
|
|
|
+ field_info_cache_clear();
|
|
|
+ variable_set('field_test_clear_info_cache_in_hook_entity_info', TRUE);
|
|
|
+ $fields = field_info_fields();
|
|
|
+ $this->assertTrue(isset($fields[$field_name]), 'The test field is found in the array returned by field_info_fields() even if its cache is cleared while being rebuilt.');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class FieldFormTestCase extends FieldTestCase {
|
|
@@ -2178,6 +2443,41 @@ class FieldCrudTestCase extends FieldTestCase {
|
|
|
$this->assertTrue($field_definition < $field, t('The field was properly read.'));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Tests reading field definitions.
|
|
|
+ */
|
|
|
+ function testReadFields() {
|
|
|
+ $field_definition = array(
|
|
|
+ 'field_name' => 'field_1',
|
|
|
+ 'type' => 'test_field',
|
|
|
+ );
|
|
|
+ field_create_field($field_definition);
|
|
|
+
|
|
|
+ // Check that 'single column' criteria works.
|
|
|
+ $fields = field_read_fields(array('field_name' => $field_definition['field_name']));
|
|
|
+ $this->assertTrue(count($fields) == 1 && isset($fields[$field_definition['field_name']]), 'The field was properly read.');
|
|
|
+
|
|
|
+ // Check that 'multi column' criteria works.
|
|
|
+ $fields = field_read_fields(array('field_name' => $field_definition['field_name'], 'type' => $field_definition['type']));
|
|
|
+ $this->assertTrue(count($fields) == 1 && isset($fields[$field_definition['field_name']]), 'The field was properly read.');
|
|
|
+ $fields = field_read_fields(array('field_name' => $field_definition['field_name'], 'type' => 'foo'));
|
|
|
+ $this->assertTrue(empty($fields), 'No field was found.');
|
|
|
+
|
|
|
+ // Create an instance of the field.
|
|
|
+ $instance_definition = array(
|
|
|
+ 'field_name' => $field_definition['field_name'],
|
|
|
+ 'entity_type' => 'test_entity',
|
|
|
+ 'bundle' => 'test_bundle',
|
|
|
+ );
|
|
|
+ field_create_instance($instance_definition);
|
|
|
+
|
|
|
+ // Check that criteria spanning over the field_config_instance table work.
|
|
|
+ $fields = field_read_fields(array('entity_type' => $instance_definition['entity_type'], 'bundle' => $instance_definition['bundle']));
|
|
|
+ $this->assertTrue(count($fields) == 1 && isset($fields[$field_definition['field_name']]), 'The field was properly read.');
|
|
|
+ $fields = field_read_fields(array('entity_type' => $instance_definition['entity_type'], 'field_name' => $instance_definition['field_name']));
|
|
|
+ $this->assertTrue(count($fields) == 1 && isset($fields[$field_definition['field_name']]), 'The field was properly read.');
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Test creation of indexes on data column.
|
|
|
*/
|