mirror of
https://github.com/phpbb/phpbb.git
synced 2025-02-25 20:44:01 +01:00
There is a phpbb_config class which simply holds an array and does not persist any data. It implements ArrayAccess, Countable and IteratorAggregate to allow regular use of configuration as if it was still an array. The phpbb_config_db class depends on an instance of the dbal and a cache driver. It obtains the configuration data from cache and database as necessary and persists data to the database. The functions set_config and set_config_count remain for backward compatability but they only call methods on the new config class now instead of directly manipulating the database and cache. PHPBB3-9988
113 lines
2.6 KiB
PHP
113 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* @package testing
|
|
* @copyright (c) 2010 phpBB Group
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
*
|
|
*/
|
|
|
|
class phpbb_config_test extends phpbb_test_case
|
|
{
|
|
public function test_offset_exists()
|
|
{
|
|
$config = new phpbb_config(array('foo' => 'bar'));
|
|
|
|
$this->assertTrue(isset($config['foo']));
|
|
$this->assertFalse(isset($config['foobar']));
|
|
}
|
|
|
|
public function test_offset_get()
|
|
{
|
|
$config = new phpbb_config(array('foo' => 'bar'));
|
|
$this->assertEquals('bar', $config['foo']);
|
|
}
|
|
|
|
public function test_offset_get_missing()
|
|
{
|
|
$config = new phpbb_config(array());
|
|
$this->assertEquals('', $config['foo']);
|
|
}
|
|
|
|
public function test_offset_set()
|
|
{
|
|
$config = new phpbb_config(array());
|
|
$config['foo'] = 'x';
|
|
$this->assertEquals('x', $config['foo']);
|
|
}
|
|
|
|
public function test_offset_unset_fails()
|
|
{
|
|
$this->setExpectedTriggerError(E_USER_ERROR);
|
|
$config = new phpbb_config(array('foo' => 'x'));
|
|
unset($config['foo']);
|
|
}
|
|
|
|
public function test_count()
|
|
{
|
|
$config = new phpbb_config(array('foo' => 'bar'));
|
|
$this->assertEquals(1, count($config));
|
|
}
|
|
|
|
public function test_iterate()
|
|
{
|
|
$vars = array('foo' => '23', 'bar' => '42');
|
|
$config = new phpbb_config($vars);
|
|
|
|
$count = 0;
|
|
foreach ($config as $key => $value)
|
|
{
|
|
$this->assertTrue(isset($vars[$key]));
|
|
$this->assertEquals($vars[$key], $value);
|
|
|
|
$count++;
|
|
}
|
|
|
|
$this->assertEquals(count($vars), $count);
|
|
}
|
|
|
|
public function test_set_overwrite()
|
|
{
|
|
$config = new phpbb_config(array('foo' => 'x'));
|
|
$config->set('foo', 'bar');
|
|
$this->assertEquals('bar', $config['foo']);
|
|
}
|
|
|
|
public function test_set_new()
|
|
{
|
|
$config = new phpbb_config(array());
|
|
$config->set('foo', 'bar');
|
|
$this->assertEquals('bar', $config['foo']);
|
|
}
|
|
|
|
public function test_set_atomic_overwrite()
|
|
{
|
|
$config = new phpbb_config(array('foo' => 'bar'));
|
|
$this->assertTrue($config->set_atomic('foo', 'bar', '23'));
|
|
$this->assertEquals('23', $config['foo']);
|
|
}
|
|
|
|
public function test_set_atomic_new()
|
|
{
|
|
$config = new phpbb_config(array());
|
|
$this->assertTrue($config->set_atomic('foo', false, '23'));
|
|
$this->assertEquals('23', $config['foo']);
|
|
}
|
|
|
|
public function test_set_atomic_failure()
|
|
{
|
|
$config = new phpbb_config(array('foo' => 'bar'));
|
|
$this->assertFalse($config->set_atomic('foo', 'wrong', '23'));
|
|
$this->assertEquals('bar', $config['foo']);
|
|
}
|
|
|
|
public function test_increment()
|
|
{
|
|
$config = new phpbb_config(array('foo' => '23'));
|
|
$config->increment('foo', 3);
|
|
$this->assertEquals(26, $config['foo']);
|
|
$config->increment('foo', 1);
|
|
$this->assertEquals(27, $config['foo']);
|
|
}
|
|
}
|