You are here

public function ContentLockModesTest::testEnabledForSelectedFormModes in Content locking (anti-concurrent editing) 8.2

Same name and namespace in other branches
  1. 8 tests/src/Functional/ContentLockModesTest.php \Drupal\Tests\content_lock\Functional\ContentLockModesTest::testEnabledForSelectedFormModes()

Test simultaneous edit on test entity.

File

tests/src/Functional/ContentLockModesTest.php, line 29

Class

ContentLockModesTest
Content lock modes tests.

Namespace

Drupal\Tests\content_lock\Functional

Code

public function testEnabledForSelectedFormModes() {
  $this
    ->drupalLogin($this->admin);
  $edit = [
    'entity_test_mul_changed[bundles][*]' => 1,
    'entity_test_mul_changed[settings][form_op_lock][mode]' => 1,
    'entity_test_mul_changed[settings][form_op_lock][values][default]' => 'default',
  ];
  $this
    ->drupalPostForm('admin/config/content/content_lock', $edit, t('Save configuration'));
  $lockService = \Drupal::service('content_lock');

  // Login user 1.
  $this
    ->drupalLogin($this->user1);

  // Create lock on default form.
  $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(), 'default', 'entity_test_mul_changed'));

  // Enter compact form mode without creating lock.
  $this
    ->drupalGet($this->entity
    ->toUrl('compact'));
  $this
    ->assertSession()
    ->pageTextNotContains('This content is now locked against simultaneous editing');
  $this
    ->assertFalse($lockService
    ->fetchLock($this->entity
    ->id(), $this->entity
    ->language()
    ->getId(), 'compact', 'entity_test_mul_changed'));
  $this
    ->drupalLogin($this->user2);
  $this
    ->drupalGet($this->entity
    ->toUrl('edit-form'));
  $this
    ->assertSession()
    ->pageTextContains('This content is being edited by the user');

  // Fields are disabled.
  $input = $this
    ->assertSession()
    ->elementExists('css', 'input#edit-field-test-text-0-value');
  $this
    ->assertTrue($input
    ->hasAttribute('disabled'));

  // Enter compact form mode without creating lock.
  $this
    ->drupalGet($this->entity
    ->toUrl('compact'));
  $this
    ->assertSession()
    ->pageTextNotContains('This content is now locked against simultaneous editing');
  $this
    ->assertFalse($lockService
    ->fetchLock($this->entity
    ->id(), $this->entity
    ->language()
    ->getId(), 'compact', 'entity_test_mul_changed'));

  // Fields are open.
  $input = $this
    ->assertSession()
    ->elementExists('css', 'input#edit-field-test-text-0-value');
  $this
    ->assertFalse($input
    ->hasAttribute('disabled'));
}