1 field_group.display.test public GroupDisplayTestCase::testDetails()

Test the details formatter.

File

core/modules/field_group/tests/field_group.display.test, line 207
Test file for field group display.

Class

GroupDisplayTestCase
Tests the functionality of the 'Manage display' screens.

Code

public function testDetails() {

  $data = array(
    'label' => 'Wrapper',
    'weight' => '1',
    'children' => array(
      0 => 'field_test',
    ),
    'format_type' => 'details',
    'format_settings' => array(
      'label' => 'Link',
      'instance_settings' => array(
        'required_fields' => 0,
        'id' => 'detail-id',
        'label_element' => 'strong',
        'classes' => 'test-class',
        'description' => 'description of details',
      ),
      'formatter' => 'open',
    ),
  );
  $group = $this->createDisplayGroup('default', $data);

  $groups = field_group_info_groups('node', 'post', 'default', TRUE);
  $this->backdropGet('node/' . $this->node->nid);

  // Test group ids and classes.
  $this->assertFieldByXPath("//details[contains(@id, 'detail-id')]", NULL, t('Detail id set on detail'));
  $this->assertFieldByXPath("//details[contains(@class, 'test-class')]", NULL, t('Test class set on details') . ' class="' . $group->group_name . ' test-class');

  // Test group label.
  $this->assertRaw('<summary><span><strong>' . $data['label'] . '</strong></span></summary>', t('Label is shown'));
  $this->assertRaw('<div class="details-content-wrapper">description of details</div>', t('Description of details is shown'));

  $this->assertFieldByXPath("//details[contains(@open, '1')]", NULL, t('Open attribute is set'));

  // Change to closed.
  $group->format_settings['formatter'] = 'closed';

  field_group_group_save($group, FALSE);
  $groups = field_group_info_groups('node', 'post', 'default', TRUE);
  $this->backdropGet('node/' . $this->node->nid);

  $this->assertNoFieldByXPath("//details[contains(@open, '1')]", NULL, t('Open attribute is not set'));
}