View source
<?php
namespace Drupal\Tests\workspace\Functional;
use Drupal\simpletest\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
class WorkspaceBypassTest extends BrowserTestBase {
use WorkspaceTestUtilities;
use BlockCreationTrait {
placeBlock as drupalPlaceBlock;
}
public static $modules = [
'node',
'user',
'block',
'workspace',
'multiversion',
];
public function testBypassSpecificWorkspace() {
$permissions = [
'create_workspace',
'edit_own_workspace',
'view_own_workspace',
];
$this
->createNodeType('Test', 'test');
$this
->setupWorkspaceSwitcherBlock();
$ditka = $this
->drupalCreateUser(array_merge($permissions, [
'create test content',
]));
$this
->drupalLogin($ditka);
$vanilla_node = $this
->createNodeThroughUI('Vanilla node', 'test');
$bears = $this
->createWorkspaceThroughUI('Bears', 'bears');
$live = $this
->getOneEntityByLabel('workspace', 'Live');
$rm = \Drupal::service('workspace.replicator_manager');
$rm
->replicate($this
->getPointerToWorkspace($live), $this
->getPointerToWorkspace($bears));
\Drupal::service('cron')
->run();
$this
->switchToWorkspace($bears);
$ditka_bears_node = $this
->createNodeThroughUI('Ditka Bears node', 'test');
$ditka_bears_node_id = $ditka_bears_node
->id();
$lombardi = $this
->drupalCreateUser(array_merge($permissions, [
'view_workspace_' . $bears
->id(),
'bypass_entity_access_workspace_' . $bears
->id(),
]));
$this
->drupalLogin($lombardi);
$this
->switchToWorkspace($bears);
$this
->drupalGet('/node/' . $ditka_bears_node_id . '/edit');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$bears_vanilla_node = $this
->getOneEntityByLabel('node', 'Vanilla node');
$this
->drupalGet('/node/' . $bears_vanilla_node
->id() . '/edit');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$lombardi_bears_node = $this
->createNodeThroughUI('Lombardi Bears node', 'test');
$lombardi_bears_node_id = $lombardi_bears_node
->id();
$this
->drupalLogin($ditka);
$this
->switchToWorkspace($bears);
$this
->drupalGet('/node/' . $lombardi_bears_node_id . '/edit');
$session = $this
->getSession();
$this
->assertEquals(403, $session
->getStatusCode());
$belichick = $this
->drupalCreateUser(array_merge($permissions, [
'view_workspace_' . $bears
->id(),
]));
$this
->drupalLogin($belichick);
$this
->switchToWorkspace($bears);
$this
->drupalGet('/node/' . $ditka_bears_node_id . '/edit');
$session = $this
->getSession();
$this
->assertEquals(403, $session
->getStatusCode());
$this
->drupalGet('/node/' . $bears_vanilla_node
->id() . '/edit');
$session = $this
->getSession();
$this
->assertEquals(403, $session
->getStatusCode());
}
public function testBypassOwnWorkspace() {
$permissions = [
'create_workspace',
'edit_own_workspace',
'view_own_workspace',
'bypass_entity_access_own_workspace',
];
$this
->createNodeType('Test', 'test');
$this
->setupWorkspaceSwitcherBlock();
$ditka = $this
->drupalCreateUser(array_merge($permissions, [
'create test content',
]));
$this
->drupalLogin($ditka);
$vanilla_node = $this
->createNodeThroughUI('Vanilla node', 'test');
$bears = $this
->createWorkspaceThroughUI('Bears', 'bears');
$live = $this
->getOneEntityByLabel('workspace', 'Live');
$rm = \Drupal::service('workspace.replicator_manager');
$rm
->replicate($this
->getPointerToWorkspace($live), $this
->getPointerToWorkspace($bears));
\Drupal::service('cron')
->run();
$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');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$bears_vanilla_node = $this
->getOneEntityByLabel('node', 'Vanilla node');
$this
->drupalGet('/node/' . $bears_vanilla_node
->id() . '/edit');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$lombardi = $this
->drupalCreateUser(array_merge($permissions, [
'view_workspace_' . $bears
->id(),
]));
$this
->drupalLogin($lombardi);
$this
->switchToWorkspace($bears);
$this
->drupalGet('/node/' . $ditka_bears_node_id . '/edit');
$session = $this
->getSession();
$this
->assertEquals(403, $session
->getStatusCode());
$this
->drupalGet('/node/' . $bears_vanilla_node
->id() . '/edit');
$session = $this
->getSession();
$this
->assertEquals(403, $session
->getStatusCode());
}
}