function WorkspaceTest::testWorkspaceFieldUi

Same name and namespace in other branches
  1. 8.9.x 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 211

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->drupalGet("admin/config/workflow/workspaces/fields/add-field");
    $this->submitForm($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->assertSession()
        ->pageTextContains($field_label);
    // Check that the field is displayed on the manage display page.
    $this->drupalGet('admin/config/workflow/workspaces/display');
    $this->assertSession()
        ->pageTextContains($field_label);
}

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