function OptionsDynamicValuesApiTest::testOptionsAllowedValues

Same name in other branches
  1. 9 core/modules/options/tests/src/Functional/OptionsDynamicValuesApiTest.php \Drupal\Tests\options\Functional\OptionsDynamicValuesApiTest::testOptionsAllowedValues()
  2. 8.9.x core/modules/options/tests/src/Functional/OptionsDynamicValuesApiTest.php \Drupal\Tests\options\Functional\OptionsDynamicValuesApiTest::testOptionsAllowedValues()
  3. 10 core/modules/options/tests/src/Kernel/OptionsDynamicValuesApiTest.php \Drupal\Tests\options\Kernel\OptionsDynamicValuesApiTest::testOptionsAllowedValues()

Tests options_allowed_values().

See also

options_test_dynamic_values_callback()

File

core/modules/options/tests/src/Kernel/OptionsDynamicValuesApiTest.php, line 82

Class

OptionsDynamicValuesApiTest
Tests the options allowed values api.

Namespace

Drupal\Tests\options\Kernel

Code

public function testOptionsAllowedValues() : void {
    // Test allowed values without passed $items.
    $values = options_allowed_values($this->fieldStorage);
    $this->assertEquals([], $values);
    $values = options_allowed_values($this->fieldStorage, $this->entity);
    $expected_values = [
        $this->entity
            ->label(),
        $this->entity
            ->toUrl()
            ->toString(),
        $this->entity
            ->uuid(),
        $this->entity
            ->bundle(),
    ];
    $expected_values = array_combine($expected_values, $expected_values);
    $this->assertEquals($expected_values, $values);
}

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