aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal/concatenate_test.php
blob: 00e7e107aa2085ede088b136d3007cdd1fe942ec (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
<?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_dbal_concatenate_test extends phpbb_database_test_case
{
	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
	}

	public function test_concatenate_string()
	{
		$db = $this->new_dbal();

		$sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string
			FROM phpbb_config';
		$result = $db->sql_query($sql);

		$db->sql_return_on_error(false);

		$this->assertEquals(array(
				array(
					'config_name'	=> 'config1',
					'string'		=> 'config1append',
				),
				array(
					'config_name'	=> 'config2',
					'string'		=> 'config2append',
				),
			),
			$db->sql_fetchrowset($result)
		);
	}

	public function test_concatenate_statement()
	{
		$db = $this->new_dbal();

		$sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string
			FROM phpbb_config';
		$result = $db->sql_query($sql);

		$db->sql_return_on_error(false);

		$this->assertEquals(array(
				array(
					'config_name'	=> 'config1',
					'string'		=> 'config1foo',
				),
				array(
					'config_name'	=> 'config2',
					'string'		=> 'config2bar',
				),
			),
			$db->sql_fetchrowset($result)
		);
	}
}