function LockFunctionalTest::testPersistentLock

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Lock/LockFunctionalTest.php \Drupal\Tests\system\Functional\Lock\LockFunctionalTest::testPersistentLock()
  2. 8.9.x core/modules/system/tests/src/Functional/Lock/LockFunctionalTest.php \Drupal\Tests\system\Functional\Lock\LockFunctionalTest::testPersistentLock()
  3. 10 core/modules/system/tests/src/Functional/Lock/LockFunctionalTest.php \Drupal\Tests\system\Functional\Lock\LockFunctionalTest::testPersistentLock()

Tests that the persistent lock is persisted between requests.

File

core/modules/system/tests/src/Functional/Lock/LockFunctionalTest.php, line 66

Class

LockFunctionalTest
Confirm locking works between two separate requests.

Namespace

Drupal\Tests\system\Functional\Lock

Code

public function testPersistentLock() : void {
    $persistent_lock = $this->container
        ->get('lock.persistent');
    // Get a persistent lock.
    $this->drupalGet('system-test/lock-persist/lock1');
    $this->assertSession()
        ->pageTextContains('TRUE: Lock successfully acquired in SystemTestController::lockPersist()');
    // Ensure that a shutdown function has not released the lock.
    $this->assertFalse($persistent_lock->lockMayBeAvailable('lock1'));
    $this->drupalGet('system-test/lock-persist/lock1');
    $this->assertSession()
        ->pageTextContains('FALSE: Lock not acquired in SystemTestController::lockPersist()');
    // Get another persistent lock.
    $this->drupalGet('system-test/lock-persist/lock2');
    $this->assertSession()
        ->pageTextContains('TRUE: Lock successfully acquired in SystemTestController::lockPersist()');
    $this->assertFalse($persistent_lock->lockMayBeAvailable('lock2'));
    // Release the first lock and try getting it again.
    $persistent_lock->release('lock1');
    $this->drupalGet('system-test/lock-persist/lock1');
    $this->assertSession()
        ->pageTextContains('TRUE: Lock successfully acquired in SystemTestController::lockPersist()');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.