You are here

public function WorkspaceTest::testWorkspaceCreation in Workspace 8

Tests the creation of workspaces.

File

tests/src/Functional/WorkspaceTest.php, line 56

Class

WorkspaceTest
Test the workspace entity.

Namespace

Drupal\Tests\workspace\Functional

Code

public function testWorkspaceCreation() {
  $web_assert = $this
    ->assertSession();

  // Create two workspaces.
  $workspace_1 = $this
    ->createWorkspaceThroughUI('Workspace 1', 'workspace_1');
  $workspace_2 = $this
    ->createWorkspaceThroughUI('Workspace 2', 'workspace_2');

  // Check they appear on the listing.
  $this
    ->drupalGet('/admin/structure/workspace');
  $web_assert
    ->pageTextContains($workspace_1
    ->label());
  $web_assert
    ->pageTextContains($workspace_2
    ->label());

  // Check they both appear as possible upstreams for each other.
  $this
    ->drupalGet($workspace_1
    ->toUrl('edit-form')
    ->toString());
  $web_assert
    ->fieldNotExists($workspace_1
    ->label());
  $web_assert
    ->fieldExists($workspace_2
    ->label());
  $this
    ->drupalGet($workspace_2
    ->toUrl('edit-form')
    ->toString());
  $web_assert
    ->fieldExists($workspace_1
    ->label());
  $web_assert
    ->fieldNotExists($workspace_2
    ->label());

  // Unpublish the first workspace.
  $workspace_1
    ->setUnpublished()
    ->save();

  // Check it doesn't appear in the listing anymore.
  $this
    ->drupalGet('/admin/structure/workspace');
  $web_assert
    ->pageTextNotContains($workspace_1
    ->label());
  $web_assert
    ->pageTextContains($workspace_2
    ->label());

  // Check it doesn't appear as a possible upstream anymore.
  $this
    ->drupalGet($workspace_1
    ->toUrl('edit-form')
    ->toString());
  $web_assert
    ->fieldNotExists($workspace_1
    ->label());
  $web_assert
    ->fieldExists($workspace_2
    ->label());
  $this
    ->drupalGet($workspace_2
    ->toUrl('edit-form')
    ->toString());
  $web_assert
    ->fieldNotExists($workspace_1
    ->label());
  $web_assert
    ->fieldNotExists($workspace_2
    ->label());
}