7ef535c96c165ea13e03290f5dda80583bd21d53
[yaffs-website] / web / core / modules / options / tests / src / Functional / OptionsDynamicValuesValidationTest.php
1 <?php
2
3 namespace Drupal\Tests\options\Functional;
4
5 /**
6  * Tests the Options field allowed values function.
7  *
8  * @group options
9  */
10 class OptionsDynamicValuesValidationTest extends OptionsDynamicValuesTestBase {
11
12   /**
13    * Test that allowed values function gets the entity.
14    */
15   public function testDynamicAllowedValues() {
16     // Verify that validation passes against every value we had.
17     foreach ($this->test as $key => $value) {
18       $this->entity->test_options->value = $value;
19       $violations = $this->entity->test_options->validate();
20       $this->assertEqual(count($violations), 0, "$key is a valid value");
21     }
22
23     // Now verify that validation does not pass against anything else.
24     foreach ($this->test as $key => $value) {
25       $this->entity->test_options->value = is_numeric($value) ? (100 - $value) : ('X' . $value);
26       $violations = $this->entity->test_options->validate();
27       $this->assertEqual(count($violations), 1, "$key is not a valid value");
28     }
29   }
30
31 }