You are here

public function PrefetchCacheTest::testPrefetchCacheJsLocking in Content locking (anti-concurrent editing) 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/Integration/PrefetchCacheTest.php \Drupal\Tests\content_lock\FunctionalJavascript\Integration\PrefetchCacheTest::testPrefetchCacheJsLocking()

Test the prefetch cache integration with JS locking.

File

tests/src/FunctionalJavascript/Integration/PrefetchCacheTest.php, line 37

Class

PrefetchCacheTest
Class PrefetchCacheTest.

Namespace

Drupal\Tests\content_lock\FunctionalJavascript\Integration

Code

public function testPrefetchCacheJsLocking() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalLogin($this->admin);
  $this
    ->drupalGet('admin/config/content/content_lock');
  $this
    ->click('#edit-entity-types-entity-test-mul-changed');
  $this
    ->click('#edit-entity-test-mul-changed-settings-js-lock');
  $page
    ->pressButton('Save configuration');
  $lockService = \Drupal::service('content_lock');
  $this
    ->drupalLogin($this->user1);
  $this
    ->drupalGet($this->entity
    ->toUrl());

  // On canonical no lock should be created.
  $this
    ->assertFalse($lockService
    ->fetchLock($this->entity
    ->id(), $this->entity
    ->language()
    ->getId(), NULL, 'entity_test_mul_changed'));

  // On edit page a lock should be there.
  $this
    ->drupalGet($this->entity
    ->toUrl('edit-form'));
  $assert_session
    ->waitForElement('css', 'messages messages--status');
  $this
    ->assertTrue($lockService
    ->fetchLock($this->entity
    ->id(), $this->entity
    ->language()
    ->getId(), NULL, 'entity_test_mul_changed'));

  // After saving, the lock should be gone.
  $page
    ->pressButton(t('Save'));
  $this
    ->assertFalse($lockService
    ->fetchLock($this->entity
    ->id(), $this->entity
    ->language()
    ->getId(), NULL, 'entity_test_mul_changed'));
}