3 namespace Drupal\Tests\workspaces\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\workspaces\Entity\Workspace;
9 * Tests concurrent edits in different workspaces.
13 class WorkspaceConcurrentEditingTest extends BrowserTestBase {
15 use WorkspaceTestUtilities;
20 public static $modules = ['block', 'node', 'workspaces'];
23 * Test switching workspace via the switcher block and admin page.
25 public function testSwitchingWorkspaces() {
30 'bypass entity access own workspace',
33 $mayer = $this->drupalCreateUser($permissions);
34 $this->drupalLogin($mayer);
35 $this->setupWorkspaceSwitcherBlock();
37 // Create a test node.
38 $this->createContentType(['type' => 'test', 'label' => 'Test']);
39 $test_node = $this->createNodeThroughUi('Test node', 'test');
41 // Check that the user can edit the node.
42 $page = $this->getSession()->getPage();
43 $page->hasField('title[0][value]');
45 // Create two workspaces.
46 $vultures = $this->createWorkspaceThroughUi('Vultures', 'vultures');
47 $gravity = $this->createWorkspaceThroughUi('Gravity', 'gravity');
49 // Edit the node in workspace 'vultures'.
50 $this->switchToWorkspace($vultures);
51 $this->drupalGet('/node/' . $test_node->id() . '/edit');
52 $page = $this->getSession()->getPage();
53 $page->fillField('Title', 'Test node - override');
54 $page->findButton('Save')->click();
56 // Check that the user can still edit the node in the same workspace.
57 $this->drupalGet('/node/' . $test_node->id() . '/edit');
58 $page = $this->getSession()->getPage();
59 $this->assertTrue($page->hasField('title[0][value]'));
61 // Switch to a different workspace and check that the user can not edit the
63 $this->switchToWorkspace($gravity);
64 $this->drupalGet('/node/' . $test_node->id() . '/edit');
65 $page = $this->getSession()->getPage();
66 $this->assertFalse($page->hasField('title[0][value]'));
67 $page->hasContent('The content is being edited in the Vultures workspace.');
69 // Check that the node fails validation for API calls.
70 $violations = $test_node->validate();
71 $this->assertCount(1, $violations);
72 $this->assertEquals('The content is being edited in the <em class="placeholder">Vultures</em> workspace. As a result, your changes cannot be saved.', $violations->get(0)->getMessage());
74 // Switch to the Live workspace and check that the user still can not edit
76 $live = Workspace::load('live');
77 $this->switchToWorkspace($live);
78 $this->drupalGet('/node/' . $test_node->id() . '/edit');
79 $page = $this->getSession()->getPage();
80 $this->assertFalse($page->hasField('title[0][value]'));
81 $page->hasContent('The content is being edited in the Vultures workspace.');
83 // Check that the node fails validation for API calls.
84 $violations = $test_node->validate();
85 $this->assertCount(1, $violations);
86 $this->assertEquals('The content is being edited in the <em class="placeholder">Vultures</em> workspace. As a result, your changes cannot be saved.', $violations->get(0)->getMessage());
88 // Deploy the changes from the 'Vultures' workspace and check that the node
89 // can be edited again in other workspaces.
91 $this->switchToWorkspace($gravity);
92 $this->drupalGet('/node/' . $test_node->id() . '/edit');
93 $page = $this->getSession()->getPage();
94 $this->assertTrue($page->hasField('title[0][value]'));