You are here

protected function ContentLockTimeoutTest::doTestForEntity in Content locking (anti-concurrent editing) 8

Same name and namespace in other branches
  1. 8.2 modules/content_lock_timeout/tests/src/Functional/ContentLockTimeoutTest.php \Drupal\Tests\content_lock_timeout\Functional\ContentLockTimeoutTest::doTestForEntity()

Run the same tests for node, block and term.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to tests.

Throws

\Drupal\Core\Entity\EntityMalformedException

2 calls to ContentLockTimeoutTest::doTestForEntity()
ContentLockTimeoutTest::testContentLockNode in modules/content_lock_timeout/tests/src/Functional/ContentLockTimeoutTest.php
Test content lock timeout with nodes.
ContentLockTimeoutTest::testContentLockTerm in modules/content_lock_timeout/tests/src/Functional/ContentLockTimeoutTest.php
Test content lock timeout with terms.

File

modules/content_lock_timeout/tests/src/Functional/ContentLockTimeoutTest.php, line 238

Class

ContentLockTimeoutTest
Test content_lock_timeout sub module.

Namespace

Drupal\Tests\content_lock_timeout\Functional

Code

protected function doTestForEntity(EntityInterface $entity) {

  // We lock article1.
  $this
    ->drupalLogin($this->user2);
  $this
    ->lockContentByUser1($entity);

  // Content should be locked.
  $this
    ->drupalGet($entity
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertText(t('This content is being edited by the user @name and is therefore locked to prevent other users changes.', [
    '@name' => $this->user1
      ->getDisplayName(),
  ]));

  // Jump into future to release lock.
  \Drupal::time()
    ->setCurrentTime(time() + 60 * 60);
  $this
    ->cronRun();
  \Drupal::time()
    ->resetCurrentTime();

  // Content should be unlocked by cron.
  $this
    ->assertNoLockOnContent($entity);
  $this
    ->drupalGet($entity
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertText(t('This content is now locked against simultaneous editing.'));
  $this
    ->drupalLogout();

  // There should be no lock on the content after logout.
  $this
    ->assertNoLockOnContent($entity);
  $this
    ->lockContentByUser1($entity);
  $this
    ->drupalLogin($this->user2);

  // Content should be locked.
  $this
    ->drupalGet($entity
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertText(t('This content is being edited by the user @name and is therefore locked to prevent other users changes.', [
    '@name' => $this->user1
      ->getDisplayName(),
  ]));

  // Jump into the future.
  \Drupal::time()
    ->setCurrentTime(time() + 60 * 60);

  // Lock should be release by form prepare.
  $this
    ->drupalGet($entity
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertText(t('This content is now locked against simultaneous editing.'));
}