You are here

public function EntityDisplayTest::testTabs in Field Group 8.3

Same name and namespace in other branches
  1. 8 tests/src/Functional/EntityDisplayTest.php \Drupal\Tests\field_group\Functional\EntityDisplayTest::testTabs()

Test the tabs formatter.

File

tests/src/Functional/EntityDisplayTest.php, line 215

Class

EntityDisplayTest
Tests for displaying entities.

Namespace

Drupal\Tests\field_group\Functional

Code

public function testTabs() {
  $data = [
    'label' => 'Tab 1',
    'weight' => '1',
    'children' => [
      0 => 'field_test',
    ],
    'format_type' => 'tab',
    'format_settings' => [
      'label' => 'Tab 1',
      'classes' => 'test-class',
      'description' => '',
      'formatter' => 'open',
    ],
  ];
  $first_tab = $this
    ->createGroup('node', $this->type, 'view', 'default', $data);
  $data = [
    'label' => 'Tab 2',
    'weight' => '1',
    'children' => [
      0 => 'field_test_2',
    ],
    'format_type' => 'tab',
    'format_settings' => [
      '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 = [
    'label' => 'Tabs',
    'weight' => '1',
    'children' => [
      0 => $first_tab->group_name,
      1 => $second_tab->group_name,
    ],
    'format_type' => 'tabs',
    'format_settings' => [
      '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
    ->assertCount(1, $this
    ->xpath("//div[contains(@class, 'test-class-wrapper')]"), 'Test class set on tabs wrapper');
  $this
    ->assertCount(1, $this
    ->xpath("//details[contains(@class, 'test-class-2')]"), 'Test class set on second tab');
  $this
    ->assertSession()
    ->responseContains('<div class="details-description">description of second tab</div>');

  // Test if correctly nested.
  $this
    ->assertCount(2, $this
    ->xpath("//div[contains(@class, 'test-class-wrapper')]//details[contains(@class, 'test-class')]"), 'First tab is displayed as child of the wrapper.');
  $this
    ->assertCount(1, $this
    ->xpath("//div[contains(@class, 'test-class-wrapper')]//details[contains(@class, 'test-class-2')]"), 'Second tab is displayed as child of the wrapper.');

  // Test if it's a vertical tab.
  $this
    ->assertCount(1, $this
    ->xpath('//div[@data-vertical-tabs-panes=""]'), '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
    ->assertCount(1, $this
    ->xpath('//div[@data-horizontal-tabs-panes=""]'), 'Tabs are shown horizontal.');
}