You are here

public function WorkspaceTest::testWorkspaceFieldUi in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workspaces/tests/src/Functional/WorkspaceTest.php \Drupal\Tests\workspaces\Functional\WorkspaceTest::testWorkspaceFieldUi()
  2. 9 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);
}