aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal/sql_affected_rows_test.php
blob: df008bab9a87bb9eef1cefa9796ddd281dbc0863 (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
<?php
/**
*
* @package testing
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

class phpbb_dbal_sql_affected_rows_test extends phpbb_database_test_case
{
	/** @var \phpbb\db\driver\driver_interface */
	protected $db;

	public function setUp()
	{
		parent::setUp();
		$this->db = $this->new_dbal();
	}

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

	public function test_select()
	{
		$sql = 'SELECT *
			FROM ' . CONFIG_TABLE;
		$this->db->sql_query($sql);

		$this->assertEquals(2, $this->db->sql_affectedrows());
	}

	public function test_update()
	{
		$sql = 'UPDATE ' . CONFIG_TABLE . "
			SET config_value = 'bertie'";
		$this->db->sql_query($sql);

		$this->assertEquals(2, $this->db->sql_affectedrows());
	}

	public function test_update_all_matched_unequal_updated()
	{
		$sql = 'UPDATE ' . CONFIG_TABLE . "
			SET config_value = 'foo'";
		$this->db->sql_query($sql);

		$this->assertEquals(2, $this->db->sql_affectedrows());
	}

	public function test_update_some_matched_unequal_updated()
	{
		$sql = 'UPDATE ' . CONFIG_TABLE . "
			SET config_value = 'foo'
			WHERE config_value = 'foo'";
		$this->db->sql_query($sql);

		$this->assertEquals(1, $this->db->sql_affectedrows());
	}

	public function test_insert()
	{
		$sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
			'config_name'	=> 'bertie',
			'config_value'	=> 'rules',
		));
		$this->db->sql_query($sql);

		$this->assertEquals(1, $this->db->sql_affectedrows());
	}
}