123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- <?php
- /**
- * @file
- * Test file for fieldgroup display.
- */
- /**
- * Group display tests
- */
- class GroupDisplayTestCase extends DrupalWebTestCase {
- protected $node;
- public static function getInfo() {
- return array(
- 'name' => 'Display tests',
- 'description' => 'Test the field group display.',
- 'group' => 'Field Group',
- );
- }
- function setUp() {
- parent::setUp('field_test', 'field_group', 'field_group_test');
- $node = new stdClass();
- $node->type = 'article';
- $node->title = $this->randomName();
- $node->status = 1;
- // Create test fields.
- $test_fields = array('field_test', 'field_test_2', 'field_no_access');
- foreach ($test_fields as $field_name) {
- $field = array(
- 'field_name' => $field_name,
- 'type' => 'test_field',
- 'cardinality' => 1,
- );
- $instance = array(
- 'field_name' => $field_name,
- 'entity_type' => 'node',
- 'bundle' => 'article',
- 'label' => $this->randomName(),
- 'display' => array(
- 'default' => array(
- 'type' => 'field_test_default',
- 'settings' => array(
- 'test_formatter_setting' => $this->randomName(),
- ),
- ),
- 'teaser' => array(
- 'type' => 'field_test_default',
- 'settings' => array(
- 'test_formatter_setting' => $this->randomName(),
- ),
- ),
- ),
- );
- field_create_field($field);
- field_create_instance($instance);
- $node->{$field_name}[LANGUAGE_NONE][0]['value'] = mt_rand(1, 127);
- }
- node_save($node);
- $this->node = $node;
- }
- /**
- * Create a new group.
- * @param array $data
- * Data for the field group.
- */
- function createGroup($mode, array $data) {
- $group_name = 'group_' . drupal_strtolower($this->randomName(8));
- $identifier = $group_name . '|node|article|' . $mode;
- $field_group = new stdClass;
- $field_group->disabled = FALSE;
- $field_group->api_version = 1;
- $field_group->identifier = $identifier;
- $field_group->group_name = $group_name;
- $field_group->entity_type = 'node';
- $field_group->bundle = 'article';
- $field_group->mode = $mode;
- $field_group->parent_name = '';
- $field_group->children = $data['children'];
- $field_group->data = $data;
- drupal_write_record('field_group', $field_group);
- ctools_export_crud_enable('field_group', $field_group->identifier);
- return $field_group;
- }
- /**
- * Test if an empty formatter.
- */
- function testFieldAccess() {
- $data = array(
- 'label' => 'Wrapper',
- 'weight' => '1',
- 'children' => array(
- 0 => 'field_no_access',
- ),
- '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 if group is not shown.
- $this->assertNoFieldByXPath("//div[contains(@id, 'wrapper-id')]", NULL, t('Div that contains fields with no access is not shown.'));
- }
- /**
- * Test the div formatter.
- */
- 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'));
- }
- /**
- * Test the horizontal tabs formatter.
- */
- function testHorizontalTabs() {
- $data = array(
- 'label' => 'Tab 1',
- 'weight' => '1',
- 'children' => array(
- 0 => 'field_test',
- ),
- 'format_type' => 'htab',
- 'format_settings' => array(
- 'label' => 'Tab 1',
- 'instance_settings' => array(
- 'classes' => 'test-class',
- 'description' => '',
- ),
- 'formatter' => 'open',
- ),
- );
- $first_tab = $this->createGroup('default', $data);
- $data = array(
- 'label' => 'Tab 2',
- 'weight' => '1',
- 'children' => array(
- 0 => 'field_test_2',
- ),
- 'format_type' => 'htab',
- 'format_settings' => array(
- 'label' => 'Tab 1',
- 'instance_settings' => array(
- 'classes' => 'test-class-2',
- 'description' => 'description of second tab',
- ),
- 'formatter' => 'closed',
- ),
- );
- $second_tab = $this->createGroup('default', $data);
- $data = array(
- 'label' => 'Tabs',
- 'weight' => '1',
- 'children' => array(
- 0 => $first_tab->group_name,
- 1 => $second_tab->group_name,
- ),
- 'format_type' => 'htabs',
- 'format_settings' => array(
- 'label' => 'Tab 1',
- 'instance_settings' => array(
- 'classes' => 'test-class-wrapper',
- ),
- ),
- );
- $tabs = $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("//fieldset[contains(@class, 'test-class-2')]", NULL, t('Test class set on second tab'));
- $this->assertRaw('<div class="fieldset-description">description of second tab</div>', t('Description of tab is shown'));
- $this->assertRaw('class="collapsible collapsed test-class-2', t('Second tab is default collapsed'));
- // Test if correctly nested
- $this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//fieldset[contains(@class, 'test-class')]", NULL, 'First tab is displayed as child of the wrapper.');
- $this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//fieldset[contains(@class, 'test-class-2')]", NULL, 'Second tab is displayed as child of the wrapper.');
- }
- /**
- * Test the vertical tabs formatter.
- */
- function testVerticalTabs() {
- $data = array(
- 'label' => 'Tab 1',
- 'weight' => '1',
- 'children' => array(
- 0 => 'field_test',
- ),
- 'format_type' => 'tab',
- 'format_settings' => array(
- 'label' => 'Tab 1',
- 'instance_settings' => array(
- 'classes' => 'test-class',
- 'description' => '',
- ),
- 'formatter' => 'open',
- ),
- );
- $first_tab = $this->createGroup('default', $data);
- $first_tab_id = 'edit-' . $first_tab->group_name;
- $data = array(
- 'label' => 'Tab 2',
- 'weight' => '1',
- 'children' => array(
- 0 => 'field_test_2',
- ),
- 'format_type' => 'tab',
- 'format_settings' => array(
- 'label' => 'Tab 1',
- 'instance_settings' => array(
- 'classes' => 'test-class-2',
- 'description' => 'description of second tab',
- ),
- 'formatter' => 'closed',
- ),
- );
- $second_tab = $this->createGroup('default', $data);
- $second_tab_id = 'edit-' . $second_tab->group_name;
- $data = array(
- 'label' => 'Tabs',
- 'weight' => '1',
- 'children' => array(
- 0 => $first_tab->group_name,
- 1 => $second_tab->group_name,
- ),
- 'format_type' => 'tabs',
- 'format_settings' => array(
- 'label' => 'Tab 1',
- 'instance_settings' => array(
- 'classes' => 'test-class-wrapper',
- ),
- ),
- );
- $tabs = $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("//fieldset[contains(@class, 'test-class-2')]", NULL, t('Test class set on second tab'));
- $this->assertRaw('<div class="fieldset-description">description of second tab</div>', t('Description of tab is shown'));
- $this->assertRaw('class="collapsible collapsed test-class-2', t('Second tab is default collapsed'));
- // Test if correctly nested
- $this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//fieldset[contains(@id, '$first_tab_id')]", NULL, 'First tab is displayed as child of the wrapper.');
- $this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//fieldset[contains(@id, '$second_tab_id')]", NULL, 'Second tab is displayed as child of the wrapper.');
- }
- /**
- * Test the accordion formatter.
- */
- 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.');
- }
- }
|