1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_config_test extends phpbb_test_case
{
public function test_offset_exists()
{
$config = new \phpbb\config\config(array('foo' => 'bar'));
$this->assertTrue(isset($config['foo']));
$this->assertFalse(isset($config['foobar']));
}
public function test_offset_get()
{
$config = new \phpbb\config\config(array('foo' => 'bar'));
$this->assertEquals('bar', $config['foo']);
}
public function test_offset_get_missing()
{
$config = new \phpbb\config\config(array());
$this->assertEquals('', $config['foo']);
}
public function test_offset_set()
{
$config = new \phpbb\config\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\config(array('foo' => 'x'));
unset($config['foo']);
}
public function test_count()
{
$config = new \phpbb\config\config(array('foo' => 'bar'));
$this->assertEquals(1, count($config));
}
public function test_iterate()
{
$vars = array('foo' => '23', 'bar' => '42');
$config = new \phpbb\config\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\config(array('foo' => 'x'));
$config->set('foo', 'bar');
$this->assertEquals('bar', $config['foo']);
}
public function test_set_new()
{
$config = new \phpbb\config\config(array());
$config->set('foo', 'bar');
$this->assertEquals('bar', $config['foo']);
}
public function test_set_atomic_overwrite()
{
$config = new \phpbb\config\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\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\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\config(array('foo' => '23'));
$config->increment('foo', 3);
$this->assertEquals(26, $config['foo']);
$config->increment('foo', 1);
$this->assertEquals(27, $config['foo']);
}
public function test_delete()
{
$config = new \phpbb\config\config(array('foo' => 'bar'));
$config->delete('foo');
$this->assertFalse(isset($config['foo']));
}
}
|