Mercurial > hg > isophonics-drupal-site
annotate core/modules/options/tests/src/Functional/OptionsDynamicValuesValidationTest.php @ 15:e200cb7efeb3
Update Drupal core to 8.5.3 via Composer
author | Chris Cannam |
---|---|
date | Thu, 26 Apr 2018 11:26:54 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Tests\options\Functional; |
Chris@0 | 4 |
Chris@0 | 5 /** |
Chris@0 | 6 * Tests the Options field allowed values function. |
Chris@0 | 7 * |
Chris@0 | 8 * @group options |
Chris@0 | 9 */ |
Chris@0 | 10 class OptionsDynamicValuesValidationTest extends OptionsDynamicValuesTestBase { |
Chris@0 | 11 /** |
Chris@0 | 12 * Test that allowed values function gets the entity. |
Chris@0 | 13 */ |
Chris@0 | 14 public function testDynamicAllowedValues() { |
Chris@0 | 15 // Verify that validation passes against every value we had. |
Chris@0 | 16 foreach ($this->test as $key => $value) { |
Chris@0 | 17 $this->entity->test_options->value = $value; |
Chris@0 | 18 $violations = $this->entity->test_options->validate(); |
Chris@0 | 19 $this->assertEqual(count($violations), 0, "$key is a valid value"); |
Chris@0 | 20 } |
Chris@0 | 21 |
Chris@0 | 22 // Now verify that validation does not pass against anything else. |
Chris@0 | 23 foreach ($this->test as $key => $value) { |
Chris@0 | 24 $this->entity->test_options->value = is_numeric($value) ? (100 - $value) : ('X' . $value); |
Chris@0 | 25 $violations = $this->entity->test_options->validate(); |
Chris@0 | 26 $this->assertEqual(count($violations), 1, "$key is not a valid value"); |
Chris@0 | 27 } |
Chris@0 | 28 } |
Chris@0 | 29 |
Chris@0 | 30 } |