WorkspaceConcurrentEditingTest.php in Workspace 8.2
File
tests/src/Functional/WorkspaceConcurrentEditingTest.php
View source
<?php
namespace Drupal\Tests\workspace\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\workspace\Entity\Workspace;
class WorkspaceConcurrentEditingTest extends BrowserTestBase {
use WorkspaceTestUtilities;
public static $modules = [
'block',
'node',
'workspace',
];
public function testSwitchingWorkspaces() {
$permissions = [
'create workspace',
'edit own workspace',
'view own workspace',
'bypass entity access own workspace',
];
$mayer = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($mayer);
$this
->setupWorkspaceSwitcherBlock();
$this
->createContentType([
'type' => 'test',
'label' => 'Test',
]);
$test_node = $this
->createNodeThroughUi('Test node', 'test');
$page = $this
->getSession()
->getPage();
$page
->hasField('title[0][value]');
$vultures = $this
->createWorkspaceThroughUi('Vultures', 'vultures');
$gravity = $this
->createWorkspaceThroughUi('Gravity', 'gravity');
$this
->switchToWorkspace($vultures);
$this
->drupalGet('/node/' . $test_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$page
->fillField('Title', 'Test node - override');
$page
->findButton('Save')
->click();
$this
->drupalGet('/node/' . $test_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasField('title[0][value]'));
$this
->switchToWorkspace($gravity);
$this
->drupalGet('/node/' . $test_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertFalse($page
->hasField('title[0][value]'));
$page
->hasContent('The content is being edited in the Vultures workspace.');
$violations = $test_node
->validate();
$this
->assertCount(1, $violations);
$this
->assertEquals('The content is being edited in the <em class="placeholder">Vultures</em> workspace. As a result, your changes cannot be saved.', $violations
->get(0)
->getMessage());
$live = Workspace::load('live');
$this
->switchToWorkspace($live);
$this
->drupalGet('/node/' . $test_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertFalse($page
->hasField('title[0][value]'));
$page
->hasContent('The content is being edited in the Vultures workspace.');
$violations = $test_node
->validate();
$this
->assertCount(1, $violations);
$this
->assertEquals('The content is being edited in the <em class="placeholder">Vultures</em> workspace. As a result, your changes cannot be saved.', $violations
->get(0)
->getMessage());
$vultures
->getRepositoryHandler()
->push();
$this
->switchToWorkspace($gravity);
$this
->drupalGet('/node/' . $test_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasField('title[0][value]'));
}
}