function OptionsDynamicValuesTest::setUp

Set the default field storage backend for fields created during tests.

Overrides FieldTestBase::setUp

File

drupal/core/modules/field/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php, line 24
Definition of Drupal\options\Tests\OptionsDynamicValuesTest.

Class

OptionsDynamicValuesTest
Sets up a Options field for testing allowed values functions.

Namespace

Drupal\options\Tests

Code

function setUp() {
  parent::setUp();
  $this->field_name = 'test_options';
  $this->field = array(
    'field_name' => $this->field_name,
    'type' => 'list_text',
    'cardinality' => 1,
    'settings' => array(
      'allowed_values_function' => 'options_test_dynamic_values_callback',
    ),
  );
  $this->field = field_create_field($this->field);
  $this->instance = array(
    'field_name' => $this->field_name,
    'entity_type' => 'test_entity',
    'bundle' => 'test_bundle',
    'required' => TRUE,
    'widget' => array(
      'type' => 'options_select',
    ),
  );
  $this->instance = field_create_instance($this->instance);
  $this->test = array(
    'id' => mt_rand(1, 10),
    // Make sure this does not equal the ID so that
    // options_test_dynamic_values_callback() always returns 4 values.
    'vid' => mt_rand(20, 30),
    'bundle' => 'test_bundle',
    'label' => $this
      ->randomName(),
  );
  $this->entity = call_user_func_array('field_test_create_entity', $this->test);
}