function WorkspaceTest::testWorkspaceList

Same name and namespace in other branches
  1. 9 core/modules/workspaces/tests/src/Functional/WorkspaceTest.php \Drupal\Tests\workspaces\Functional\WorkspaceTest::testWorkspaceList()
  2. 10 core/modules/workspaces/tests/src/Functional/WorkspaceTest.php \Drupal\Tests\workspaces\Functional\WorkspaceTest::testWorkspaceList()

Tests the Workspaces listing UI.

File

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

Class

WorkspaceTest
Test the workspace entity.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testWorkspaceList() : void {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    // Login and create a workspace.
    $this->drupalLogin($this->editor1);
    $this->createWorkspaceThroughUi('Summer event', 'summer_event');
    // Check that Live is the current active workspace.
    $this->drupalGet('/admin/config/workflow/workspaces');
    $this->assertSession()
        ->statusCodeEquals(200);
    $active_workspace_row = $page->find('css', '.active-workspace');
    $this->assertTrue($active_workspace_row->hasClass('active-workspace--default'));
    $this->assertEquals('Live', $active_workspace_row->find('css', 'td:first-of-type')
        ->getText());
    // The 'Switch to Live' operation is not shown when 'Live' is the active
    // workspace.
    $assert_session->linkNotExists('Switch to Live');
    // Switch to another workspace and check that it has been marked as active.
    $page->clickLink('Switch to Summer event');
    $page->pressButton('Confirm');
    $active_workspace_row = $page->find('css', '.active-workspace');
    $this->assertTrue($active_workspace_row->hasClass('active-workspace--not-default'));
    $this->assertEquals('Summer event', $active_workspace_row->find('css', 'td:first-of-type')
        ->getText());
    // 'Live' is no longer the active workspace, so it's 'Switch to Live'
    // operation should be visible now.
    $assert_session->linkExists('Switch to Live');
    // Delete any of the workspace owners and visit workspaces listing.
    $this->drupalLogin($this->editor2);
    user_cancel([], $this->editor1
        ->id(), 'user_cancel_reassign');
    $user = \Drupal::service('entity_type.manager')->getStorage('user')
        ->load($this->editor1
        ->id());
    $user->delete();
    $this->drupalGet('/admin/config/workflow/workspaces');
    $this->assertSession()
        ->pageTextContains('Summer event');
    $summer_event_workspace_row = $page->find('css', 'table tbody tr:nth-of-type(3)');
    $this->assertEquals('N/A', $summer_event_workspace_row->find('css', 'td:nth-of-type(2)')
        ->getText());
}

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