class WorkspaceViewTest
Same name and namespace in other branches
- 11.x core/modules/workspaces/tests/src/Functional/WorkspaceViewTest.php \Drupal\Tests\workspaces\Functional\WorkspaceViewTest
- 10 core/modules/workspaces/tests/src/Functional/WorkspaceViewTest.php \Drupal\Tests\workspaces\Functional\WorkspaceViewTest
- 8.9.x core/modules/workspaces/tests/src/Functional/WorkspaceViewTest.php \Drupal\Tests\workspaces\Functional\WorkspaceViewTest
Tests permission controls on workspaces.
@group workspaces
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\workspaces\Functional\WorkspaceViewTest uses \Drupal\Tests\workspaces\Functional\WorkspaceTestUtilities extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of WorkspaceViewTest
File
-
core/
modules/ workspaces/ tests/ src/ Functional/ WorkspaceViewTest.php, line 13
Namespace
Drupal\Tests\workspaces\FunctionalView source
class WorkspaceViewTest extends BrowserTestBase {
use WorkspaceTestUtilities;
/**
* {@inheritdoc}
*/
protected static $modules = [
'workspaces',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Verifies that a user can view their own workspace.
*/
public function testViewOwnWorkspace() {
$permissions = [
'access administration pages',
'administer site configuration',
'create workspace',
'edit own workspace',
'view own workspace',
];
$editor1 = $this->drupalCreateUser($permissions);
// Login as a limited-access user and create a workspace.
$this->drupalLogin($editor1);
$this->createWorkspaceThroughUi('Bears', 'bears');
$bears = Workspace::load('bears');
// Now login as a different user and create a workspace.
$editor2 = $this->drupalCreateUser($permissions);
$this->drupalLogin($editor2);
$this->createWorkspaceThroughUi('Packers', 'packers');
$packers = Workspace::load('packers');
// Load the activate form for the Bears workspace. It should fail because
// the workspace belongs to someone else.
$this->drupalGet("admin/config/workflow/workspaces/manage/{$bears->id()}/activate");
$this->assertSession()
->statusCodeEquals(403);
// But editor 2 should be able to activate the Packers workspace.
$this->drupalGet("admin/config/workflow/workspaces/manage/{$packers->id()}/activate");
$this->assertSession()
->statusCodeEquals(200);
}
/**
* Verifies that a user can view any workspace.
*/
public function testViewAnyWorkspace() {
$permissions = [
'access administration pages',
'administer site configuration',
'create workspace',
'edit own workspace',
'view any workspace',
];
$editor1 = $this->drupalCreateUser($permissions);
// Login as a limited-access user and create a workspace.
$this->drupalLogin($editor1);
$this->createWorkspaceThroughUi('Bears', 'bears');
$bears = Workspace::load('bears');
// Now login as a different user and create a workspace.
$editor2 = $this->drupalCreateUser($permissions);
$this->drupalLogin($editor2);
$this->createWorkspaceThroughUi('Packers', 'packers');
$packers = Workspace::load('packers');
// Load the activate form for the Bears workspace. This user should be
// able to see both workspaces because of the "view any" permission.
$this->drupalGet("admin/config/workflow/workspaces/manage/{$bears->id()}/activate");
$this->assertSession()
->statusCodeEquals(200);
// But editor 2 should be able to activate the Packers workspace.
$this->drupalGet("admin/config/workflow/workspaces/manage/{$packers->id()}/activate");
$this->assertSession()
->statusCodeEquals(200);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.