public function EntityDisplayTest::testTabs in Field Group 8
Same name and namespace in other branches
- 8.3 tests/src/Functional/EntityDisplayTest.php \Drupal\Tests\field_group\Functional\EntityDisplayTest::testTabs()
Test the tabs formatter.
File
- tests/
src/ Functional/ EntityDisplayTest.php, line 209
Class
- EntityDisplayTest
- Tests for displaying entities.
Namespace
Drupal\Tests\field_group\FunctionalCode
public function testTabs() {
$data = array(
'label' => 'Tab 1',
'weight' => '1',
'children' => array(
0 => 'field_test',
),
'format_type' => 'tab',
'format_settings' => array(
'label' => 'Tab 1',
'classes' => 'test-class',
'description' => '',
'formatter' => 'open',
),
);
$first_tab = $this
->createGroup('node', $this->type, 'view', 'default', $data);
$data = array(
'label' => 'Tab 2',
'weight' => '1',
'children' => array(
0 => 'field_test_2',
),
'format_type' => 'tab',
'format_settings' => array(
'label' => 'Tab 1',
'classes' => 'test-class-2',
'description' => 'description of second tab',
'formatter' => 'closed',
),
);
$second_tab = $this
->createGroup('node', $this->type, 'view', 'default', $data);
$data = array(
'label' => 'Tabs',
'weight' => '1',
'children' => array(
0 => $first_tab->group_name,
1 => $second_tab->group_name,
),
'format_type' => 'tabs',
'format_settings' => array(
'direction' => 'vertical',
'label' => 'Tab 1',
'classes' => 'test-class-wrapper',
),
);
$tabs_group = $this
->createGroup('node', $this->type, 'view', 'default', $data);
$this
->drupalGet('node/' . $this->node
->id());
// Test properties.
$this
->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]", NULL, 'Test class set on tabs wrapper');
$this
->assertFieldByXPath("//details[contains(@class, 'test-class-2')]", NULL, 'Test class set on second tab');
$this
->assertRaw('<div class="details-description">description of second tab</div>');
// Test if correctly nested.
$this
->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//details[contains(@class, 'test-class')]", NULL, 'First tab is displayed as child of the wrapper.');
$this
->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//details[contains(@class, 'test-class-2')]", NULL, 'Second tab is displayed as child of the wrapper.');
// Test if it's a vertical tab.
$this
->assertFieldByXPath('//div[@data-vertical-tabs-panes=""]', NULL, 'Tabs are shown vertical.');
// Switch to horizontal
$tabs_group->format_settings['direction'] = 'horizontal';
field_group_group_save($tabs_group);
$this
->drupalGet('node/' . $this->node
->id());
// Test if it's a horizontal tab.
$this
->assertFieldByXPath('//div[@data-horizontal-tabs-panes=""]', NULL, 'Tabs are shown horizontal.');
}