function GroupDisplayTestCase::testAccordion in Field Group 7
Test the accordion formatter.
File
- tests/
field_group.display.test, line 342 - Test file for fieldgroup display.
Class
- GroupDisplayTestCase
- Group display tests
Code
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',
'instance_settings' => array(
'classes' => 'test-class',
),
'formatter' => 'closed',
),
);
$first_item = $this
->createGroup('default', $data);
$first_item_id = 'node_article_full_' . $first_item->group_name;
$data = array(
'label' => 'Accordion item 2',
'weight' => '1',
'children' => array(
0 => 'field_test_2',
),
'format_type' => 'accordion-item',
'format_settings' => array(
'label' => 'Tab 2',
'instance_settings' => array(
'classes' => 'test-class-2',
),
'formatter' => 'open',
),
);
$second_item = $this
->createGroup('default', $data);
$second_item_id = 'node_article_full_' . $second_item->group_name;
$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',
'instance_settings' => array(
'classes' => 'test-class-wrapper',
'effect' => 'bounceslide',
),
),
);
$accordion = $this
->createGroup('default', $data);
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
$this
->drupalGet('node/' . $this->node->nid);
// Test properties.
$this
->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]", NULL, t('Test class set on tabs wrapper'));
$this
->assertFieldByXPath("//div[contains(@class, 'effect-bounceslide')]", NULL, t('Correct effect is set on the accordion'));
$this
->assertFieldByXPath("//div[contains(@class, 'test-class')]", NULL, t('Accordion item with test-class is shown'));
$this
->assertFieldByXPath("//div[contains(@class, 'test-class-2')]", NULL, t('Accordion item with test-class-2 is shown'));
$this
->assertFieldByXPath("//h3[contains(@class, 'field-group-accordion-active')]", NULL, t('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.');
}