mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-09 10:16:36 +02:00
Merge branch '3.3.x'
This commit is contained in:
56
tests/lock/posting_test.php
Normal file
56
tests/lock/posting_test.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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->assertFalse($this->lock->acquire(100, 'foo'));
|
||||
$this->cache->put(sha1('100foo') . '_posting_lock', 'foo', -30);
|
||||
|
||||
$this->assertTrue($this->lock->acquire(100, 'foo'));
|
||||
$this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock'));
|
||||
$this->config->offsetSet('ci_tests_no_lock_posting', true);
|
||||
$this->assertTrue($this->lock->acquire(100, 'foo'));
|
||||
$this->assertTrue($this->cache->_exists(sha1('100foo') . '_posting_lock'));
|
||||
// Multiple acquires possible due to special ci test flag
|
||||
$this->assertTrue($this->lock->acquire(100, 'foo'));
|
||||
}
|
||||
}
|
@@ -106,6 +106,14 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
|
||||
$db = $this->get_db();
|
||||
|
||||
// Special flag for testing without possibility to run into lock scenario.
|
||||
// Unset entry and add it back if lock behavior for posting should be tested.
|
||||
// Unset ci_tests_no_lock_posting from config
|
||||
$db->sql_return_on_error(true);
|
||||
$sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value) VALUES ('ci_tests_no_lock_posting', '1')";
|
||||
$this->db->sql_query($sql);
|
||||
$db->sql_return_on_error(false);
|
||||
|
||||
foreach (static::setup_extensions() as $extension)
|
||||
{
|
||||
$this->purge_cache();
|
||||
@@ -130,6 +138,11 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
|
||||
if ($this->db instanceof \phpbb\db\driver\driver_interface)
|
||||
{
|
||||
// Unset ci_tests_no_lock_posting from config
|
||||
$sql = 'DELETE FROM ' . CONFIG_TABLE . "
|
||||
WHERE config_name = 'ci_tests_no_lock_posting'";
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
// Close the database connections again this test
|
||||
$this->db->sql_close();
|
||||
}
|
||||
@@ -212,6 +225,9 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \phpbb\db\driver\driver_interface
|
||||
*/
|
||||
protected function get_db()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
@@ -136,7 +136,6 @@ class phpbb_test_case_helpers
|
||||
{
|
||||
$config = array();
|
||||
|
||||
|
||||
if (extension_loaded('sqlite3'))
|
||||
{
|
||||
$config = array_merge($config, array(
|
||||
|
Reference in New Issue
Block a user