View source
<?php
namespace Drupal\Tests\content_lock\Functional;
use Drupal\Tests\BrowserTestBase;
class ContentLockNodeTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'node',
'content_lock',
];
public function testContentLockNode() {
$this
->drupalCreateContentType([
'type' => 'article',
]);
$article = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'Article 1',
]);
$admin = $this
->drupalCreateUser([
'edit any article content',
'delete any article content',
'administer nodes',
'administer content types',
'administer content lock',
]);
$user1 = $this
->drupalCreateUser([
'create article content',
'edit any article content',
'delete any article content',
'access content',
]);
$user2 = $this
->drupalCreateUser([
'create article content',
'edit any article content',
'delete any article content',
'access content',
'break content lock',
]);
$this
->drupalLogin($admin);
$edit = [
'node[bundles][article]' => 1,
];
$this
->drupalPostForm('admin/config/content/content_lock', $edit, t('Save configuration'));
$this
->drupalLogin($user1);
$this
->drupalGet("node/{$article->id()}/edit");
$assert_session = $this
->assertSession();
$assert_session
->pageTextContains(t('This content is now locked against simultaneous editing.'));
$this
->drupalLogin($user2);
$this
->drupalGet("node/{$article->id()}/edit");
$assert_session
->pageTextContains(t('This content is being edited by the user @name and is therefore locked to prevent other users changes.', [
'@name' => $user1
->getDisplayName(),
]));
$assert_session
->linkExists(t('Break lock'));
$submit = $assert_session
->buttonExists('edit-submit');
$this
->assertTrue($submit
->hasAttribute('disabled'));
$textarea = $assert_session
->elementExists('css', 'textarea#edit-body-0-value');
$this
->assertTrue($textarea
->hasAttribute('disabled'));
$this
->drupalLogin($user1);
$this
->drupalGet("node/{$article->id()}/edit");
$assert_session
->pageTextContains(t('This content is now locked by you against simultaneous editing.'));
$this
->drupalPostForm('/node/' . $article
->id() . '/edit', [], t('Save'));
$this
->drupalLogin($user2);
$this
->drupalGet("node/{$article->id()}/edit");
$assert_session
->pageTextContains(t('This content is now locked against simultaneous editing.'));
$this
->drupalLogin($user1);
$this
->drupalGet("node/{$article->id()}/edit");
$assert_session
->pageTextContains(t('This content is being edited by the user @name and is therefore locked to prevent other users changes.', [
'@name' => $user2
->getDisplayName(),
]));
$assert_session
->linkNotExists(t('Break lock'));
$submit = $assert_session
->buttonExists('edit-submit');
$this
->assertTrue($submit
->hasAttribute('disabled'));
$this
->drupalLogin($user2);
$this
->drupalGet("node/{$article->id()}/edit");
$assert_session
->pageTextContains(t('This content is now locked by you against simultaneous editing.'));
$this
->drupalPostForm('/node/' . $article
->id() . '/edit', [], t('Save'));
$assert_session
->pageTextContains(t('updated.'));
}
}