aboutsummaryrefslogtreecommitdiffstats
path: root/tests/migrator/convert_timezones_test.php
blob: 4bb0aec34fd22690198cce0af3204703b7f23f07 (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
<?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_migrator_convert_timezones_test extends phpbb_database_test_case
{
	protected $notifications, $db, $container, $user, $config, $auth, $cache;

	public function getDataSet()
	{
		$this->db = $this->new_dbal();
		$factory = new \phpbb\db\tools\factory();
		$db_tools = $factory->get($this->db);

		// user_dst doesn't exist anymore, must re-add it to test this
		$db_tools->sql_column_add('phpbb_users', 'user_dst', array('BOOL', 1));

		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/convert_timezones.xml');
	}

	public function revert_schema()
	{
		return array(
			'drop_columns'	=> array(
				$this->table_prefix . 'users'			=> array(
					'user_dst',
				),
			),
		);
	}

	public function update_schema()
	{
		return array(
			'add_columns'	=> array(
				$this->table_prefix . 'users'			=> array(
					'user_dst'		=> array('BOOL', 0),
				),
			),
		);
	}

	protected function setUp(): void
	{
		parent::setUp();

		global $phpbb_root_path, $phpEx;

		$this->db = $this->new_dbal();
		$factory = new \phpbb\db\tools\factory();

		$this->migration = new \phpbb\db\migration\data\v310\timezone(
			new \phpbb\config\config(array()),
			$this->db,
			$factory->get($this->db),
			$phpbb_root_path,
			$phpEx,
			'phpbb_'
		);
	}

	protected $expected_results = array(
		//user_id => user_timezone
		1 => 'Etc/GMT+12',
		2 => 'Etc/GMT+11',
		3 => 'Etc/GMT-3',
		4 => 'Etc/GMT-4',
		5 => 'America/St_Johns',
		6 => 'Australia/Eucla',
	);

	public function test_convert()
	{
		$this->migration->update_timezones(0);

		$sql = 'SELECT user_id, user_timezone
			FROM phpbb_users
			ORDER BY user_id ASC';
		$result = $this->db->sql_query($sql);
		while ($row = $this->db->sql_fetchrow($result))
		{
			$this->assertEquals($this->expected_results[$row['user_id']], $row['user_timezone']);
		}
		$this->db->sql_freeresult($result);

		$factory = new \phpbb\db\tools\factory();
		$db_tools = $factory->get($this->db);

		// Remove the user_dst field again
		$db_tools->sql_column_remove('phpbb_users', 'user_dst');
	}
}