You are here

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

Test the html element formatter.

File

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

Class

EntityDisplayTest
Tests for displaying entities.

Namespace

Drupal\Tests\field_group\Functional

Code

public function testHtmlElement() {
  $data = array(
    'weight' => '1',
    'children' => array(
      0 => 'field_test',
      1 => 'body',
    ),
    'label' => 'Link',
    'format_type' => 'html_element',
    'format_settings' => array(
      '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
    ->assertFieldByXPath("//div[contains(@id, 'wrapper-id')]", NULL, 'Wrapper id set on wrapper div');
  $this
    ->assertFieldByXPath("//div[contains(@class, 'test-class')]", NULL, 'Test class set on wrapper div, class="' . $group->group_name . ' test-class');

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

  // Set show label to true.
  $group->format_settings['show_label'] = TRUE;
  $group->format_settings['label_element'] = 'h3';
  field_group_group_save($group);
  $this
    ->drupalGet('node/' . $this->node
    ->id());
  $this
    ->assertRaw('<h3>' . $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
    ->assertFieldByXPath("//div[contains(@class, 'speed-fast')]", NULL, 'Speed class is set');
  $this
    ->assertFieldByXPath("//div[contains(@class, 'effect-blink')]", NULL, 'Effect class is set');
}