WorkspaceConcurrentEditingTest.php in Drupal 10
File
core/modules/workspaces/tests/src/Functional/WorkspaceConcurrentEditingTest.php
View source
<?php
namespace Drupal\Tests\workspaces\Functional;
use Drupal\Tests\BrowserTestBase;
class WorkspaceConcurrentEditingTest extends BrowserTestBase {
use WorkspaceTestUtilities;
protected static $modules = [
'block',
'node',
'workspaces',
];
protected $defaultTheme = 'stark';
public function testConcurrentEditing() {
$this
->createContentType([
'type' => 'test',
'label' => 'Test',
]);
$this
->setupWorkspaceSwitcherBlock();
$permissions = [
'create workspace',
'edit own workspace',
'view own workspace',
'create test content',
'edit own test content',
];
$mayer = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($mayer);
$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. As a result, your changes cannot be saved.');
$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());
$this
->switchToLive();
$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. As a result, your changes cannot be saved.');
$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
->publish();
$this
->switchToWorkspace($gravity);
$this
->drupalGet('/node/' . $test_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasField('title[0][value]'));
}
}