1 options.test OptionsSelectDynamicValuesTestCase::testSelectListDynamic()

Tests the 'options_select' widget (single select).

File

core/modules/field/modules/options/tests/options.test, line 558
Tests for options.module.

Class

OptionsSelectDynamicValuesTestCase
Test an options select on a list field with a dynamic allowed values function.

Code

function testSelectListDynamic() {
  // Create an entity.
  $this->entity->is_new = TRUE;
  field_test_entity_save($this->entity);
  // Create a web user.
  $web_user = $this->backdropCreateUser(array('access field_test content', 'administer field_test content'));
  $this->backdropLogin($web_user);

  // Set the values that are checked by list_test_dynamic_values_callback().
  $expected_values = array(
    'foo' => $this->randomName(),
    'bar' => $this->randomName(),
    'baz' => $this->randomName(),
  );
  state_set('list_test_dynamic_values', $expected_values);

  // Display form.
  $this->backdropGet('test-entity/manage/' . $this->entity->ftid . '/edit');
  $options = $this->xpath('//select[@id="edit-test-list-und"]/option');
  $this->assertEqual(count($options), count($expected_values) + 1, 'Expected number of items found in dynamic select list.');
  foreach ($options as $option) {
    $key = (string) $option['value'];
    $value = (string) $option;
    if ($key !== '_none') {
      $this->assertTrue($expected_values[$key] === $value);
    }
  }
}