public function ContentLockBlockTest::testContentLockBlock in Content locking (anti-concurrent editing) 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/ContentLockBlockTest.php \Drupal\Tests\content_lock\Functional\ContentLockBlockTest::testContentLockBlock()
Test simultaneous edit on block.
File
- tests/
src/ Functional/ ContentLockBlockTest.php, line 79
Class
- ContentLockBlockTest
- Block tests.
Namespace
Drupal\Tests\content_lock\FunctionalCode
public function testContentLockBlock() {
// Create block.
$this
->createBlockContentType('basic', TRUE);
$block1 = $this
->createBlockContent('Block 1');
$admin = $this
->drupalCreateUser([
'administer blocks',
'administer content lock',
]);
$user1 = $this
->drupalCreateUser([
'administer blocks',
'access content',
]);
$user2 = $this
->drupalCreateUser([
'administer blocks',
'break content lock',
]);
// We protect the bundle created.
$this
->drupalLogin($admin);
$edit = [
'block_content[bundles][basic]' => 1,
];
$this
->drupalPostForm('admin/config/content/content_lock', $edit, t('Save configuration'));
// We lock block1.
$this
->drupalLogin($user1);
// Edit a node without saving.
$this
->drupalGet("block/{$block1->id()}");
$assert_session = $this
->assertSession();
$assert_session
->pageTextContains(t('This content is now locked against simultaneous editing.'));
// Other user can not edit block1.
$this
->drupalLogin($user2);
$this
->drupalGet("block/{$block1->id()}");
$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'));
$disabled_button = $this
->xpath('//input[@id=:id and @disabled="disabled"]', [
':id' => 'edit-submit',
]);
$this
->assertTrue($disabled_button, t('The form cannot be submitted.'));
// We save block1 and unlock it.
$this
->drupalLogin($user1);
$this
->drupalGet("block/{$block1->id()}");
$assert_session
->pageTextContains(t('This content is now locked by you against simultaneous editing.'));
$this
->drupalPostForm('/block/' . $block1
->id(), [], t('Save'));
// We lock block1 with user2.
$this
->drupalLogin($user2);
// Edit a node without saving.
$this
->drupalGet("block/{$block1->id()}");
$assert_session
->pageTextContains(t('This content is now locked against simultaneous editing.'));
// Other user can not edit block1.
$this
->drupalLogin($user1);
$this
->drupalGet("block/{$block1->id()}");
$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'));
$disabled_button = $this
->xpath('//input[@id=:id and @disabled="disabled"]', [
':id' => 'edit-submit',
]);
$this
->assertTrue($disabled_button, t('The form cannot be submitted.'));
// We unlock block1 with user2.
$this
->drupalLogin($user2);
// Edit a node without saving.
$this
->drupalGet("block/{$block1->id()}");
$assert_session
->pageTextContains(t('This content is now locked by you against simultaneous editing.'));
$this
->drupalPostForm('/block/' . $block1
->id(), [], t('Save'));
$assert_session
->pageTextContains(t('has been updated.'));
}