diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php new file mode 100644 index 0000000000..2bb23e31c2 --- /dev/null +++ b/tests/dbal/migration/revert.php @@ -0,0 +1,45 @@ + array( + 'phpbb_config' => array( + 'bar_column' => array('UINT', 1), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + 'phpbb_config' => array( + 'bar_column', + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('foobartest', 0)), + ); + } +} diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php new file mode 100644 index 0000000000..f6820dbf3f --- /dev/null +++ b/tests/dbal/migration/revert_with_dependency.php @@ -0,0 +1,16 @@ +db_tools->sql_column_remove('phpbb_config', 'extra_column'); } public function test_if() @@ -150,4 +154,54 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertSame(10, $migrator_test_call_input); } + + public function test_revert() + { + // Make sure there are no other migrations in the db, this could cause issues + $this->db->sql_query("DELETE FROM phpbb_migrations"); + $this->migrator->load_migration_state(); + + $this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency')); + + $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + + // Install the migration first + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->migration_installed('phpbb_dbal_migration_revert')); + $this->assertTrue($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + + $this->assertSqlResultEquals( + array(array('bar_column' => '1')), + "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", + 'Installing revert migration failed to create bar_column.' + ); + + $this->assertTrue(isset($this->config['foobartest'])); + + while ($this->migrator->migration_installed('phpbb_dbal_migration_revert')) + { + $this->migrator->revert('phpbb_dbal_migration_revert'); + } + + $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + + $this->assertFalse(isset($this->config['foobartest'])); + + try + { + // Should cause an error + $this->assertSqlResultEquals( + false, + "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", + 'Revert did not remove bar_column.' + ); + } + catch (Exception $e) {} + } }