3 namespace Drupal\Tests\workspaces\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\workspaces\Entity\Workspace;
9 * Tests permission controls on workspaces.
13 class WorkspaceViewTest extends BrowserTestBase {
15 use WorkspaceTestUtilities;
20 public static $modules = ['workspaces'];
23 * Verifies that a user can view their own workspace.
25 public function testViewOwnWorkspace() {
27 'access administration pages',
28 'administer site configuration',
34 $editor1 = $this->drupalCreateUser($permissions);
36 // Login as a limited-access user and create a workspace.
37 $this->drupalLogin($editor1);
38 $this->createWorkspaceThroughUi('Bears', 'bears');
40 $bears = Workspace::load('bears');
42 // Now login as a different user and create a workspace.
43 $editor2 = $this->drupalCreateUser($permissions);
45 $this->drupalLogin($editor2);
46 $this->createWorkspaceThroughUi('Packers', 'packers');
48 $packers = Workspace::load('packers');
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);
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);
61 * Verifies that a user can view any workspace.
63 public function testViewAnyWorkspace() {
65 'access administration pages',
66 'administer site configuration',
72 $editor1 = $this->drupalCreateUser($permissions);
74 // Login as a limited-access user and create a workspace.
75 $this->drupalLogin($editor1);
77 $this->createWorkspaceThroughUi('Bears', 'bears');
79 $bears = Workspace::load('bears');
81 // Now login as a different user and create a workspace.
82 $editor2 = $this->drupalCreateUser($permissions);
84 $this->drupalLogin($editor2);
85 $this->createWorkspaceThroughUi('Packers', 'packers');
87 $packers = Workspace::load('packers');
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");
93 $this->assertSession()->statusCodeEquals(200);
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);