You are here

public function FormatterTest::testAllowedValues in Double Field 4.x

Test callback.

File

tests/src/FunctionalJavascript/FormatterTest.php, line 621

Class

FormatterTest
A tests for Double Field formatter.

Namespace

Drupal\Tests\double_field\FunctionalJavascript

Code

public function testAllowedValues() : void {
  $page = $this
    ->getSession()
    ->getPage();
  $settings = [];
  $settings['storage']['first']['type'] = 'string';
  $settings['storage']['second']['type'] = 'email';
  $settings['first']['list'] = TRUE;
  $settings['first']['allowed_values'] = [
    'alpha' => '-= Alpha =-',
    'beta' => '-= Beta =-',
    'gamma' => '-= Gamma =-',
  ];
  $settings['second']['list'] = TRUE;
  $settings['second']['allowed_values'] = [
    'developer@example.com' => '-= Developer =-',
    'manager@example.com' => '-= Manager =-',
    'ceo@example.com' => '-= CEO =-',
  ];
  $settings['formatter']['type'] = 'double_field_unformatted_list';
  $this
    ->createField($settings);
  $this
    ->submitNode([
    'gamma',
    'ceo@example.com',
  ]);
  $this
    ->drupalGet('node/1');
  $xpath = <<<'XPATH'
      //div[contains(@class, "field--type-double-field")]
      /div[@class = "double-field-first" and text() = "-= Gamma =-"]
      /following-sibling::div[@class = "double-field-second" and text() = "-= CEO =-"]
XPATH;
  $this
    ->assertXpath($xpath);
  $this
    ->drupalGet($this->displayAdminPath);
  $expected_summary = [
    'Display as inline element',
    '<b>First subfield - text (list)</b>',
    'Hidden: no',
    'Display key: no',
    '<b>Second subfield - email (list)</b>',
    'Link: no',
    'Hidden: no',
    'Display key: no',
  ];
  $this
    ->assertSettingsSummary($expected_summary);
  $this
    ->openSettingsForm();
  $details_1 = $page
    ->find('xpath', '//details[1]');
  $details_1
    ->click();
  $page
    ->checkField(sprintf('fields[%s][settings_edit_form][settings][first][key]', $this->fieldName));
  $details_2 = $page
    ->find('xpath', '//details[2]');
  $details_2
    ->click();
  $page
    ->checkField(sprintf('fields[%s][settings_edit_form][settings][second][key]', $this->fieldName));
  $this
    ->submitSettingsForm();
  $expected_summary = [
    'Display as inline element',
    '<b>First subfield - text (list)</b>',
    'Hidden: no',
    'Display key: yes',
    '<b>Second subfield - email (list)</b>',
    'Link: no',
    'Hidden: no',
    'Display key: yes',
  ];
  $this
    ->assertSettingsSummary($expected_summary);
  $this
    ->drupalGet('node/1');
  $xpath = <<<'XPATH'
      //div[contains(@class, "field--type-double-field")]
      /div[@class = "double-field-first" and text() = "gamma"]
      /following-sibling::div[@class = "double-field-second" and text() = "ceo@example.com"]
XPATH;
  $this
    ->assertXpath($xpath);
}