function WorkspaceTest::testWorkspaceFieldUi

Same name in other branches
  1. 9 core/modules/workspaces/tests/src/Functional/WorkspaceTest.php \Drupal\Tests\workspaces\Functional\WorkspaceTest::testWorkspaceFieldUi()
  2. 10 core/modules/workspaces/tests/src/Functional/WorkspaceTest.php \Drupal\Tests\workspaces\Functional\WorkspaceTest::testWorkspaceFieldUi()
  3. 11.x core/modules/workspaces/tests/src/Functional/WorkspaceTest.php \Drupal\Tests\workspaces\Functional\WorkspaceTest::testWorkspaceFieldUi()

Tests adding new fields to workspace entities.

File

core/modules/workspaces/tests/src/Functional/WorkspaceTest.php, line 152

Class

WorkspaceTest
Test the workspace entity.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testWorkspaceFieldUi() {
    $user = $this->drupalCreateUser([
        'administer workspaces',
        'access administration pages',
        'administer site configuration',
        'administer workspace fields',
        'administer workspace display',
        'administer workspace form display',
    ]);
    $this->drupalLogin($user);
    $this->drupalGet('admin/config/workflow/workspaces/fields');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Create a new filed.
    $field_name = mb_strtolower($this->randomMachineName());
    $field_label = $this->randomMachineName();
    $edit = [
        'new_storage_type' => 'string',
        'label' => $field_label,
        'field_name' => $field_name,
    ];
    $this->drupalPostForm("admin/config/workflow/workspaces/fields/add-field", $edit, 'Save and continue');
    $page = $this->getSession()
        ->getPage();
    $page->pressButton('Save field settings');
    $page->pressButton('Save settings');
    // Check that the field is displayed on the manage form display page.
    $this->drupalGet('admin/config/workflow/workspaces/form-display');
    $this->assertText($field_label);
    // Check that the field is displayed on the manage display page.
    $this->drupalGet('admin/config/workflow/workspaces/display');
    $this->assertText($field_label);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.