.../Drupal/field/Tests/FieldAttachOtherTest.php | 8 +-- .../lib/Drupal/field/Tests/FieldAttachTestBase.php | 61 +++++++++----------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index 0557362..0d04e8f 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -25,7 +25,7 @@ public static function getInfo() { * Test field_attach_view() and field_attach_prepare_view(). */ function testFieldAttachView() { - $this->setUpSecondField(); + $this->createFieldInstance(' 2', '_2'); $entity_type = 'test_entity'; $entity_init = field_test_create_entity(); @@ -328,7 +328,7 @@ function testFieldAttachCache() { * hook_field_validate. */ function testFieldAttachValidate() { - $this->setUpSecondField(); + $this->createFieldInstance(' 2', '_2'); $entity_type = 'test_entity'; $entity = field_test_create_entity(0, 0, $this->instance['bundle']); @@ -420,7 +420,7 @@ function testFieldAttachValidate() { * widgets show up. */ function testFieldAttachForm() { - $this->setUpSecondField(); + $this->createFieldInstance(' 2', '_2'); $entity_type = 'test_entity'; $entity = field_test_create_entity(0, 0, $this->instance['bundle']); @@ -460,7 +460,7 @@ function testFieldAttachForm() { * Test field_attach_submit(). */ function testFieldAttachSubmit() { - $this->setUpSecondField(); + $this->createFieldInstance(' 2', '_2'); $entity_type = 'test_entity'; $entity_init = field_test_create_entity(0, 0, $this->instance['bundle']); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachTestBase.php index 37b30f2..e25f721 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachTestBase.php @@ -19,54 +19,47 @@ function setUp() { parent::setUp(); - $this->field_name = drupal_strtolower($this->randomName() . '_field_name_1'); - $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_1', - 'description' => $this->randomName() . '_description', - 'weight' => mt_rand(0, 127), - 'settings' => array( - 'test_instance_setting' => $this->randomName(), - ), - 'widget' => array( - 'type' => 'test_field_widget', - 'label' => 'Test Field', - 'settings' => array( - 'test_widget_setting' => $this->randomName(), - ) - ) - ); - field_create_instance($this->instance); + $this->createFieldInstance(' 1'); } - function setUpSecondField() { - $this->field_name_2 = drupal_strtolower($this->randomName() . '_field_name_2'); - $this->field_2 = array('field_name' => $this->field_name_2, 'type' => 'test_field', 'cardinality' => 4); - $this->field_2 = field_create_field($this->field_2); - $this->field_id_2 = $this->field_2['id']; - $this->instance_2 = array( - 'field_name' => $this->field_name_2, + /** + * Create a field instance. + * + * @param string $label_suffix + * A suffix that will be used to uniquely identify this field instance in + * all user-visible string references to it. + * @param string $suffix + * (optional) A string that should only contain characters that are valid in + * PHP variable names as well. The details for this field + */ + function createFieldInstance($label_suffix, $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_2', - 'description' => $this->randomName() . '_description_2', + 'label' => $this->randomName() . '_label' . $label_suffix, + 'description' => $this->randomName() . '_description' . $label_suffix, 'weight' => mt_rand(0, 127), 'settings' => array( 'test_instance_setting' => $this->randomName(), ), 'widget' => array( 'type' => 'test_field_widget', - 'label' => 'Test Field 2', + 'label' => 'Test Field' . $label_suffix, 'settings' => array( 'test_widget_setting' => $this->randomName(), ) ) ); - field_create_instance($this->instance_2); + field_create_instance($this->$instance); } }