WorkspaceBypassTest.php in Drupal 10
File
core/modules/workspaces/tests/src/Functional/WorkspaceBypassTest.php
View source
<?php
namespace Drupal\Tests\workspaces\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
class WorkspaceBypassTest extends BrowserTestBase {
use WorkspaceTestUtilities;
use ContentTypeCreationTrait;
protected static $modules = [
'node',
'user',
'block',
'workspaces',
];
protected $defaultTheme = 'stark';
public function testBypassOwnWorkspace() {
$permissions = [
'create workspace',
'edit own workspace',
'view own workspace',
'bypass entity access own workspace',
];
$this
->createContentType([
'type' => 'test',
'label' => 'Test',
]);
$this
->setupWorkspaceSwitcherBlock();
$ditka = $this
->drupalCreateUser(array_merge($permissions, [
'create test content',
]));
$this
->drupalLogin($ditka);
$bears = $this
->createWorkspaceThroughUi('Bears', 'bears');
$this
->switchToWorkspace($bears);
$ditka_bears_node = $this
->createNodeThroughUi('Ditka Bears node', 'test');
$ditka_bears_node_id = $ditka_bears_node
->id();
$this
->drupalGet('/node/' . $ditka_bears_node_id . '/edit');
$this
->assertSession()
->statusCodeEquals(200);
$lombardi = $this
->drupalCreateUser(array_merge($permissions, [
'view any workspace',
]));
$this
->drupalLogin($lombardi);
$this
->switchToWorkspace($bears);
$this
->drupalGet('/node/' . $ditka_bears_node_id . '/edit');
$this
->assertSession()
->statusCodeEquals(403);
}
}