aboutsummaryrefslogtreecommitdiffstats
path: root/tests/migrator/get_schema_steps_test.php
blob: c37d55ea40b416bc4cf459917ee19ecea055b456 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
*
* @package testing
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

class get_schema_steps_test extends phpbb_test_case
{
	public function schema_provider()
	{
		return array(
			array(
				array(
					'add_tables'	=> array('table1', 'table2', 'table3'),
					'drop_tables'	=> array('table1', 'table2', 'table3'),
					'add_index'	=> array(
						'table1'	=> array(
							'index1'	=> 'column1',
							'index2'	=> 'column2',
						),
						'table2'	=> array(
							'index1'	=> 'column1',
							'index2'	=> 'column2',
						),
					),
					'add_columns'	=> array(
						'table1'	=> array(
							'column1'	=> array('foo'),
							'column2'	=> array('bar'),
						),
					),
					'change_columns'	=> array(
						'table1'	=> array(
							'column1'	=> array('foo'),
							'column2'	=> array('bar'),
						),
					),
					'drop_columns'	=> array(
						'table1'	=> array(
							'column1',
							'column2',
						),
					),
					'add_unique_index'	=> array(
						'table1'	=> array(
							'index1'	=> 'column1',
							'index2'	=> 'column2',
						),
					),
					'drop_keys'	=> array(
						'table1'	=> array(
							'column1',
							'column2',
						),
					),
					'add_primary_keys'	=> array(
						'table1' => array('foo'),
						'table2' => array('bar'),
						'table3' => array('foobar'),
					),
				),
				array(
					array('dbtools.perform_schema_changes', array(array('drop_tables'	=> array('table1')))),
					array('dbtools.perform_schema_changes', array(array('drop_tables'	=> array('table2')))),
					array('dbtools.perform_schema_changes', array(array('drop_tables'	=> array('table3')))),
					array('dbtools.perform_schema_changes', array(array('add_tables'	=> array('table1')))),
					array('dbtools.perform_schema_changes', array(array('add_tables'	=> array('table2')))),
					array('dbtools.perform_schema_changes', array(array('add_tables'	=> array('table3')))),
					array('dbtools.perform_schema_changes', array(array('change_columns'	=> array(
						'table1'	=> array(
							'column1'	=> array('foo'),
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('change_columns'	=> array(
						'table1'	=> array(
							'column2'	=> array('bar'),
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_columns'	=> array(
						'table1'	=> array(
							'column1'	=> array('foo'),
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_columns'	=> array(
						'table1'	=> array(
							'column2'	=> array('bar'),
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('drop_keys'	=> array(
						'table1'	=> array(
							0 => 'column1',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('drop_keys'	=> array(
						'table1'	=> array(
							1 => 'column2',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('drop_columns'	=> array(
						'table1'	=> array(
							0 => 'column1',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('drop_columns'	=> array(
						'table1'	=> array(
							1 => 'column2',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_primary_keys'	=> array(
						'table1' => array('foo'),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_primary_keys'	=> array(
						'table2' => array('bar'),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_primary_keys'	=> array(
						'table3' => array('foobar'),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_unique_index'	=> array(
						'table1'	=> array(
							'index1'	=> 'column1',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_unique_index'	=> array(
						'table1'	=> array(
							'index2'	=> 'column2',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_index'	=> array(
						'table1'	=> array(
							'index1'	=> 'column1',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_index'	=> array(
						'table1'	=> array(
							'index2'	=> 'column2',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_index'	=> array(
						'table2'	=> array(
							'index1'	=> 'column1',
						),
					)))),
					array('dbtools.perform_schema_changes', array(array('add_index'	=> array(
						'table2'	=> array(
							'index2'	=> 'column2',
						),
					)))),
				),
			),
		);
	}

	/**
	 * @dataProvider schema_provider
	 */
	public function test_get_schema_steps($schema_changes, $expected)
	{
		$this->assertEquals($expected, \phpbb\db\migrator::get_schema_steps($schema_changes));
	}
}