diff --git a/core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php b/core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php new file mode 100644 index 0000000..933f8b5 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php @@ -0,0 +1,77 @@ + 'LockBackendAbstract test', + 'description' => 'Test the LockBackendAbstract class.', + 'group' => 'Lock', + ); + } + + public function setUp() { + $this->lock = $this->getMockForAbstractClass('Drupal\Core\Lock\LockBackendAbstract'); + } + + /** + * Tests the wait() method when lockMayBeAvailable() returns TRUE. + */ + public function testWaitFalse() { + $this->lock->expects($this->any()) + ->method('lockMayBeAvailable') + ->with($this->equalTo('test_name')) + ->will($this->returnValue(TRUE)); + + $this->assertFalse($this->lock->wait('test_name')); + } + + /** + * Tests the wait() method when lockMayBeAvailable() returns FALSE. + */ + public function testWaitTrue() { + $this->lock->expects($this->any()) + ->method('lockMayBeAvailable') + ->with($this->equalTo('test_name')) + ->will($this->returnValue(FALSE)); + + $this->assertTrue($this->lock->wait('test_name', 1)); + } + + /** + * Test the getLockId() method. + */ + public function testGetLockId() { + $lock_id = $this->lock->getLockId(); + $this->assertInternalType('string', $lock_id); + // Example lock ID would be '7213141505232b6ee2cb967.27683891'. + $this->assertRegExp('/[\da-f]+\.\d+/', $lock_id); + // Test the same lock ID is returned a second time. + $this->assertSame($lock_id, $this->lock->getLockId()); + } + +}