aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php
blob: 0e27f129de7d6812035d38c90c68ceb8eb493ae2 (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
<?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.
*
*/

require_once dirname(__FILE__) . '/../../phpBB/includes/functions_database_helper.php';

class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_case
{
	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/bookmarks_duplicates.xml');
	}

	public static function fixture_data()
	{
		return array(
			// description
			// from array
			// to value
			// expected count with to value post update
			array(
				'trivial',
				array(1),
				10,
				1,
			),
			array(
				'no conflict',
				array(2),
				3,
				2,
			),
			array(
				'conflict',
				array(4),
				5,
				1,
			),
			array(
				'conflict and no conflict',
				array(6),
				7,
				2,
			),
		);
	}

	/**
	* @dataProvider fixture_data
	*/
	public function test_update($description, $from, $to, $expected_result_count)
	{
		$db = $this->new_dbal();

		phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $from, $to);

		$sql = 'SELECT COUNT(*) AS remaining_rows
			FROM ' . BOOKMARKS_TABLE . '
			WHERE topic_id = ' . (int) $to;
		$result = $db->sql_query($sql);
		$result_count = $db->sql_fetchfield('remaining_rows');
		$db->sql_freeresult($result);

		$this->assertEquals($expected_result_count, $result_count);
	}
}