function ListDynamicValuesValidationTestCase::testDynamicAllowedValues

Test that allowed values function gets the entity.

File

modules/field/modules/list/tests/list.test, line 181

Class

ListDynamicValuesValidationTestCase
Tests the List field allowed values function.

Code

function testDynamicAllowedValues() {
    // Verify that the test passes against every value we had.
    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');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.