You are here

public function ContentLockModesTest::testMultipleFormModes in Content locking (anti-concurrent editing) 8

Same name and namespace in other branches
  1. 8.2 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 107

Class

ContentLockModesTest
Content lock modes tests.

Namespace

Drupal\Tests\content_lock\Functional

Code

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
    ->assertTrue($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
    ->assertTrue($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');
  $disabled_field = $this
    ->xpath('//input[@id=:id and @disabled="disabled"]', [
    ':id' => 'edit-field-test-text-0-value',
  ]);
  $this
    ->assertTrue($disabled_field, t('The form can be submitted.'));
  $this
    ->drupalGet($this->entity
    ->toUrl('compact'));
  $this
    ->assertSession()
    ->pageTextContains('This content is being edited by the user');
  $disabled_field = $this
    ->xpath('//input[@id=:id and @disabled="disabled"]', [
    ':id' => 'edit-field-test-text-0-value',
  ]);
  $this
    ->assertTrue($disabled_field, t('The form can be submitted.'));
}