function OptionsFieldTest::testGenerateSampleItemsWithNoAllowedValues

Same name in other branches
  1. 10 core/modules/options/tests/src/Kernel/OptionsFieldTest.php \Drupal\Tests\options\Kernel\OptionsFieldTest::testGenerateSampleItemsWithNoAllowedValues()
  2. 11.x core/modules/options/tests/src/Kernel/OptionsFieldTest.php \Drupal\Tests\options\Kernel\OptionsFieldTest::testGenerateSampleItemsWithNoAllowedValues()

Tests that ::generateSampleItems does not fail with empty allowed values.

File

core/modules/options/tests/src/Kernel/OptionsFieldTest.php, line 104

Class

OptionsFieldTest
Tests for the 'Options' field types.

Namespace

Drupal\Tests\options\Kernel

Code

public function testGenerateSampleItemsWithNoAllowedValues() {
    $this->fieldStorage
        ->setSetting('allowed_values', [])
        ->save();
    $entity = EntityTest::create();
    $value = $entity->{$this->fieldName}
        ->generateSampleItems();
    $this->assertNull($value);
}

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