1 list.test | ListDynamicValuesValidationTestCase::testDynamicAllowedValues() |
Test that allowed values function gets the entity.
File
- core/
modules/ field/ modules/ list/ tests/ list.test, line 196 - Tests for list.module.
Class
- ListDynamicValuesValidationTestCase
- Tests the List field allowed values function.
Code
function testDynamicAllowedValues() {
// Verify that the test passes against every value we had.
state_set('list_test_dynamic_values', backdrop_map_assoc($this->test));
foreach ($this->test as $key => $value) {
$this->entity->test_list[LANGUAGE_NONE][0]['value'] = $value;
try {
field_attach_validate('test_entity', $this->entity);
$this->pass("$key should pass");
}
catch (FieldValidationException $e) {
// This will display as an exception, no need for a separate error.
throw ($e);
}
}
// Now verify that the test does not pass against anything else.
foreach ($this->test as $key => $value) {
$this->entity->test_list[LANGUAGE_NONE][0]['value'] = is_numeric($value) ? (100 - $value) : ('X' . $value);
$pass = FALSE;
try {
field_attach_validate('test_entity', $this->entity);
}
catch (FieldValidationException $e) {
$pass = TRUE;
}
$this->assertTrue($pass, $key . ' should not pass');
}
}