You are here

public function EntityDisplayTest::testAccordion 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::testAccordion()

Test the accordion formatter.

File

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

Class

EntityDisplayTest
Tests for displaying entities.

Namespace

Drupal\Tests\field_group\Functional

Code

public function testAccordion() {
  $data = [
    'label' => 'Accordion item 1',
    'weight' => '1',
    'children' => [
      0 => 'field_test',
    ],
    'format_type' => 'accordion_item',
    'format_settings' => [
      'label' => 'Accordion item 1',
      'classes' => 'test-class',
      'formatter' => 'closed',
    ],
  ];
  $first_item = $this
    ->createGroup('node', $this->type, 'view', 'default', $data);
  $data = [
    'label' => 'Accordion item 2',
    'weight' => '1',
    'children' => [
      0 => 'field_test_2',
    ],
    'format_type' => 'accordion_item',
    'format_settings' => [
      'label' => 'Tab 2',
      'classes' => 'test-class-2',
      'formatter' => 'open',
    ],
  ];
  $second_item = $this
    ->createGroup('node', $this->type, 'view', 'default', $data);
  $data = [
    'label' => 'Accordion',
    'weight' => '1',
    'children' => [
      0 => $first_item->group_name,
      1 => $second_item->group_name,
    ],
    'format_type' => 'accordion',
    'format_settings' => [
      'label' => 'Tab 1',
      'classes' => 'test-class-wrapper',
      'effect' => 'bounceslide',
    ],
  ];
  $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("//div[contains(@class, 'effect-bounceslide')]"), 'Correct effect is set on the accordion');
  $this
    ->assertCount(3, $this
    ->xpath("//div[contains(@class, 'test-class')]"), 'Accordion item with test-class is shown');
  $this
    ->assertCount(1, $this
    ->xpath("//div[contains(@class, 'test-class-2')]"), 'Accordion item with test-class-2 is shown');
  $this
    ->assertCount(1, $this
    ->xpath("//h3[contains(@class, 'field-group-accordion-active')]"), 'Accordion item 2 was set active');

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