public function FormatterTest::testTableFormatter in Double Field 4.x
Same name and namespace in other branches
- 8.3 tests/src/FunctionalJavascript/FormatterTest.php \Drupal\Tests\double_field\FunctionalJavascript\FormatterTest::testTableFormatter()
Test callback.
File
- tests/
src/ FunctionalJavascript/ FormatterTest.php, line 553
Class
- FormatterTest
- A tests for Double Field formatter.
Namespace
Drupal\Tests\double_field\FunctionalJavascriptCode
public function testTableFormatter() : 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_table';
$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 .= '//table[@class = "double-field-table"]/tbody';
$item_xpath = $prefix . '/tr[1]/td[normalize-space() = "Foo 1"]/following-sibling::td[normalize-space() = "Foo 2"]';
$this
->assertXpath($item_xpath);
$item_xpath = $prefix . '/tr[2]/td[normalize-space() = "Bar 1"]/following-sibling::td[normalize-space() = "Bar 2"]';
$this
->assertXpath($item_xpath);
$item_xpath = $prefix . '/tr[3]/td[normalize-space() = "Qux 1"]/following-sibling::td[normalize-space() = "Qux 2"]';
$this
->assertXpath($item_xpath);
$this
->drupalGet($this->displayAdminPath);
$expected_summary = [
'Enable row number column: no',
'<b>First subfield - text</b>',
'Hidden: no',
'<b>Second subfield - text</b>',
'Hidden: no',
];
$this
->assertSettingsSummary($expected_summary);
$this
->openSettingsForm();
$page
->checkField('Enable row number column');
$page
->fillField('First column label', 'First');
$page
->fillField('Second column label', 'Second');
$this
->submitSettingsForm();
$this
->drupalGet($this->displayAdminPath);
$expected_summary = [
'Enable row number column: yes',
'Number column label: №',
'First column label: First',
'Second column label: Second',
'<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 .= '//table[contains(@class, "double-field-table")]';
$header_xpath = $prefix . '/thead/tr/th[text() = "№"]/following-sibling::th[text() = "First"]/following-sibling::th[text() = "Second"]';
$this
->assertXpath($header_xpath);
$item_xpath = $prefix . '//tr[1]/td[normalize-space() = "Foo 1"]/following-sibling::td[normalize-space() = "Foo 2"]';
$this
->assertXpath($item_xpath);
$item_xpath = $prefix . '//tr[2]/td[normalize-space() = "Bar 1"]/following-sibling::td[normalize-space() = "Bar 2"]';
$this
->assertXpath($item_xpath);
$item_xpath = $prefix . '//tr[3]/td[normalize-space() = "Qux 1"]/following-sibling::td[normalize-space() = "Qux 2"]';
$this
->assertXpath($item_xpath);
}