function testFieldgroupFields::testFieldgroup in Content Construction Kit (CCK) 6.3
File
- tests/
fieldgroup.test, line 92
Class
Code
function testFieldgroup() {
// Create a content type with a multivalue text field.
$type = $this->content_types[0];
$type_name = $type->type;
$type_url = str_replace('_', '-', $type_name);
$admin_type_url = 'admin/content/node-type/' . $type_url;
$field = $this
->createFieldText(array(
'text_processing' => 0,
'multiple' => 1,
'weight' => -4,
));
$field_name = $field['field_name'];
$field2 = $this
->createFieldText(array(
'text_processing' => 0,
'multiple' => 1,
'weight' => -3,
));
$field_name2 = $field2['field_name'];
$fields = array(
$field_name,
$field_name2,
);
// Create a fieldgroup and nest the fields in it.
$settings = array(
'type_name' => $type_name,
'group_type' => 'standard',
'parent' => '',
);
$group_name = $this
->createGroup($settings, $fields);
// Check that our new group shows up on the administration pages.
$this
->drupalGet($admin_type_url . '/groups/' . $group_name);
$this
->drupalGet($admin_type_url . '/fields');
$this
->assertText($group_name, 'Group name displayed');
$this
->drupalGet($admin_type_url . '/display');
$this
->assertText($group_name, 'Group name displayed');
// Create a node with 2 values set in each of 2 fields.
$value1 = $this
->randomName(5);
$value2 = $this
->randomName(5);
$value3 = $this
->randomName(5);
$value4 = $this
->randomName(5);
$edit = array(
'title' => $this
->randomName(20),
'body' => $this
->randomName(20),
'type' => $type_name,
);
$edit[$field_name][0]['value'] = $value1;
$edit[$field_name][1]['value'] = $value2;
$edit[$field_name2][0]['value'] = $value3;
$edit[$field_name2][1]['value'] = $value4;
$node = $this
->drupalCreateNode($edit);
$this
->drupalGet('node/' . $node->nid);
$this
->assertText($value1, 'First value displayed');
$this
->assertText($value2, 'Second value displayed');
$this
->assertText($value3, 'Third value displayed');
$this
->assertText($value4, 'Fourth value displayed');
$this
->assertText($group_name, 'Group name displayed');
// Create a second fieldgroup and nest the first fieldgroup inside the second one.
$settings = array(
'type_name' => $type_name,
'group_type' => 'standard',
'parent' => '',
);
$group_name2 = $this
->createGroup($settings, array());
// Check that our new group shows up on the administration pages.
$this
->drupalGet($admin_type_url . '/groups/' . $group_name2);
$this
->drupalGet($admin_type_url . '/fields');
$this
->assertText($group_name2, 'Group name 2 displayed');
$this
->drupalGet($admin_type_url . '/display');
$this
->assertText($group_name2, 'Group name 2 displayed');
// Set the first group to use the second group as a parent.
$groups = fieldgroup_groups($type->name);
$settings = $groups[$group_name];
$settings['parent'] = $group_name2;
$group_name = $this
->createGroup($settings, $fields);
// Clear the content cache to re-generate the node display.
cache_clear_all('content:', content_cache_tablename(), TRUE);
// Checking that the outside group is displayed is sufficient to tell us they got nested,
// because it has no fields and empty groups are not displayed.
$this
->drupalGet('node/' . $node->nid);
$this
->assertText($value1, 'First value displayed');
$this
->assertText($value2, 'Second value displayed');
$this
->assertText($value3, 'Third value displayed');
$this
->assertText($value4, 'Fourth value displayed');
$this
->assertText($group_name, 'Group name displayed');
$this
->assertText($group_name2, 'Group name 2 displayed');
}