Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / workspaces / tests / src / Functional / WorkspaceViewTest.php
1 <?php
2
3 namespace Drupal\Tests\workspaces\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\workspaces\Entity\Workspace;
7
8 /**
9  * Tests permission controls on workspaces.
10  *
11  * @group workspaces
12  */
13 class WorkspaceViewTest extends BrowserTestBase {
14
15   use WorkspaceTestUtilities;
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['workspaces'];
21
22   /**
23    * Verifies that a user can view their own workspace.
24    */
25   public function testViewOwnWorkspace() {
26     $permissions = [
27       'access administration pages',
28       'administer site configuration',
29       'create workspace',
30       'edit own workspace',
31       'view own workspace',
32     ];
33
34     $editor1 = $this->drupalCreateUser($permissions);
35
36     // Login as a limited-access user and create a workspace.
37     $this->drupalLogin($editor1);
38     $this->createWorkspaceThroughUi('Bears', 'bears');
39
40     $bears = Workspace::load('bears');
41
42     // Now login as a different user and create a workspace.
43     $editor2 = $this->drupalCreateUser($permissions);
44
45     $this->drupalLogin($editor2);
46     $this->createWorkspaceThroughUi('Packers', 'packers');
47
48     $packers = Workspace::load('packers');
49
50     // Load the activate form for the Bears workspace. It should fail because
51     // the workspace belongs to someone else.
52     $this->drupalGet("admin/config/workflow/workspaces/manage/{$bears->id()}/activate");
53     $this->assertSession()->statusCodeEquals(403);
54
55     // But editor 2 should be able to activate the Packers workspace.
56     $this->drupalGet("admin/config/workflow/workspaces/manage/{$packers->id()}/activate");
57     $this->assertSession()->statusCodeEquals(200);
58   }
59
60   /**
61    * Verifies that a user can view any workspace.
62    */
63   public function testViewAnyWorkspace() {
64     $permissions = [
65       'access administration pages',
66       'administer site configuration',
67       'create workspace',
68       'edit own workspace',
69       'view any workspace',
70     ];
71
72     $editor1 = $this->drupalCreateUser($permissions);
73
74     // Login as a limited-access user and create a workspace.
75     $this->drupalLogin($editor1);
76
77     $this->createWorkspaceThroughUi('Bears', 'bears');
78
79     $bears = Workspace::load('bears');
80
81     // Now login as a different user and create a workspace.
82     $editor2 = $this->drupalCreateUser($permissions);
83
84     $this->drupalLogin($editor2);
85     $this->createWorkspaceThroughUi('Packers', 'packers');
86
87     $packers = Workspace::load('packers');
88
89     // Load the activate form for the Bears workspace. This user should be
90     // able to see both workspaces because of the "view any" permission.
91     $this->drupalGet("admin/config/workflow/workspaces/manage/{$bears->id()}/activate");
92
93     $this->assertSession()->statusCodeEquals(200);
94
95     // But editor 2 should be able to activate the Packers workspace.
96     $this->drupalGet("admin/config/workflow/workspaces/manage/{$packers->id()}/activate");
97     $this->assertSession()->statusCodeEquals(200);
98   }
99
100 }