You are here

public function EntityDisplayTest::testAccordion in Field Group 8

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

Test the accordion formatter.

File

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

Class

EntityDisplayTest
Tests for displaying entities.

Namespace

Drupal\Tests\field_group\Functional

Code

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

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