Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / workspaces / tests / src / Functional / WorkspaceBypassTest.php
1 <?php
2
3 namespace Drupal\Tests\workspaces\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
7
8 /**
9  * Tests access bypass permission controls on workspaces.
10  *
11  * @group workspaces
12  */
13 class WorkspaceBypassTest extends BrowserTestBase {
14
15   use WorkspaceTestUtilities;
16   use ContentTypeCreationTrait;
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = ['node', 'user', 'block', 'workspaces'];
22
23   /**
24    * Verifies that a user can edit anything in a workspace they own.
25    */
26   public function testBypassOwnWorkspace() {
27     $permissions = [
28       'create workspace',
29       'edit own workspace',
30       'view own workspace',
31       'bypass entity access own workspace',
32     ];
33
34     $this->createContentType(['type' => 'test', 'label' => 'Test']);
35     $this->setupWorkspaceSwitcherBlock();
36
37     $ditka = $this->drupalCreateUser(array_merge($permissions, ['create test content']));
38
39     // Login as a limited-access user and create a workspace.
40     $this->drupalLogin($ditka);
41     $bears = $this->createWorkspaceThroughUi('Bears', 'bears');
42     $this->switchToWorkspace($bears);
43
44     // Now create a node in the Bears workspace, as the owner of that workspace.
45     $ditka_bears_node = $this->createNodeThroughUi('Ditka Bears node', 'test');
46     $ditka_bears_node_id = $ditka_bears_node->id();
47
48     // Editing both nodes should be possible.
49     $this->drupalGet('/node/' . $ditka_bears_node_id . '/edit');
50     $this->assertSession()->statusCodeEquals(200);
51
52     // Create a new user that should be able to edit anything in the Bears
53     // workspace.
54     $lombardi = $this->drupalCreateUser(array_merge($permissions, ['view any workspace']));
55     $this->drupalLogin($lombardi);
56     $this->switchToWorkspace($bears);
57
58     // Because editor 2 has the bypass permission, he should be able to create
59     // and edit any node.
60     $this->drupalGet('/node/' . $ditka_bears_node_id . '/edit');
61     $this->assertSession()->statusCodeEquals(403);
62   }
63
64 }