You are here

function GroupDisplayTestCase::testDiv in Field Group 7

Test the div formatter.

File

tests/field_group.display.test, line 137
Test file for fieldgroup display.

Class

GroupDisplayTestCase
Group display tests

Code

function testDiv() {
  $data = array(
    'label' => 'Wrapper',
    'weight' => '1',
    'children' => array(
      0 => 'field_test',
    ),
    'format_type' => 'div',
    'format_settings' => array(
      'label' => 'Link',
      'instance_settings' => array(
        'required_fields' => 0,
        'id' => 'wrapper-id',
        'classes' => 'test-class',
        'description' => '',
        'show_label' => FALSE,
        'label_element' => 'h3',
        'effect' => 'blink',
        'speed' => 'fast',
      ),
      'formatter' => 'open',
    ),
  );
  $group = $this
    ->createGroup('default', $data);
  $groups = field_group_info_groups('node', 'article', 'default', TRUE);
  $this
    ->drupalGet('node/' . $this->node->nid);

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

  // Test group label.
  $this
    ->assertNoRaw('<h3><span>' . $data['label'] . '</span></h3>', t('Label is not shown'));

  // Set show label to true.
  $group->data['format_settings']['instance_settings']['show_label'] = TRUE;
  drupal_write_record('field_group', $group, array(
    'identifier',
  ));
  $groups = field_group_info_groups('node', 'article', 'default', TRUE);
  $this
    ->drupalGet('node/' . $this->node->nid);
  $this
    ->assertRaw('<h3><span>' . $data['label'] . '</span></h3>', t('Label is shown'));

  // Change to collapsible
  $group->data['format_settings']['formatter'] = 'collapsible';
  drupal_write_record('field_group', $group, array(
    'identifier',
  ));
  $groups = field_group_info_groups('node', 'article', 'default', TRUE);
  $this
    ->drupalGet('node/' . $this->node->nid);
  $this
    ->assertFieldByXPath("//div[contains(@class, 'speed-fast')]", NULL, t('Speed class is set'));
  $this
    ->assertFieldByXPath("//div[contains(@class, 'effect-blink')]", NULL, t('Effect class is set'));
}