You are here

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

Same name and namespace in other branches
  1. 8.3 tests/src/FunctionalJavascript/FormatterTest.php \Drupal\Tests\double_field\FunctionalJavascript\FormatterTest::testListFormatter()

Test callback.

File

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

Class

FormatterTest
A tests for Double Field formatter.

Namespace

Drupal\Tests\double_field\FunctionalJavascript

Code

public function testListFormatter() : void {
  $page = $this
    ->getSession()
    ->getPage();
  $settings = [];
  $settings['storage']['cardinality'] = 3;
  $settings['storage']['first']['type'] = 'string';
  $settings['storage']['second']['type'] = 'string';
  $settings['formatter']['type'] = 'double_field_html_list';
  $this
    ->createField($settings);
  $this
    ->submitNode([
    'Foo 1',
    'Foo 2',
  ], [
    'Bar 1',
    'Bar 2',
  ], [
    'Qux 1',
    'Qux 2',
  ]);
  $this
    ->drupalGet('node/1');
  $prefix = '//div[contains(@class, "field--type-double-field")]';
  $prefix .= '//div[@class = "item-list"]';
  $prefix .= '//ul[@class = "double-field-list"]';
  $item_xpath = $prefix . '/li[@class = "container-inline"][1]';
  $item_xpath .= '/div[@class = "double-field-first" and text() = "Foo 1"][1]';
  $item_xpath .= '/following-sibling::div[@class = "double-field-second" and text() = "Foo 2"]';
  $this
    ->assertXpath($item_xpath);
  $item_xpath = $prefix . '/li[@class = "container-inline"][2]';
  $item_xpath .= '/div[@class = "double-field-first" and text() = "Bar 1"][1]';
  $item_xpath .= '/following-sibling::div[@class = "double-field-second" and text() = "Bar 2"]';
  $this
    ->assertXpath($item_xpath);
  $item_xpath = $prefix . '/li[@class = "container-inline"][3]';
  $item_xpath .= '/div[@class = "double-field-first" and text() = "Qux 1"][1]';
  $item_xpath .= '/following-sibling::div[@class = "double-field-second" and text() = "Qux 2"]';
  $this
    ->assertXpath($item_xpath);
  $this
    ->drupalGet($this->displayAdminPath);
  $expected_summary = [
    'List type: ul',
    'Display as inline element',
    '<b>First subfield - text</b>',
    'Hidden: no',
    '<b>Second subfield - text</b>',
    'Hidden: no',
  ];
  $this
    ->assertSettingsSummary($expected_summary);
  $this
    ->openSettingsForm();
  $page
    ->selectFieldOption($this->fieldPrefix . '[list_type]', 'ol');
  $this
    ->submitSettingsForm();
  $expected_summary = [
    'List type: ol',
    'Display as inline element',
    '<b>First subfield - text</b>',
    'Hidden: no',
    '<b>Second subfield - text</b>',
    'Hidden: no',
  ];
  $this
    ->assertSettingsSummary($expected_summary);
  $this
    ->drupalGet('node/1');
  $prefix = '//div[contains(@class, "field--type-double-field")]';
  $prefix .= '//div[@class = "item-list"]';
  $prefix .= '//ol[@class = "double-field-list"]';
  $item_xpath = $prefix . '/li[@class = "container-inline"][1]';
  $item_xpath .= '/div[@class = "double-field-first" and text() = "Foo 1"]';
  $item_xpath .= '/following-sibling::div[@class = "double-field-second" and text() = "Foo 2"]';
  $this
    ->assertXpath($item_xpath);
  $item_xpath = $prefix . '/li[@class = "container-inline"][2]';
  $item_xpath .= '/div[@class = "double-field-first" and text() = "Bar 1"]';
  $item_xpath .= '/following-sibling::div[@class = "double-field-second" and text() = "Bar 2"]';
  $this
    ->assertXpath($item_xpath);
  $item_xpath = $prefix . '/li[@class = "container-inline"][3]';
  $item_xpath .= '/div[@class = "double-field-first" and text() = "Qux 1"]';
  $item_xpath .= '/following-sibling::div[@class = "double-field-second" and text() = "Qux 2"]';
  $this
    ->assertXpath($item_xpath);
  $this
    ->drupalGet($this->displayAdminPath);
  $this
    ->openSettingsForm();
  $inline_input = $page
    ->find('xpath', '//input[@name = "fields[' . $this->fieldName . '][settings_edit_form][settings][inline]"]');
  $this
    ->assertTrue($inline_input
    ->isVisible());
  $page
    ->selectFieldOption($this->fieldPrefix . '[list_type]', 'dl');
  $this
    ->assertFalse($inline_input
    ->isVisible());
  $this
    ->submitSettingsForm();
  $expected_summary = [
    'List type: dl',
    '<b>First subfield - text</b>',
    'Hidden: no',
    '<b>Second subfield - text</b>',
    'Hidden: no',
  ];
  $this
    ->assertSettingsSummary($expected_summary);
  $this
    ->drupalGet('node/1');
  $prefix = '//div[contains(@class, "field--type-double-field")]';
  $prefix .= '//dl[@class = "double-field-definition-list"]';
  $item_xpath = $prefix . '/dt[text() = "Foo 1"]/following-sibling::dd[text() = "Foo 2"]';
  $this
    ->assertXpath($item_xpath);
  $item_xpath = $prefix . '/dt[text() = "Bar 1"]/following-sibling::dd[text() = "Bar 2"]';
  $this
    ->assertXpath($item_xpath);
  $item_xpath = $prefix . '/dt[text() = "Qux 1"]/following-sibling::dd[text() = "Qux 2"]';
  $this
    ->assertXpath($item_xpath);
}