View source
<?php
module_load_include('test', 'content', 'tests/content.crud');
class FieldgroupCRUDTest extends ContentCrudTestCase {
var $last_group = NULL;
var $next_group_n = 1;
function setUp() {
$args = func_get_args();
$modules = array_merge(array(
'fieldgroup',
), $args);
call_user_func_array(array(
'parent',
'setUp',
), $modules);
}
function createGroup($settings, $fields = array(), $content_type = 0) {
if (is_numeric($content_type) && isset($this->content_types[$content_type])) {
$content_type = $this->content_types[$content_type];
}
$type_name = $content_type->type;
$group_name = 'simpletest_g' . $this->next_group_n++;
$defaults = array(
'group_name' => $group_name,
'group_type' => 'standard',
'parent' => '',
'label' => $group_name,
'weight' => -3,
'settings' => array(
'form' => array(
'style' => 'fieldset',
'description' => '',
),
'display' => array(
'weight' => -3,
'parent' => '',
'label' => 'above',
'description' => '',
'teaser' => array(
'format' => 'fieldset',
'exclude' => 0,
),
'full' => array(
'format' => 'fieldset',
'exclude' => 0,
),
),
),
);
$group = $settings + $defaults;
fieldgroup_save_group($type_name, $group);
$this->last_group = $group_name;
foreach ($fields as $field_name) {
$form_values = array(
'field_name' => $field_name,
'group' => $group_name,
'type_name' => $type_name,
);
fieldgroup_update_fields($form_values);
}
cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
return $this->last_group;
}
}
class testFieldgroupFields extends FieldgroupCRUDTest {
public static function getInfo() {
return array(
'name' => t('Fieldgroups'),
'description' => t('Test creating fields in fieldgroups.'),
'group' => t('CCK'),
);
}
function setUp() {
parent::setUp();
$this
->loginWithPermissions();
$this
->acquireContentTypes(1);
}
function testFieldgroup() {
$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,
);
$settings = array(
'type_name' => $type_name,
'group_type' => 'standard',
'parent' => '',
);
$group_name = $this
->createGroup($settings, $fields);
$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');
$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');
$settings = array(
'type_name' => $type_name,
'group_type' => 'standard',
'parent' => '',
);
$group_name2 = $this
->createGroup($settings, array());
$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');
$groups = fieldgroup_groups($type->name);
$settings = $groups[$group_name];
$settings['parent'] = $group_name2;
$group_name = $this
->createGroup($settings, $fields);
cache_clear_all('content:', content_cache_tablename(), TRUE);
$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');
}
}