aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/dbal/migration/revert.php45
-rw-r--r--tests/dbal/migration/revert_with_dependency.php16
-rw-r--r--tests/dbal/migrator_test.php54
3 files changed, 115 insertions, 0 deletions
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 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_dbal_migration_revert extends phpbb_db_migration
+{
+ function depends_on()
+ {
+ return array();
+ }
+
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => 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 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration
+{
+ function depends_on()
+ {
+ return array('phpbb_dbal_migration_revert');
+ }
+}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index 9c40eec15a..84bcb109b2 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -16,6 +16,8 @@ require_once dirname(__FILE__) . '/migration/dummy.php';
require_once dirname(__FILE__) . '/migration/unfulfillable.php';
require_once dirname(__FILE__) . '/migration/if.php';
require_once dirname(__FILE__) . '/migration/recall.php';
+require_once dirname(__FILE__) . '/migration/revert.php';
+require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
class phpbb_dbal_migrator_test extends phpbb_database_test_case
{
@@ -102,6 +104,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
'Dummy migration was run, even though an unfulfillable migration was found.'
);
+
+ $this->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) {}
+ }
}