Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
68 / 68 |
|
100.00% |
18 / 18 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_config_db_test | |
100.00% |
68 / 68 |
|
100.00% |
18 / 18 |
18 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_load_config | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_load_cached | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| test_offset_set | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_overwrite | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_overwrite_uncached | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_new | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_new_json | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_new_uncached | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_atomic_overwrite | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_atomic_new | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_atomic_failure | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_increment | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_increment_new | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_write_read_not_cacheable | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_write_read_cacheable | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class phpbb_config_db_test extends phpbb_database_test_case |
| 15 | { |
| 16 | private $cache; |
| 17 | private $db; |
| 18 | private $config; |
| 19 | |
| 20 | public function getDataSet() |
| 21 | { |
| 22 | return $this->createXMLDataSet(__DIR__ . '/fixtures/config.xml'); |
| 23 | } |
| 24 | |
| 25 | protected function setUp(): void |
| 26 | { |
| 27 | parent::setUp(); |
| 28 | |
| 29 | $this->cache = new phpbb_mock_cache; |
| 30 | $this->db = $this->new_dbal(); |
| 31 | $this->config = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); |
| 32 | } |
| 33 | |
| 34 | public function test_load_config() |
| 35 | { |
| 36 | $this->assertEquals('23', $this->config['foo']); |
| 37 | $this->assertEquals('42', $this->config['bar']); |
| 38 | } |
| 39 | |
| 40 | public function test_load_cached() |
| 41 | { |
| 42 | $cache = new phpbb_mock_cache(array('config' => array('x' => 'y'))); |
| 43 | $this->config = new \phpbb\config\db($this->db, $cache, 'phpbb_config'); |
| 44 | |
| 45 | $this->assertTrue(!isset($this->config['foo'])); |
| 46 | $this->assertEquals('42', $this->config['bar']); |
| 47 | |
| 48 | $this->assertEquals('y', $this->config['x']); |
| 49 | } |
| 50 | |
| 51 | public function test_offset_set() |
| 52 | { |
| 53 | $this->config['foo'] = 'x'; // temporary set |
| 54 | $this->assertEquals('x', $this->config['foo']); |
| 55 | |
| 56 | $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); |
| 57 | $this->assertEquals('23', $config2['foo']); |
| 58 | } |
| 59 | |
| 60 | public function test_set_overwrite() |
| 61 | { |
| 62 | $this->config->set('foo', '17'); |
| 63 | $this->assertEquals('17', $this->config['foo']); |
| 64 | |
| 65 | // re-read config and populate cache |
| 66 | $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); |
| 67 | $this->cache->checkVar($this, 'config', array('foo' => '17')); |
| 68 | } |
| 69 | |
| 70 | public function test_set_overwrite_uncached() |
| 71 | { |
| 72 | $this->config->set('bar', '17', false); |
| 73 | |
| 74 | // re-read config and populate cache |
| 75 | $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); |
| 76 | $this->cache->checkVar($this, 'config', array('foo' => '23')); |
| 77 | } |
| 78 | |
| 79 | public function test_set_new() |
| 80 | { |
| 81 | $this->config->set('foobar', '5'); |
| 82 | $this->assertEquals('5', $this->config['foobar']); |
| 83 | |
| 84 | // re-read config and populate cache |
| 85 | $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); |
| 86 | $this->cache->checkVar($this, 'config', array('foo' => '23', 'foobar' => '5')); |
| 87 | } |
| 88 | |
| 89 | public function test_set_new_json() |
| 90 | { |
| 91 | $json_value = '{"menu":{"id":"file","value":"File"}}'; |
| 92 | $this->config->set('foobar_json', $json_value); |
| 93 | $this->assertEquals($json_value, $this->config['foobar_json']); |
| 94 | |
| 95 | // re-read config and populate cache |
| 96 | $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); |
| 97 | $this->cache->checkVar($this, 'config', ['foo' => '23', 'foobar_json' => $json_value]); |
| 98 | } |
| 99 | |
| 100 | public function test_set_new_uncached() |
| 101 | { |
| 102 | $this->config->set('foobar', '5', false); |
| 103 | $this->assertEquals('5', $this->config['foobar']); |
| 104 | |
| 105 | // re-read config and populate cache |
| 106 | $config2 = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); |
| 107 | $this->cache->checkVar($this, 'config', array('foo' => '23')); |
| 108 | } |
| 109 | |
| 110 | public function test_set_atomic_overwrite() |
| 111 | { |
| 112 | $this->assertTrue($this->config->set_atomic('foo', '23', '17')); |
| 113 | $this->assertEquals('17', $this->config['foo']); |
| 114 | } |
| 115 | |
| 116 | public function test_set_atomic_new() |
| 117 | { |
| 118 | $this->assertTrue($this->config->set_atomic('foobar', false, '5')); |
| 119 | $this->assertEquals('5', $this->config['foobar']); |
| 120 | } |
| 121 | |
| 122 | public function test_set_atomic_failure() |
| 123 | { |
| 124 | $this->assertFalse($this->config->set_atomic('foo', 'wrong', '17')); |
| 125 | $this->assertEquals('23', $this->config['foo']); |
| 126 | } |
| 127 | |
| 128 | public function test_increment() |
| 129 | { |
| 130 | $this->config->increment('foo', 3); |
| 131 | $this->assertEquals(26, $this->config['foo']); |
| 132 | $this->config->increment('foo', 1); |
| 133 | $this->assertEquals(27, $this->config['foo']); |
| 134 | } |
| 135 | |
| 136 | public function test_increment_new() |
| 137 | { |
| 138 | $this->config->increment('foobar', 3); |
| 139 | $this->assertEquals(3, $this->config['foobar']); |
| 140 | } |
| 141 | |
| 142 | public function test_delete() |
| 143 | { |
| 144 | $this->assertTrue(isset($this->config['foo'])); |
| 145 | $this->config->delete('foo'); |
| 146 | $this->cache->checkVarUnset($this, 'foo'); |
| 147 | $this->assertFalse(isset($this->config['foo'])); |
| 148 | |
| 149 | // re-read config and populate cache |
| 150 | $cache2 = new phpbb_mock_cache; |
| 151 | $config2 = new \phpbb\config\db($this->db, $cache2, 'phpbb_config'); |
| 152 | $cache2->checkVarUnset($this, 'foo'); |
| 153 | $this->assertFalse(isset($config2['foo'])); |
| 154 | } |
| 155 | |
| 156 | public function test_delete_write_read_not_cacheable() |
| 157 | { |
| 158 | // bar is dynamic |
| 159 | $this->assertTrue(isset($this->config['bar'])); |
| 160 | $this->config->delete('bar'); |
| 161 | $this->cache->checkVarUnset($this, 'bar'); |
| 162 | $this->assertFalse(isset($this->config['bar'])); |
| 163 | |
| 164 | $this->config->set('bar', 'new bar', false); |
| 165 | $this->assertEquals('new bar', $this->config['bar']); |
| 166 | } |
| 167 | |
| 168 | public function test_delete_write_read_cacheable() |
| 169 | { |
| 170 | // foo is not dynamic |
| 171 | $this->assertTrue(isset($this->config['foo'])); |
| 172 | $this->config->delete('foo'); |
| 173 | $this->cache->checkVarUnset($this, 'foo'); |
| 174 | $this->assertFalse(isset($this->config['foo'])); |
| 175 | |
| 176 | $this->config->set('foo', 'new foo', true); |
| 177 | $this->assertEquals('new foo', $this->config['foo']); |
| 178 | } |
| 179 | } |