function WorkspaceTest::testWorkspaceManagePage

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

Tests the manage workspace page.

File

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

Class

WorkspaceTest
Test the workspace entity.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testWorkspaceManagePage() : void {
    $this->drupalCreateContentType([
        'type' => 'test',
        'label' => 'Test',
    ]);
    $permissions = [
        'administer taxonomy',
        'administer workspaces',
        'create test content',
        'delete any test content',
    ];
    $this->drupalLogin($this->drupalCreateUser($permissions));
    $this->setupWorkspaceSwitcherBlock();
    $assert_session = $this->assertSession();
    $vocabulary = $this->createVocabulary();
    $test_1 = $this->createWorkspaceThroughUi('Test 1', 'test_1');
    $test_2 = $this->createWorkspaceThroughUi('Test 2', 'test_2');
    $this->switchToWorkspace($test_1);
    // Check that the 'test_1' workspace doesn't contain any changes initially.
    $this->drupalGet($test_1->toUrl()
        ->toString());
    $assert_session->pageTextContains('This workspace has no changes.');
    // Check that the 'Switch to this workspace' action link is not displayed on
    // the manage page of the currently active workspace.
    $assert_session->linkNotExists('Switch to this workspace');
    $this->drupalGet($test_2->toUrl()
        ->toString());
    $assert_session->linkExists('Switch to this workspace');
    // Create some test content.
    $this->createNodeThroughUi('Node 1', 'test');
    $this->createNodeThroughUi('Node 2', 'test');
    $edit = [
        'name[0][value]' => 'Term 1',
    ];
    $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
    $this->submitForm($edit, 'Save');
    $this->drupalGet($test_1->toUrl()
        ->toString());
    $assert_session->pageTextContains('2 content items, 1 taxonomy term');
    $assert_session->linkExists('Node 1');
    $assert_session->linkExists('Node 2');
    $assert_session->linkExists('Term 1');
    // Create 50 more nodes to test the pagination.
    for ($i = 3; $i < 53; $i++) {
        $this->createNodeThroughUi('Node ' . $i, 'test');
    }
    $this->drupalGet($test_1->toUrl()
        ->toString());
    $assert_session->pageTextContains('52 content items');
    $assert_session->pageTextContains('1 taxonomy term');
    $assert_session->linkExists('Node 52');
    $assert_session->linkExists('Node 3');
    $assert_session->linkNotExists('Term 1');
    $this->drupalGet($test_1->toUrl()
        ->toString(), [
        'query' => [
            'page' => '1',
        ],
    ]);
    $assert_session->linkExists('Node 1');
    $assert_session->linkExists('Node 2');
    $assert_session->linkExists('Term 1');
}

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