aboutsummaryrefslogtreecommitdiff
blob: b24c2fb17fe9c97cc60cf7167d4ba42a2fc23e1f (plain)
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
<?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.
*
*/

class phpbb_config_db_text_test extends phpbb_database_test_case
{
	private $db;
	private $config_text;

	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config_text.xml');
	}

	public function setUp()
	{
		parent::setUp();

		$this->db = $this->new_dbal();
		$this->config_text = new \phpbb\config\db_text($this->db, 'phpbb_config_text');
	}

	public function test_get()
	{
		$this->assertSame('23', $this->config_text->get('foo'));
		$this->assertSame('string-de-ding', $this->config_text->get('meh'));
	}

	public function test_get_nonexisting()
	{
		$this->assertNull($this->config_text->get('noooooo'));
	}

	public function test_set_new_get()
	{
		$this->config_text->set('barz', 'phpbb');
		$this->assertSame('phpbb', $this->config_text->get('barz'));
	}

	public function test_set_replace_get()
	{
		$this->config_text->set('foo', '24');
		$this->assertSame('24', $this->config_text->get('foo'));
	}

	public function test_set_get_long_string()
	{
		$expected = str_repeat('ABC', 10000);
		$this->config_text->set('long', $expected);
		$this->assertSame($expected, $this->config_text->get('long'));
	}

	public function test_delete_get()
	{
		$this->config_text->delete('foo');
		$this->assertNull($this->config_text->get('foo'));

		$this->assertSame('42', $this->config_text->get('bar'));
		$this->assertSame('string-de-ding', $this->config_text->get('meh'));
	}

	public function test_get_array_empty()
	{
		$this->assertEmpty($this->config_text->get_array(array('key1', 'key2')));
	}

	public function test_get_array_subset()
	{
		$expected = array(
			'bar' => '42',
			'foo' => '23',
		);

		$actual = $this->config_text->get_array(array_keys($expected));
		ksort($actual);

		$this->assertSame($expected, $actual);
	}

	public function test_set_array_get_array_subset()
	{
		$set_array_param = array(
			// New entry
			'baby' => 'phpBB',
			// Entry update
			'bar' => '64',
		);

		$this->config_text->set_array($set_array_param);

		$expected = array_merge($set_array_param, array(
			'foo' => '23',
		));

		$actual = $this->config_text->get_array(array_keys($expected));
		ksort($actual);

		$this->assertSame($expected, $actual);
	}

	public function test_delete_array_get_remaining()
	{
		$this->config_text->delete_array(array('foo', 'bar'));

		$this->assertNull($this->config_text->get('bar'));
		$this->assertNull($this->config_text->get('foo'));

		$this->assertSame('string-de-ding', $this->config_text->get('meh'));
	}
}