You are here

public function OptionsSelectDynamicValuesTest::testSelectListDynamic in Drupal 8

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

Tests the 'options_select' widget (single select).

File

core/modules/options/tests/src/Functional/OptionsSelectDynamicValuesTest.php, line 20

Class

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

Namespace

Drupal\Tests\options\Functional

Code

public function testSelectListDynamic() {

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

  // Create a web user.
  $web_user = $this
    ->drupalCreateUser([
    '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 = $option
      ->getValue();
    if ($value != '_none') {
      $this
        ->assertContains($value, $this->test);
    }
  }
}