You are here

function OptionsSelectDynamicValuesTest::testSelectListDynamic in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/options/src/Tests/OptionsSelectDynamicValuesTest.php \Drupal\options\Tests\OptionsSelectDynamicValuesTest::testSelectListDynamic()

Tests the 'options_select' widget (single select).

File

core/modules/options/src/Tests/OptionsSelectDynamicValuesTest.php, line 19
Contains \Drupal\options\Tests\OptionsSelectDynamicValuesTest.

Class

OptionsSelectDynamicValuesTest
Tests an options select with a dynamic allowed values function.

Namespace

Drupal\options\Tests

Code

function testSelectListDynamic() {

  // Create an entity.
  $this->entity
    ->save();

  // Create a web user.
  $web_user = $this
    ->drupalCreateUser(array(
    'view test entity',
    'administer entity_test content',
  ));
  $this
    ->drupalLogin($web_user);

  // Display form.
  $this
    ->drupalGet('entity_test_rev/manage/' . $this->entity
    ->id() . '/edit');
  $options = $this
    ->xpath('//select[@id="edit-test-options"]/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));
    }
  }
}