You are here

public function NameOptionsProviderTest::testTitleOptionsFromField in Name Field 8

Tests the field options.

File

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

Class

NameOptionsProviderTest
Tests NameOptionsProvider class.

Namespace

Drupal\Tests\name\Functional

Code

public function testTitleOptionsFromField() {
  $field = $this
    ->createNameField('field_name_test', 'entity_test', 'entity_test');
  $settings = $field
    ->getSettings();
  $settings['title_options'] = [
    '-- --',
    'b',
    'a',
    'c',
  ];
  $field
    ->getConfig('entity_test')
    ->setSettings($settings)
    ->save();
  $expected = [
    '' => '--',
    'b' => 'b',
    'a' => 'a',
    'c' => 'c',
  ];
  $this
    ->assertEquals($expected, $this->optionsProvider
    ->getOptions($field, 'title'));

  // Enable sorting.
  $settings['sort_options']['title'] = TRUE;
  $field
    ->getConfig('entity_test')
    ->setSettings($settings)
    ->save();
  $expected = [
    '' => '--',
    'a' => 'a',
    'b' => 'b',
    'c' => 'c',
  ];
  $this
    ->assertEquals($expected, $this->optionsProvider
    ->getOptions($field, 'title'));
}