public function ManageDisplayTest::testCreateGroup in Field Group 8
Same name and namespace in other branches
- 8.3 tests/src/Functional/ManageDisplayTest.php \Drupal\Tests\field_group\Functional\ManageDisplayTest::testCreateGroup()
Test the creation a group on the article content type.
File
- tests/
src/ Functional/ ManageDisplayTest.php, line 58
Class
- ManageDisplayTest
- Tests for managing display of entities.
Namespace
Drupal\Tests\field_group\FunctionalCode
public function testCreateGroup() {
// Create random group name.
$group_label = $this
->randomString(8);
$group_name_input = Unicode::strtolower($this
->randomMachineName());
$group_name = 'group_' . $group_name_input;
$group_formatter = 'details';
// Setup new group.
$group = array(
'group_formatter' => $group_formatter,
'label' => $group_label,
);
$add_form_display = 'admin/structure/types/manage/' . $this->type . '/form-display/add-group';
$this
->drupalPostForm($add_form_display, $group, 'Save and continue');
$this
->assertSession()
->pageTextContains('Machine-readable name field is required.');
// Add required field to form.
$group['group_name'] = $group_name_input;
// Add new group on the 'Manage form display' page.
$this
->drupalPostForm($add_form_display, $group, 'Save and continue');
$this
->drupalPostForm(NULL, [], 'Create group');
$this
->assertSession()
->responseContains(t('New group %label successfully created.', array(
'%label' => $group_label,
)));
// Test if group is in the $groups array.
$this->group = field_group_load_field_group($group_name, 'node', $this->type, 'form', 'default');
$this
->assertNotNull($group, 'Group was loaded');
// Add new group on the 'Manage display' page.
$this
->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display/add-group', $group, 'Save and continue');
$this
->drupalPostForm(NULL, [], 'Create group');
$this
->assertSession()
->responseContains(t('New group %label successfully created.', array(
'%label' => $group_label,
)));
// Test if group is in the $groups array.
$loaded_group = field_group_load_field_group($group_name, 'node', $this->type, 'view', 'default');
$this
->assertNotNull($loaded_group, 'Group was loaded');
}