1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-05 14:04:57 +02:00

[ticket/17077] Add test for posting lock

PHPBB3-17077
This commit is contained in:
Marc Alexander 2024-04-09 21:13:28 +02:00
parent 3b5777f900
commit 98929ca983
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995

View File

@ -0,0 +1,54 @@
<?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'));
}
}