public function ContentLockModesTest::testMultipleFormModes in Content locking (anti-concurrent editing) 8.2
Same name and namespace in other branches
- 8 tests/src/Functional/ContentLockModesTest.php \Drupal\Tests\content_lock\Functional\ContentLockModesTest::testMultipleFormModes()
Test that all forms are getting locked.
File
- tests/
src/ Functional/ ContentLockModesTest.php, line 112
Class
- ContentLockModesTest
- Content lock modes tests.
Namespace
Drupal\Tests\content_lock\FunctionalCode
public function testMultipleFormModes() {
$this
->drupalLogin($this->admin);
$edit = [
'entity_test_mul_changed[bundles][*]' => 1,
];
$this
->drupalPostForm('admin/config/content/content_lock', $edit, t('Save configuration'));
$lockService = \Drupal::service('content_lock');
// Login user 1.
$this
->drupalLogin($this->user1);
// Enter default form mode and create lock.
$this
->drupalGet($this->entity
->toUrl('edit-form'));
$this
->assertSession()
->pageTextContains('This content is now locked against simultaneous editing');
$this
->assertNotFalse($lockService
->fetchLock($this->entity
->id(), $this->entity
->language()
->getId(), NULL, 'entity_test_mul_changed'));
$this
->drupalGet($this->entity
->toUrl('compact'));
$this
->assertSession()
->pageTextContains('This content is now locked by you against simultaneous editing');
$this
->assertNotFalse($lockService
->fetchLock($this->entity
->id(), $this->entity
->language()
->getId(), NULL, 'entity_test_mul_changed'));
// Login as user 2. Shouldn't be able to edit forms.
$this
->drupalLogin($this->user2);
$this
->drupalGet($this->entity
->toUrl('edit-form'));
$this
->assertSession()
->pageTextContains('This content is being edited by the user');
$input = $this
->assertSession()
->elementExists('css', 'input#edit-field-test-text-0-value');
$this
->assertTrue($input
->hasAttribute('disabled'));
$this
->drupalGet($this->entity
->toUrl('compact'));
$this
->assertSession()
->pageTextContains('This content is being edited by the user');
$input = $this
->assertSession()
->elementExists('css', 'input#edit-field-test-text-0-value');
$this
->assertTrue($input
->hasAttribute('disabled'));
}