diff options
Diffstat (limited to 'tests/migrator')
-rw-r--r-- | tests/migrator/get_schema_steps_test.php | 200 | ||||
-rw-r--r-- | tests/migrator/schema_generator_test.php | 49 |
2 files changed, 249 insertions, 0 deletions
diff --git a/tests/migrator/get_schema_steps_test.php b/tests/migrator/get_schema_steps_test.php new file mode 100644 index 0000000000..226535754e --- /dev/null +++ b/tests/migrator/get_schema_steps_test.php @@ -0,0 +1,200 @@ +<?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 setUp() + { + parent::setUp(); + + $this->helper = new \phpbb\db\migration\helper(); + } + + public function schema_provider() + { + return array( + array( + array( + 'add_tables' => array( + 'foo' => array( + 'COLUMNS' => array( + 'foobar' => array('BOOL', 0), + 'foobar2' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('foobar'), + ), + 'bar' => array( + 'COLUMNS' => array( + 'barfoo' => array('BOOL', 0), + 'barfoor2' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('barfoo'), + ), + ), + '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( + 'foo' => array( + 'COLUMNS' => array( + 'foobar' => array('BOOL', 0), + 'foobar2' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('foobar'), + ), + )))), + array('dbtools.perform_schema_changes', array(array('add_tables' => array( + 'bar' => array( + 'COLUMNS' => array( + 'barfoo' => array('BOOL', 0), + 'barfoor2' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('barfoo'), + ), + )))), + 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, $this->helper->get_schema_steps($schema_changes)); + } +} diff --git a/tests/migrator/schema_generator_test.php b/tests/migrator/schema_generator_test.php new file mode 100644 index 0000000000..4bac447229 --- /dev/null +++ b/tests/migrator/schema_generator_test.php @@ -0,0 +1,49 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class schmema_generator_test extends phpbb_test_case +{ + public function setUp() + { + parent::setUp(); + + $this->config = new \phpbb\config\config(array()); + $this->db = new \phpbb\db\driver\sqlite(); + $this->db_tools = new \phpbb\db\tools($this->db); + $this->table_prefix = 'phpbb_'; + } + + 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()); + } +} |