You are here

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

Test the html element formatter.

File

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

Class

EntityDisplayTest
Tests for displaying entities.

Namespace

Drupal\Tests\field_group\Functional

Code

public function testHtmlElement() {
  $data = [
    'weight' => '1',
    'children' => [
      0 => 'field_test',
      1 => 'body',
    ],
    'label' => 'Link',
    'format_type' => 'html_element',
    'format_settings' => [
      'label' => 'Link',
      'element' => 'div',
      'id' => 'wrapper-id',
      'classes' => 'test-class',
    ],
  ];
  $group = $this
    ->createGroup('node', $this->type, 'view', 'default', $data);

  // $groups = field_group_info_groups('node', 'article', 'view', 'default', TRUE);.
  $this
    ->drupalGet('node/' . $this->node
    ->id());

  // Test group ids and classes.
  $this
    ->assertCount(1, $this
    ->xpath("//div[contains(@id, 'wrapper-id')]"), 'Wrapper id set on wrapper div');
  $this
    ->assertCount(1, $this
    ->xpath("//div[contains(@class, 'test-class')]"), 'Test class set on wrapper div, class="' . $group->group_name . ' test-class');

  // Test group label.
  $this
    ->assertSession()
    ->responseNotContains('<h3><span>' . $data['label'] . '</span></h3>');

  // Set show label to true.
  $group->format_settings['show_label'] = TRUE;
  $group->format_settings['label_element'] = 'h3';
  $group->format_settings['label_element_classes'] = 'my-label-class';
  field_group_group_save($group);
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->assertSession()
    ->responseContains('<h3 class="my-label-class">' . $data['label'] . '</h3>');

  // Change to collapsible with blink effect.
  $group->format_settings['effect'] = 'blink';
  $group->format_settings['speed'] = 'fast';
  field_group_group_save($group);
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->assertCount(1, $this
    ->xpath("//div[contains(@class, 'speed-fast')]"), 'Speed class is set');
  $this
    ->assertCount(1, $this
    ->xpath("//div[contains(@class, 'effect-blink')]"), 'Effect class is set');
}