- <?php
- * @file
- * Test file for field group display.
- */
-
- include_once('field_group.test');
-
-
- * Tests the functionality of the 'Manage display' screens.
- */
- class GroupDisplayTestCase extends GroupTestCase {
-
-
- * @var Node
- */
- protected $node;
-
-
- * Set up.
- */
- public function setUp() {
- parent::setUp();
-
- $node = entity_create('node', array ('type' => 'post'));
- $node->uid = $this->admin_user->uid;
- $node->title = $this->randomName();
- $node->status = 1;
-
-
- $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' => 'post',
- '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();
- $this->node = $node;
- }
-
-
- * Create a new group.
- * @param string $mode
- * Form or display.
- * @param array $data
- * Data for the field group.
- */
- public function createDisplayGroup($mode, array $data) {
-
- $group_name = 'group_' . backdrop_strtolower($this->randomName(8));
-
- $field_group = new stdClass;
- $field_group->group_name = $group_name;
- $field_group->entity_type = 'node';
- $field_group->bundle = 'post';
- $field_group->mode = $mode;
- $field_group->parent_name = '';
- $field_group->children = $data['children'];
- $field_group->label = $data['label'];
- $field_group->weight = $data['weight'];
- $field_group->format_type = $data['format_type'];
- $field_group->format_settings = $data['format_settings'];
- field_group_group_save($field_group);
-
- return $field_group;
- }
-
-
- * Test if an empty formatter.
- */
- public function testFieldAccess() {
-
- $data = array(
- 'label' => 'Wrapper',
- 'weight' => '1',
- 'children' => array(
- 0 => 'field_no_access',
- ),
- 'format_type' => 'html-element',
- 'format_settings' => array(
- 'label' => 'Link',
- 'instance_settings' => array(
- 'wrapper' => 'div',
- 'required_fields' => 0,
- 'id' => 'wrapper-id',
- 'classes' => 'test-class',
- 'description' => '',
- 'show_label' => FALSE,
- 'label_element' => 'h3',
- ),
- ),
- );
- $group = $this->createDisplayGroup('default', $data);
-
- $groups = field_group_info_groups('node', 'post', 'default', TRUE);
- $this->backdropGet('node/' . $this->node->nid);
-
-
- $this->assertNoFieldByXPath("//div[contains(@id, 'wrapper-id')]", NULL, t('Div that contains fields with no access is not shown.'));
- }
-
-
- * Test the vertical tabs formatter.
- */
- public 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->createDisplayGroup('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->createDisplayGroup('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->createDisplayGroup('default', $data);
-
- $groups = field_group_info_groups('node', 'post', 'default', TRUE);
-
- $this->backdropGet('node/' . $this->node->nid);
-
-
- $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="description">description of second tab</div>', t('Description of tab is shown'));
-
-
- $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 details formatter.
- */
- 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);
-
-
- $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');
-
-
- $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'));
-
-
- $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'));
- }
-
- }