You are here

public function NameOptionsProviderTest::testTitleOptionsFromTaxonomy in Name Field 8

Tests the taxonomy options source.

File

tests/src/Functional/NameOptionsProviderTest.php, line 92

Class

NameOptionsProviderTest
Tests NameOptionsProvider class.

Namespace

Drupal\Tests\name\Functional

Code

public function testTitleOptionsFromTaxonomy() {
  $field = $this
    ->createNameField('field_name_test', 'entity_test', 'entity_test');
  $vocabulary = Vocabulary::create([
    'vid' => 'title_options',
    'name' => 'Title options',
  ]);
  $vocabulary
    ->save();
  foreach ([
    'foo',
    'bar',
    'baz',
  ] as $name) {
    $term = Term::create([
      'name' => $name,
      'vid' => $vocabulary
        ->id(),
    ]);
    $term
      ->save();
  }
  $settings = $field
    ->getSettings();
  $settings['title_options'] = [
    '-- --',
    '[vocabulary:title_options]',
  ];
  $settings['sort_options']['title'] = TRUE;
  $field
    ->getConfig('entity_test')
    ->setSettings($settings)
    ->save();
  $expected = [
    '' => '--',
    'bar' => 'bar',
    'baz' => 'baz',
    'foo' => 'foo',
  ];
  $this
    ->assertEquals($expected, $this->optionsProvider
    ->getOptions($field, 'title'));
}