function OptionsSelectDynamicValuesTestCase::testSelectListDynamic

7.x options.test OptionsSelectDynamicValuesTestCase::testSelectListDynamic()

Tests the 'options_select' widget (single select).

File

drupal-7.x/modules/field/modules/options/options.test, line 534
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->drupalCreateUser(array('access field_test content', 'administer field_test content'));
  $this->drupalLogin($web_user);

  // Display form.
  $this->drupalGet('test-entity/manage/' . $this->entity->ftid . '/edit');
  $options = $this->xpath('//select[@id="edit-test-list-und"]/option');
  $this->assertEqual(count($options), count($this->test) + 1);
  foreach ($options as $option) {
    $value = (string) $option['value'];
    if ($value != '_none') {
      $this->assertTrue(array_search($value, $this->test));
    }
  }
}