152 lines
5.8 KiB
Plaintext
152 lines
5.8 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Unit test file for groups.
|
|
*
|
|
* @todo - fill along if we know more.
|
|
*
|
|
* - nest a group under another group and see if parent_name is first group
|
|
* - nest a group under second group and see if parent_name is second group
|
|
* - settings: open f and verify on front-end (classes)
|
|
* - settings: collapsible f and verify on front-end (classes)
|
|
* - settings: collapsed f and verify on front-end (classes)
|
|
* - settings: vertical tabs and verify on front-end (classes)
|
|
* - settings: horizontal item and verify on front-end (classes)
|
|
* - settings: vertical item and verify on front-end (classes)
|
|
* - settings: hidden (simple div) and verify on front-end (classes)
|
|
* - settings: label and verify on front-end
|
|
* - delete a fieldgroup - make sure we have a couple with the same name
|
|
* and make sure the right one is deleted!
|
|
*/
|
|
|
|
/**
|
|
* Group UI tests.
|
|
*/
|
|
class GroupUITestCase extends DrupalWebTestCase {
|
|
public static function getInfo() {
|
|
return array(
|
|
'name' => 'Field group tests',
|
|
'description' => 'Test the field group functionality.',
|
|
'group' => 'Field group',
|
|
);
|
|
}
|
|
|
|
function setUp() {
|
|
parent::setUp('field_test', 'field_group');
|
|
|
|
// Create test user.
|
|
$admin_user = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'access administration pages', 'bypass node access'));
|
|
$this->drupalLogin($admin_user);
|
|
|
|
// Create random group name.
|
|
$this->group_label = $this->randomName(8);
|
|
$this->group_name_input = drupal_strtolower($this->randomName(8));
|
|
$this->group_name = 'group_' . $this->group_name_input;
|
|
|
|
// Create a fieldgroup.
|
|
$field_group = new stdClass;
|
|
$field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
|
|
$field_group->api_version = 1;
|
|
$field_group->identifier = 'wrapper|node|article|form';
|
|
$field_group->group_name = 'wrapper';
|
|
$field_group->entity_type = 'node';
|
|
$field_group->bundle = 'article';
|
|
$field_group->mode = 'form';
|
|
$field_group->parent_name = '';
|
|
$field_group->data = array(
|
|
'label' => 'Wrapper',
|
|
'weight' => '1',
|
|
'children' => array(
|
|
0 => 'field_image',
|
|
),
|
|
'format_type' => 'div',
|
|
'format_settings' => array(
|
|
'label' => 'Link',
|
|
'instance_settings' => array(
|
|
'required_fields' => 0,
|
|
'id' => 'wrapper-id',
|
|
'classes' => '',
|
|
'description' => '',
|
|
'show_label' => '0',
|
|
'label_element' => 'h3',
|
|
'effect' => 'none',
|
|
'speed' => 'fast',
|
|
),
|
|
'formatter' => 'open',
|
|
),
|
|
);
|
|
drupal_write_record('field_group', $field_group);
|
|
ctools_export_crud_enable('field_group', $field_group->identifier);
|
|
}
|
|
|
|
/**
|
|
* Creates a group on the article content type.
|
|
*/
|
|
function createGroup() {
|
|
|
|
// Setup new group.
|
|
$group = array(
|
|
'fields[_add_new_group][label]' => $this->group_label,
|
|
'fields[_add_new_group][group_name]' => $this->group_name_input,
|
|
);
|
|
|
|
// Add new group on the 'Manage fields' page.
|
|
$this->drupalPost('admin/structure/types/manage/article/fields', $group, t('Save'));
|
|
$this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.'));
|
|
|
|
// Test if group is in the $groups array.
|
|
$groups = field_group_info_groups('node', 'article', 'form', TRUE);
|
|
$this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array'));
|
|
|
|
// Add new group on the 'Manage display' page.
|
|
$this->drupalPost('admin/structure/types/manage/article/display', $group, t('Save'));
|
|
$this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.'));
|
|
|
|
// Test if group is in the $groups array.
|
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
|
$this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array'));
|
|
}
|
|
|
|
/**
|
|
* Delete a group.
|
|
*/
|
|
function deleteGroup() {
|
|
|
|
$this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/form', array(), t('Delete'));
|
|
$this->assertRaw(t('The group %label has been deleted from the %article content type.', array('%label' => $this->group_label, '%article' => 'Article')), t('Group removal message displayed on screen.'));
|
|
|
|
// Test that group is not in the $groups array.
|
|
$groups = field_group_info_groups('node', 'article', 'form', TRUE);
|
|
$this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting'));
|
|
|
|
$this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/default', array(), t('Delete'));
|
|
$this->assertRaw(t('The group %label has been deleted from the %article content type.', array('%label' => $this->group_label, '%article' => 'Article')), t('Group removal message displayed on screen.'));
|
|
|
|
// Test that group is not in the $groups array.
|
|
$groups = field_group_info_groups('node', 'article', 'default', TRUE);
|
|
$this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting'));
|
|
}
|
|
|
|
/**
|
|
* General CRUD.
|
|
*/
|
|
function testCRUDGroup() {
|
|
$this->createGroup();
|
|
$this->deleteGroup();
|
|
}
|
|
|
|
/**
|
|
* Nest a field underneath a group.
|
|
*/
|
|
function testNestField() {
|
|
|
|
// Test on the wrapper field.
|
|
$groups = field_group_info_groups('node', 'article', 'form', TRUE);
|
|
$this->assertTrue(in_array('field_image', $groups['wrapper']->children), t('Image is a child of %group', array('%group' => 'Wrapper')));
|
|
|
|
$this->drupalGet('node/add/article');
|
|
$this->assertRaw('id="wrapper-id"', t('Wrapper id set on wrapper div'));
|
|
}
|
|
}
|