You are here

function OptionsDynamicValuesValidationTest::testDynamicAllowedValues in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/options/src/Tests/OptionsDynamicValuesValidationTest.php \Drupal\options\Tests\OptionsDynamicValuesValidationTest::testDynamicAllowedValues()

Test that allowed values function gets the entity.

File

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

Class

OptionsDynamicValuesValidationTest
Tests the Options field allowed values function.

Namespace

Drupal\options\Tests

Code

function testDynamicAllowedValues() {

  // Verify that validation passes against every value we had.
  foreach ($this->test as $key => $value) {
    $this->entity->test_options->value = $value;
    $violations = $this->entity->test_options
      ->validate();
    $this
      ->assertEqual(count($violations), 0, "{$key} is a valid value");
  }

  // Now verify that validation does not pass against anything else.
  foreach ($this->test as $key => $value) {
    $this->entity->test_options->value = is_numeric($value) ? 100 - $value : 'X' . $value;
    $violations = $this->entity->test_options
      ->validate();
    $this
      ->assertEqual(count($violations), 1, "{$key} is not a valid value");
  }
}