You are here

public function FormatterTest::testDateAndUri 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::testDateAndUri()

Test callback.

File

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

Class

FormatterTest
A tests for Double Field formatter.

Namespace

Drupal\Tests\double_field\FunctionalJavascript

Code

public function testDateAndUri() : void {
  $page = $this
    ->getSession()
    ->getPage();
  $settings = [];
  $settings['storage']['first']['type'] = 'datetime_iso8601';
  $settings['storage']['second']['type'] = 'uri';
  $settings['formatter']['type'] = 'double_field_unformatted_list';
  $this
    ->createField($settings);
  $this
    ->drupalGet($this->displayAdminPath);
  $expected_summary = [
    'Display as inline element',
    '<b>First subfield - date</b>',
    'Date format: medium',
    'Hidden: no',
    '<b>Second subfield - url</b>',
    'Link: no',
    'Hidden: no',
  ];
  $this
    ->assertSettingsSummary($expected_summary);

  // Make sure the values are not rendered as links.
  $this
    ->drupalGet($this->nodeAddPath);
  $page
    ->fillField('title[0][value]', 'Example');
  $page
    ->fillField($this->fieldName . '[0][first][date]', '12/11/2019');
  $page
    ->fillField($this->fieldName . '[0][first][time]', '034700PM');
  $page
    ->fillField($this->fieldName . '[0][second]', 'https://example.com');
  $page
    ->pressButton('Save');
  $prefix = '//div[contains(@class, "double-field-unformatted-list")]';
  $this
    ->assertXpath($prefix . '/div[@class = "double-field-first"]/time[@datetime = "2019-12-11T15:47:00Z" and text() = "Wed, 12/11/2019 - 15:47"]');
  $this
    ->assertXpath($prefix . '/div[@class = "double-field-second" and text() = "https://example.com"]');
  $this
    ->drupalGet($this->displayAdminPath);
  $this
    ->openSettingsForm();
  $page = $this
    ->getSession()
    ->getPage();
  $details_1 = $page
    ->find('xpath', '//details[1]');
  $details_1
    ->click();
  $details_1
    ->selectFieldOption('Date format', 'short');
  $details_2 = $page
    ->find('xpath', '//details[2]');
  $details_2
    ->click();
  $details_2
    ->checkField('Display as link');
  $this
    ->submitSettingsForm();
  $expected_summary = [
    'Display as inline element',
    '<b>First subfield - date</b>',
    'Date format: short',
    'Hidden: no',
    '<b>Second subfield - url</b>',
    'Link: yes',
    'Hidden: no',
  ];
  $this
    ->assertSettingsSummary($expected_summary);
  $this
    ->drupalGet('node/1');
  $prefix = '//div[contains(@class, "double-field-unformatted-list")]';
  $this
    ->assertXpath($prefix . '/div[@class = "double-field-first"]/time[@datetime = "2019-12-11T15:47:00Z" and text() = "12/11/2019 - 15:47"]');
  $this
    ->assertXpath($prefix . '/div[@class = "double-field-second"]/a[@href = "https://example.com" and text() = "https://example.com"]');
}