aboutsummaryrefslogtreecommitdiffstats
path: root/tests/migrator/schema_generator_test.php
blob: 1349b9895347b723bbb2ca17a75faf2fd88e2371 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?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 __DIR__ . '/../dbal/migration/dummy_order.php';
require_once __DIR__ . '/../dbal/migration/dummy_order_0.php';
require_once __DIR__ . '/../dbal/migration/dummy_order_1.php';
require_once __DIR__ . '/../dbal/migration/dummy_order_2.php';
require_once __DIR__ . '/../dbal/migration/dummy_order_3.php';
require_once __DIR__ . '/../dbal/migration/dummy_order_4.php';
require_once __DIR__ . '/../dbal/migration/dummy_order_5.php';

class schema_generator_test extends phpbb_test_case
{
	/** @var \phpbb\db\migration\schema_generator */
	protected $generator;

	public function setUp(): void
	{
		global $phpbb_root_path, $phpEx;

		parent::setUp();

		$this->config = new \phpbb\config\config(array());
		$this->db = new \phpbb\db\driver\sqlite3();
		$factory = new \phpbb\db\tools\factory();
		$this->db_tools = $factory->get($this->db);
		$this->table_prefix = 'phpbb_';
		$this->phpbb_root_path = $phpbb_root_path;
		$this->php_ext = $phpEx;
	}

	protected function get_schema_generator(array $class_names)
	{
		$this->generator = new \phpbb\db\migration\schema_generator($class_names, $this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);

		return $this->generator;
	}

	/**
	 * @expectedException \UnexpectedValueException
	 */
	public function test_check_dependencies_fail()
	{
		$this->get_schema_generator(array('\phpbb\db\migration\data\v310\forgot_password'));

		$this->generator->get_schema();
	}

	public function test_get_schema_success()
	{
		$this->get_schema_generator(array(
			'\phpbb\db\migration\data\v30x\release_3_0_1_rc1',
			'\phpbb\db\migration\data\v30x\release_3_0_0',
			'\phpbb\db\migration\data\v310\boardindex'
		));

		$this->assertArrayHasKey('phpbb_users', $this->generator->get_schema());
	}

	public function column_add_after_data()
	{
		return array(
			array(
				'phpbb_dbal_migration_dummy_order_0',
				array(
					'foobar1',
					'foobar2',
					'foobar3',
				),
			),
			array(
				'phpbb_dbal_migration_dummy_order_1',
				array(
					'foobar1',
					'foobar3',
					'foobar4',
				),
			),
			array(
				'phpbb_dbal_migration_dummy_order_2',
				array(
					'foobar1',
					'foobar3',
					'foobar5',
				),
			),
			array(
				'phpbb_dbal_migration_dummy_order_3',
				array(
					'foobar1',
					'foobar3',
					'foobar6',
				),
			),
			array(
				'phpbb_dbal_migration_dummy_order_4',
				array(
					'foobar1',
					'foobar3',
					'foobar7',
				),
			),
			array(
				'phpbb_dbal_migration_dummy_order_5',
				array(
					'foobar1',
					'foobar3',
					'foobar9',
					'foobar8',
				),
			),
		);
	}

	/**
	* @dataProvider column_add_after_data
	*/
	public function test_column_add_after($migration, $expected)
	{
		$this->get_schema_generator(array(
			'phpbb_dbal_migration_dummy_order',
			$migration,
		));

		$tables = $this->generator->get_schema();

		$this->assertEquals(
			$expected,
			array_keys($tables[$this->table_prefix . 'column_order_test1']['COLUMNS']),
			'The schema generator could not position the column correctly, using the "after" option in the migration script.'
		);
	}
}