Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
47 / 47 |
|
100.00% |
14 / 14 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_config_db_text_test | |
100.00% |
47 / 47 |
|
100.00% |
14 / 14 |
14 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_get | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_nonexisting | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_new_get | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_new_get_json | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_replace_get | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_same_value_get | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_get_long_string | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_get | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_array_empty | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_array_subset | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_array_get_array_subset | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_array_get_remaining | |
100.00% |
4 / 4 |
|
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_text_test extends phpbb_database_test_case |
| 15 | { |
| 16 | /** @var \phpbb\config\db_text */ |
| 17 | protected $config_text; |
| 18 | |
| 19 | protected $db; |
| 20 | |
| 21 | public function getDataSet() |
| 22 | { |
| 23 | return $this->createXMLDataSet(__DIR__ . '/fixtures/config_text.xml'); |
| 24 | } |
| 25 | |
| 26 | protected function setUp(): void |
| 27 | { |
| 28 | parent::setUp(); |
| 29 | |
| 30 | $this->db = $this->new_dbal(); |
| 31 | $this->config_text = new \phpbb\config\db_text($this->db, 'phpbb_config_text'); |
| 32 | } |
| 33 | |
| 34 | public function test_get() |
| 35 | { |
| 36 | $this->assertSame('23', $this->config_text->get('foo')); |
| 37 | $this->assertSame('string-de-ding', $this->config_text->get('meh')); |
| 38 | } |
| 39 | |
| 40 | public function test_get_nonexisting() |
| 41 | { |
| 42 | $this->assertNull($this->config_text->get('noooooo')); |
| 43 | } |
| 44 | |
| 45 | public function test_set_new_get() |
| 46 | { |
| 47 | $this->config_text->set('barz', 'phpbb'); |
| 48 | $this->assertSame('phpbb', $this->config_text->get('barz')); |
| 49 | } |
| 50 | |
| 51 | public function test_set_new_get_json() |
| 52 | { |
| 53 | $json_value = '{"menu":{"id":"file","value":"File"}}'; |
| 54 | $this->config_text->set('foobar_json', $json_value); |
| 55 | $this->assertEquals($json_value, $this->config_text->get('foobar_json')); |
| 56 | } |
| 57 | |
| 58 | public function test_set_replace_get() |
| 59 | { |
| 60 | $this->config_text->set('foo', '24'); |
| 61 | $this->assertSame('24', $this->config_text->get('foo')); |
| 62 | } |
| 63 | |
| 64 | public function test_set_same_value_get() |
| 65 | { |
| 66 | $this->config_text->set('foo', '23'); |
| 67 | $this->assertSame('23', $this->config_text->get('foo')); |
| 68 | } |
| 69 | |
| 70 | public function test_set_get_long_string() |
| 71 | { |
| 72 | $expected = str_repeat('ABC', 10000); |
| 73 | $this->config_text->set('long', $expected); |
| 74 | $this->assertSame($expected, $this->config_text->get('long')); |
| 75 | } |
| 76 | |
| 77 | public function test_delete_get() |
| 78 | { |
| 79 | $this->config_text->delete('foo'); |
| 80 | $this->assertNull($this->config_text->get('foo')); |
| 81 | |
| 82 | $this->assertSame('42', $this->config_text->get('bar')); |
| 83 | $this->assertSame('string-de-ding', $this->config_text->get('meh')); |
| 84 | } |
| 85 | |
| 86 | public function test_get_array_empty() |
| 87 | { |
| 88 | $this->assertEmpty($this->config_text->get_array(array('key1', 'key2'))); |
| 89 | } |
| 90 | |
| 91 | public function test_get_array_subset() |
| 92 | { |
| 93 | $expected = array( |
| 94 | 'bar' => '42', |
| 95 | 'foo' => '23', |
| 96 | ); |
| 97 | |
| 98 | $actual = $this->config_text->get_array(array_keys($expected)); |
| 99 | ksort($actual); |
| 100 | |
| 101 | $this->assertSame($expected, $actual); |
| 102 | } |
| 103 | |
| 104 | public function test_set_array_get_array_subset() |
| 105 | { |
| 106 | $set_array_param = array( |
| 107 | // New entry |
| 108 | 'baby' => 'phpBB', |
| 109 | // Entry update |
| 110 | 'bar' => '64', |
| 111 | // Entry update - same value |
| 112 | 'foo' => '23', |
| 113 | ); |
| 114 | |
| 115 | $this->config_text->set_array($set_array_param); |
| 116 | |
| 117 | $expected = array_merge($set_array_param, array( |
| 118 | 'foo' => '23', |
| 119 | )); |
| 120 | |
| 121 | $actual = $this->config_text->get_array(array_keys($expected)); |
| 122 | ksort($actual); |
| 123 | |
| 124 | $this->assertSame($expected, $actual); |
| 125 | } |
| 126 | |
| 127 | public function test_delete_array_get_remaining() |
| 128 | { |
| 129 | $this->config_text->delete_array(array('foo', 'bar')); |
| 130 | |
| 131 | $this->assertNull($this->config_text->get('bar')); |
| 132 | $this->assertNull($this->config_text->get('foo')); |
| 133 | |
| 134 | $this->assertSame('string-de-ding', $this->config_text->get('meh')); |
| 135 | } |
| 136 | } |