phpbb/tests/lock/posting_test.php
2024-04-09 21:13:28 +02:00

54 lines
No EOL
1.4 KiB
PHP

<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
use phpbb\cache\driver\file as file_cache;
use phpbb\config\config;
use phpbb\lock\posting;
class phpbb_lock_posting_test extends phpbb_test_case
{
/** @var \phpbb\cache\driver\file */
protected $cache;
/** @var config */
protected $config;
/** @var posting */
protected $lock;
public function setUp(): void
{
$this->cache = new file_cache(__DIR__ . '/../tmp/');
$this->cache->purge(); // ensure cache is clean
$this->config = new config([
'flood_interval' => 15,
]);
$this->lock = new posting($this->cache, $this->config);
}
public function test_lock_acquire()
{
$this->assertTrue($this->lock->acquire(100, 'foo'));
$this->assertFalse($this->lock->acquire(100, 'foo'));
$this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock'));
$this->lock->release();
$this->assertFalse($this->cache->_exists(sha1('100foo') . '_posting_lock'));
$this->assertTrue($this->lock->acquire(100, 'foo'));
$this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock'));
$this->lock->release();
$this->lock->release(); // double release has no effect
$this->assertFalse($this->cache->_exists(sha1('100foo') . '_posting_lock'));
}
}