diff --git content.crud.test content.crud.test
index 48b5427..d66d035 100644
--- content.crud.test
+++ content.crud.test
@@ -1234,3 +1234,176 @@ class ContentOptionWidgetTest extends ContentCrudTestCase {
}
+class ContentMultigroupTest extends ContentCrudTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Multigroup'),
+ 'description' => t('Tests fields in a multigroup. Requires Schema module.', array('@schema_link' => 'http://www.drupal.org/project/schema')),
+ 'group' => t('CCK'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp('fieldgroup', 'content_multigroup');
+ $this->loginWithPermissions();
+ $this->acquireContentTypes(3);
+ $this->acquireNodes();
+ }
+
+ function testAddGroupFieldsUI() {
+ // Add a content type with a random name (to avoid schema module problems).
+ $type = 'simpletest'. mt_rand();
+ $type_name = $this->randomName(10);
+ $edit = array(
+ 'type' => $type,
+ 'name' => $type_name,
+ );
+ $this->drupalPost('admin/content/types/add', $edit, 'Save content type');
+ $admin_type_url = 'admin/content/node-type/'. $type;
+
+ // Add a multigroup to the content type.
+ $group_name = strtolower($this->randomName(10));
+ $group_label = $this->randomName(10);
+ $edit = array(
+ '_add_new_group[label]' => $group_label,
+ '_add_new_group[group_name]' => $group_name,
+ '_add_new_group[group_type]' => 'multigroup',
+ );
+ $this->drupalPost($admin_type_url .'/fields', $edit, 'Save');
+ $group_name = 'group_'. $group_name;
+ // Check if multigroup was created.
+ $this->assertRaw($admin_type_url .'/groups/'. $group_name, 'Group created');
+
+ // Add new field to the group.
+ $field1_label = $this->randomName(10);
+ $field1_name = strtolower($this->randomName(10));
+ $edit = array(
+ '_add_new_field[label]' => $field1_label,
+ '_add_new_field[field_name]' => $field1_name,
+ '_add_new_field[type]' => 'text',
+ '_add_new_field[widget_type]' => 'text_textfield',
+ '_add_new_field[parent]' => $group_name,
+ );
+ $this->drupalPost($admin_type_url .'/fields', $edit, 'Save');
+ $this->assertRaw('These settings apply only to the '. $field1_label .' field', 'Field settings page for new field displayed');
+ // Submit new field settings
+ $edit = array();
+ $this->drupalPost(NULL, $edit, 'Save field settings');
+ $this->assertRaw('Added field '. $field1_label .'.', 'Field settings for new field saved');
+ $field1_name = 'field_'. $field1_name;
+ $field1_type_url = $admin_type_url .'/fields/'. $field1_name;
+ $this->assertRaw($field1_type_url, 'New field displayed in overview');
+ $this->assertRaw($admin_type_url .'/groups/'. $group_name, 'New group displayed in overview');
+
+ // Add another new field to the group.
+ $field2_label = $this->randomName(10);
+ $field2_name = strtolower($this->randomName(10));
+ $edit = array(
+ '_add_new_field[label]' => $field2_label,
+ '_add_new_field[field_name]' => $field2_name,
+ '_add_new_field[type]' => 'text',
+ '_add_new_field[widget_type]' => 'text_textfield',
+ '_add_new_field[parent]' => $group_name,
+ );
+ $this->drupalPost($admin_type_url .'/fields', $edit, 'Save');
+ $this->assertRaw('These settings apply only to the '. $field2_label .' field', 'Field settings page for second field displayed');
+ // Submit new field settings
+ $edit = array();
+ $this->drupalPost(NULL, $edit, 'Save field settings');
+ $this->assertRaw('Added field '. $field2_label .'.', 'Field settings for second field saved');
+ $field2_name = 'field_'. $field2_name;
+ $field2_type_url = $admin_type_url .'/fields/'. $field2_name;
+ $this->assertRaw($field2_type_url, 'Second field displayed in overview');
+ $this->assertRaw($admin_type_url .'/groups/'. $group_name, 'New group displayed in overview');
+
+ // Check Parenting
+ $groups = fieldgroup_groups($type, FALSE, TRUE);
+ $this->assertTrue(isset($groups[$group_name]['fields'][$field1_name]), 'First field in correct group');
+ $this->assertFieldByXPath('//select[@id="edit-'. strtr($field1_name, '_', '-') .'-parent"]//option[@selected]', $group_name, 'Parenting for first field correct in overview');
+ $this->assertTrue(isset($groups[$group_name]['fields'][$field2_name]), 'Second field in correct group');
+ $this->assertFieldByXPath('//select[@id="edit-'. strtr($field2_name, '_', '-') .'-parent"]//option[@selected]', $group_name, 'Parenting for second field correct in overview');
+ }
+
+ function testAddContentUI() {
+ // Add a content type with a random name (to avoid schema module problems).
+ $type = 'simpletest'. mt_rand();
+ $type_name = $this->randomName(10);
+ $edit = array(
+ 'type' => $type,
+ 'name' => $type_name,
+ );
+ $this->drupalPost('admin/content/types/add', $edit, 'Save content type');
+ $admin_type_url = 'admin/content/node-type/'. $type;
+
+ // Add a multigroup to the content type.
+ $group_name = strtolower($this->randomName(10));
+ $group_label = $this->randomName(10);
+ $edit = array(
+ '_add_new_group[label]' => $group_label,
+ '_add_new_group[group_name]' => $group_name,
+ '_add_new_group[group_type]' => 'multigroup',
+ );
+ $this->drupalPost($admin_type_url .'/fields', $edit, 'Save');
+ $group_name = 'group_'. $group_name;
+
+ // Add new field to the group.
+ $field1_label = $this->randomName(10);
+ $field1_name = strtolower($this->randomName(10));
+ $edit = array(
+ '_add_new_field[label]' => $field1_label,
+ '_add_new_field[field_name]' => $field1_name,
+ '_add_new_field[type]' => 'text',
+ '_add_new_field[widget_type]' => 'text_textfield',
+ '_add_new_field[parent]' => $group_name,
+ );
+ $this->drupalPost($admin_type_url .'/fields', $edit, 'Save');
+ // Submit new field settings
+ $edit = array();
+ $this->drupalPost(NULL, $edit, 'Save field settings');
+ $field1_name = 'field_'. $field1_name;
+
+ // Add another new field to the group.
+ $field2_label = $this->randomName(10);
+ $field2_name = strtolower($this->randomName(10));
+ $edit = array(
+ '_add_new_field[label]' => $field2_label,
+ '_add_new_field[field_name]' => $field2_name,
+ '_add_new_field[type]' => 'text',
+ '_add_new_field[widget_type]' => 'text_textfield',
+ '_add_new_field[parent]' => $group_name,
+ );
+ $this->drupalPost($admin_type_url .'/fields', $edit, 'Save');
+ // Submit new field settings
+ $edit = array();
+ $this->drupalPost(NULL, $edit, 'Save field settings');
+ $field2_name = 'field_'. $field2_name;
+
+ // Check that fields are displayed.
+ $this->drupalGet('node/add/' . $type);
+ $this->assertText($group_label, 'Group label displayed on add form');
+
+ $value1 = $this->randomName(20);
+ $value2 = $this->randomName(20);
+ $value3 = $this->randomName(20);
+ $value4 = $this->randomName(20);
+ $edit = array();
+ $edit['title'] = $this->randomName(20);
+ $edit['body'] = $this->randomName(20);
+ $edit[$group_name . '[0][' . $field1_name . '][value]'] = $value1;
+ $edit[$group_name . '[0][' . $field2_name . '][value]'] = $value2;
+
+ $this->drupalPost('node/add/'. $type, $edit, 'Add more values'); // Non-JS method.
+
+ $edit[$group_name . '[1][' . $field1_name . '][value]'] = $value3;
+ $edit[$group_name . '[1][' . $field2_name . '][value]'] = $value4;
+ // Save a node with multiple content in the fields.
+ $this->drupalPost(NULL, $edit, 'Save');
+ $node = node_load(array('title' => $edit['title']));
+ $this->drupalGet('node/'. $node->nid);
+
+ $this->assertText($value1, 'First value saved and displayed');
+ $this->assertText($value2, 'Second value saved and displayed');
+ $this->assertText($value3, 'Third value saved and displayed');
+ $this->assertText($value4, 'Fourth value saved and displayed');
+ }
+}