aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dbal')
-rw-r--r--tests/dbal/fixtures/migrator.xml29
-rw-r--r--tests/dbal/fixtures/migrator_module.xml42
-rw-r--r--tests/dbal/fixtures/migrator_permission.xml31
-rw-r--r--tests/dbal/migration/dummy.php27
-rw-r--r--tests/dbal/migration/fail.php41
-rw-r--r--tests/dbal/migration/if.php44
-rw-r--r--tests/dbal/migration/installed.php30
-rw-r--r--tests/dbal/migration/recall.php38
-rw-r--r--tests/dbal/migration/revert.php40
-rw-r--r--tests/dbal/migration/revert_with_dependency.php16
-rw-r--r--tests/dbal/migration/unfulfillable.php26
-rw-r--r--tests/dbal/migrator_test.php257
-rw-r--r--tests/dbal/migrator_tool_config_test.php124
-rw-r--r--tests/dbal/migrator_tool_module.php150
-rw-r--r--tests/dbal/migrator_tool_permission.php159
15 files changed, 1054 insertions, 0 deletions
diff --git a/tests/dbal/fixtures/migrator.xml b/tests/dbal/fixtures/migrator.xml
new file mode 100644
index 0000000000..25be4d4129
--- /dev/null
+++ b/tests/dbal/fixtures/migrator.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_migrations">
+ <column>migration_name</column>
+ <column>migration_depends_on</column>
+ <column>migration_schema_done</column>
+ <column>migration_data_done</column>
+ <column>migration_data_state</column>
+ <column>migration_start_time</column>
+ <column>migration_end_time</column>
+ <row>
+ <value>installed_migration</value>
+ <value></value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>1234</value>
+ <value>5678</value>
+ </row>
+ </table>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <row>
+ <value>foo</value>
+ <value>bar</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/dbal/fixtures/migrator_module.xml b/tests/dbal/fixtures/migrator_module.xml
new file mode 100644
index 0000000000..32afe7e6f3
--- /dev/null
+++ b/tests/dbal/fixtures/migrator_module.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_modules">
+ <column>module_id</column>
+ <column>module_enabled</column>
+ <column>module_display</column>
+ <column>module_basename</column>
+ <column>module_class</column>
+ <column>parent_id</column>
+ <column>left_id</column>
+ <column>right_id</column>
+ <column>module_langname</column>
+ <column>module_mode</column>
+ <column>module_auth</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>1</value>
+ <value></value>
+ <value>acp</value>
+ <value>0</value>
+ <value>1</value>
+ <value>4</value>
+ <value>ACP_CAT</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>1</value>
+ <value>acp_test</value>
+ <value>acp</value>
+ <value>1</value>
+ <value>2</value>
+ <value>3</value>
+ <value>ACP_MODULE</value>
+ <value>test</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/dbal/fixtures/migrator_permission.xml b/tests/dbal/fixtures/migrator_permission.xml
new file mode 100644
index 0000000000..08cec42a42
--- /dev/null
+++ b/tests/dbal/fixtures/migrator_permission.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_acl_options">
+ <column>auth_option_id</column>
+ <column>auth_option</column>
+ <column>is_global</column>
+ <column>is_local</column>
+ <column>founder_only</column>
+ <row>
+ <value>1</value>
+ <value>global</value>
+ <value>1</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>local</value>
+ <value>0</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>both</value>
+ <value>1</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php
new file mode 100644
index 0000000000..0ac6e733a1
--- /dev/null
+++ b/tests/dbal/migration/dummy.php
@@ -0,0 +1,27 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_dbal_migration_dummy extends phpbb_db_migration
+{
+ static public function depends_on()
+ {
+ return array('installed_migration');
+ }
+
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ 'phpbb_config' => array(
+ 'extra_column' => array('UINT', 1),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php
new file mode 100644
index 0000000000..f88d8169f5
--- /dev/null
+++ b/tests/dbal/migration/fail.php
@@ -0,0 +1,41 @@
+<?php
+/**
+*
+* @package migration
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
+*
+*/
+
+class phpbb_dbal_migration_fail extends phpbb_db_migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ $this->table_prefix . 'config' => array(
+ 'test_column' => array('BOOL', 1),
+ ),
+ ),
+ );
+ }
+
+ function revert_schema()
+ {
+ return array(
+ 'drop_columns' => array(
+ $this->table_prefix . 'config' => array(
+ 'test_column',
+ ),
+ ),
+ );
+ }
+
+ function update_data()
+ {
+ return array(
+ array('config.add', array('foobar3', true)),
+ array('config.update', array('does_not_exist', true)),
+ );
+ }
+}
diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php
new file mode 100644
index 0000000000..83fe21bd21
--- /dev/null
+++ b/tests/dbal/migration/if.php
@@ -0,0 +1,44 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_dbal_migration_if extends phpbb_db_migration
+{
+ function update_schema()
+ {
+ return array();
+ }
+
+ function update_data()
+ {
+ return array(
+ array('if', array(
+ true,
+ array('custom', array(array(&$this, 'test_true'))),
+ )),
+ array('if', array(
+ false,
+ array('custom', array(array(&$this, 'test_false'))),
+ )),
+ );
+ }
+
+ function test_true()
+ {
+ global $migrator_test_if_true_failed;
+
+ $migrator_test_if_true_failed = false;
+ }
+
+ function test_false()
+ {
+ global $migrator_test_if_false_failed;
+
+ $migrator_test_if_false_failed = true;
+ }
+}
diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php
new file mode 100644
index 0000000000..01829f7a99
--- /dev/null
+++ b/tests/dbal/migration/installed.php
@@ -0,0 +1,30 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_dbal_migration_installed extends phpbb_db_migration
+{
+ function effectively_installed()
+ {
+ return true;
+ }
+
+ function update_data()
+ {
+ return array(
+ array('custom', array(array(&$this, 'test'))),
+ );
+ }
+
+ function test()
+ {
+ global $migrator_test_installed_failed;
+
+ $migrator_test_installed_failed = true;
+ }
+}
diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php
new file mode 100644
index 0000000000..6c2f04bf08
--- /dev/null
+++ b/tests/dbal/migration/recall.php
@@ -0,0 +1,38 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_dbal_migration_recall extends phpbb_db_migration
+{
+ function update_schema()
+ {
+ return array();
+ }
+
+ function update_data()
+ {
+ return array(
+ array('custom', array(array(&$this, 'test_call'))),
+ );
+ }
+
+ // This function should be called 10 times
+ function test_call($input)
+ {
+ global $migrator_test_call_input;
+
+ $migrator_test_call_input = (int) $input;
+
+ if ($migrator_test_call_input < 10)
+ {
+ return ($migrator_test_call_input + 1);
+ }
+
+ return;
+ }
+}
diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php
new file mode 100644
index 0000000000..ac01987cd4
--- /dev/null
+++ b/tests/dbal/migration/revert.php
@@ -0,0 +1,40 @@
+<?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 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..ca2c070e8c
--- /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
+{
+ static public function depends_on()
+ {
+ return array('phpbb_dbal_migration_revert');
+ }
+}
diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php
new file mode 100644
index 0000000000..6d375e6880
--- /dev/null
+++ b/tests/dbal/migration/unfulfillable.php
@@ -0,0 +1,26 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration
+{
+ static public function depends_on()
+ {
+ return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration');
+ }
+
+ function update_schema()
+ {
+ trigger_error('Schema update of migration with unfulfillable dependency was run!');
+ }
+
+ function update_data()
+ {
+ trigger_error('Data update of migration with unfulfillable dependency was run!');
+ }
+}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
new file mode 100644
index 0000000000..9460e76f37
--- /dev/null
+++ b/tests/dbal/migrator_test.php
@@ -0,0 +1,257 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
+
+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';
+require_once dirname(__FILE__) . '/migration/fail.php';
+require_once dirname(__FILE__) . '/migration/installed.php';
+
+class phpbb_dbal_migrator_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $db_tools;
+ protected $migrator;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ $this->db_tools = new phpbb_db_tools($this->db);
+
+ $this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config');
+
+ $tools = array(
+ new phpbb_db_migration_tool_config($this->config),
+ );
+ $this->migrator = new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools);
+ }
+
+ public function test_update()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy'));
+
+ // schema
+ $this->migrator->update();
+ $this->assertFalse($this->migrator->finished());
+
+ $this->assertSqlResultEquals(
+ array(array('success' => '1')),
+ "SELECT 1 as success
+ FROM phpbb_migrations
+ WHERE migration_name = 'phpbb_dbal_migration_dummy'
+ AND migration_start_time >= " . (time() - 1) . "
+ AND migration_start_time <= " . (time() + 1),
+ 'Start time set correctly'
+ );
+
+ // data
+ $this->migrator->update();
+ $this->assertTrue($this->migrator->finished());
+
+ $this->assertSqlResultEquals(
+ array(array('extra_column' => '1')),
+ "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
+ 'Dummy migration created extra_column with value 1 in all rows.'
+ );
+
+ $this->assertSqlResultEquals(
+ array(array('success' => '1')),
+ "SELECT 1 as success
+ FROM phpbb_migrations
+ WHERE migration_name = 'phpbb_dbal_migration_dummy'
+ AND migration_start_time <= migration_end_time
+ AND migration_end_time >= " . (time() - 1) . "
+ AND migration_end_time <= " . (time() + 1),
+ 'End time set correctly'
+ );
+
+ // cleanup
+ $this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
+ }
+
+ public function test_unfulfillable()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy'));
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->finished());
+
+ $this->assertSqlResultEquals(
+ array(array('extra_column' => '1')),
+ "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()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_if'));
+
+ // Don't like this, but I'm not sure there is any other way to do this
+ global $migrator_test_if_true_failed, $migrator_test_if_false_failed;
+ $migrator_test_if_true_failed = true;
+ $migrator_test_if_false_failed = false;
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ if ($migrator_test_if_true_failed)
+ {
+ $this->fail('True test failed');
+ }
+
+ if ($migrator_test_if_false_failed)
+ {
+ $this->fail('False test failed');
+ }
+ }
+
+ public function test_recall()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_recall'));
+
+ global $migrator_test_call_input;
+
+ // Run the schema first
+ $this->migrator->update();
+
+ $i = 0;
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+
+ $this->assertSame($i, $migrator_test_call_input);
+
+ $i++;
+ }
+
+ $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_state('phpbb_dbal_migration_revert'));
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency'));
+
+ // Install the migration first
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false);
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency') !== false);
+
+ $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_state('phpbb_dbal_migration_revert') !== false)
+ {
+ $this->migrator->revert('phpbb_dbal_migration_revert');
+ }
+
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert'));
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency'));
+
+ $this->assertFalse(isset($this->config['foobartest']));
+
+ $sql = 'SELECT * FROM phpbb_config';
+ $result = $this->db->sql_query_limit($sql, 1);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ if (isset($row['bar_column']))
+ {
+ $this->fail('Revert did not remove test_column.');
+ }
+ }
+
+ public function test_fail()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_fail'));
+
+ $this->assertFalse(isset($this->config['foobar3']));
+
+ try
+ {
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+ }
+ catch (phpbb_db_migration_exception $e) {}
+
+ // Failure should have caused an automatic roll-back, so this should not exist.
+ $this->assertFalse(isset($this->config['foobar3']));
+
+ $sql = 'SELECT * FROM phpbb_config';
+ $result = $this->db->sql_query_limit($sql, 1);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
+
+ if (isset($row['test_column']))
+ {
+ $this->fail('Revert did not remove test_column.');
+ }
+ }
+
+ public function test_installed()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_installed'));
+
+ global $migrator_test_installed_failed;
+ $migrator_test_installed_failed = false;
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_installed') !== false);
+
+ if ($migrator_test_installed_failed)
+ {
+ $this->fail('Installed test failed');
+ }
+ }
+}
diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php
new file mode 100644
index 0000000000..7d582f230b
--- /dev/null
+++ b/tests/dbal/migrator_tool_config_test.php
@@ -0,0 +1,124 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
+
+class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case
+{
+ public function setup()
+ {
+ $this->config = new phpbb_config(array());
+
+ $this->tool = new phpbb_db_migration_tool_config($this->config);
+
+ parent::setup();
+ }
+
+ public function test_add()
+ {
+ try
+ {
+ $this->tool->add('foo', 'bar');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals('bar', $this->config['foo']);
+
+ try
+ {
+ $this->tool->add('foo', 'bar');
+ $this->fail('Exception not thrown');
+ }
+ catch (Exception $e) {}
+ }
+
+ public function test_update()
+ {
+ $this->config->set('foo', 'bar');
+ try
+ {
+ $this->tool->update('foo', 'bar2');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals('bar2', $this->config['foo']);
+ }
+
+ public function test_update_if_equals()
+ {
+ $this->config->set('foo', 'bar');
+
+ try
+ {
+ $this->tool->update_if_equals('', 'foo', 'bar2');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals('bar', $this->config['foo']);
+
+ try
+ {
+ $this->tool->update_if_equals('bar', 'foo', 'bar2');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals('bar2', $this->config['foo']);
+ }
+
+ public function test_remove()
+ {
+ $this->config->set('foo', 'bar');
+
+ try
+ {
+ $this->tool->remove('foo');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertFalse(isset($this->config['foo']));
+ }
+
+ public function test_reverse()
+ {
+ $this->config->set('foo', 'bar');
+
+ try
+ {
+ $this->tool->reverse('add', 'foo');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertFalse(isset($this->config['foo']));
+
+ $this->config->set('foo', 'bar');
+
+ try
+ {
+ $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals('test', $this->config['foo']);
+ }
+}
diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php
new file mode 100644
index 0000000000..6937b6f8c5
--- /dev/null
+++ b/tests/dbal/migrator_tool_module.php
@@ -0,0 +1,150 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
+
+class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml');
+ }
+
+ public function setup()
+ {
+ // Need global $db, $user for delete_module function in acp_modules
+ global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user;
+
+ parent::setup();
+
+ // Force add_log function to not be used
+ $skip_add_log = true;
+
+ $db = $this->db = $this->new_dbal();
+ $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx);
+ $user = $this->user = new phpbb_user();
+
+ $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules');
+ }
+
+ public function exists_data()
+ {
+ return array(
+ // Test the category
+ array(
+ '',
+ 'ACP_CAT',
+ true,
+ ),
+ array(
+ 0,
+ 'ACP_CAT',
+ true,
+ ),
+
+ // Test the module
+ array(
+ '',
+ 'ACP_MODULE',
+ false,
+ ),
+ array(
+ false,
+ 'ACP_MODULE',
+ true,
+ ),
+ array(
+ 'ACP_CAT',
+ 'ACP_MODULE',
+ true,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider exists_data
+ */
+ public function test_exists($parent, $module, $expected)
+ {
+ $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module));
+ }
+
+ public function test_add()
+ {
+ try
+ {
+ $this->tool->add('acp', 0, 'ACP_NEW_CAT');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
+
+ // Should throw an exception when trying to add a module that already exists
+ try
+ {
+ $this->tool->add('acp', 0, 'ACP_NEW_CAT');
+ $this->fail('Exception not thrown');
+ }
+ catch (Exception $e) {}
+
+ try
+ {
+ $this->tool->add('acp', 'ACP_NEW_CAT', array(
+ 'module_basename' => 'acp_new_module',
+ 'module_langname' => 'ACP_NEW_MODULE',
+ 'module_mode' => 'test',
+ 'module_auth' => '',
+ ));
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE'));
+ }
+
+ public function test_remove()
+ {
+ try
+ {
+ $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE'));
+ }
+
+ public function test_reverse()
+ {
+ try
+ {
+ $this->tool->add('acp', 0, 'ACP_NEW_CAT');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+
+ try
+ {
+ $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT');
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
+ }
+}
diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php
new file mode 100644
index 0000000000..438ab2b28e
--- /dev/null
+++ b/tests/dbal/migrator_tool_permission.php
@@ -0,0 +1,159 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
+
+class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml');
+ }
+
+ public function setup()
+ {
+ // Global $db and $cache are needed in acp/auth.php constructor
+ global $phpbb_root_path, $phpEx, $db, $cache;
+
+ parent::setup();
+
+ $db = $this->db = $this->new_dbal();
+ $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx);
+ $this->auth = new phpbb_auth();
+
+ $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx);
+ }
+
+ public function exists_data()
+ {
+ return array(
+ array(
+ 'global',
+ true,
+ true,
+ ),
+ array(
+ 'local',
+ false,
+ true,
+ ),
+ array(
+ 'both',
+ true,
+ true,
+ ),
+ array(
+ 'both',
+ false,
+ true,
+ ),
+ array(
+ 'does_not_exist',
+ true,
+ false,
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider exists_data
+ */
+ public function test_exists($auth_option, $global, $expected)
+ {
+ $this->assertEquals($expected, $this->tool->exists($auth_option, $global));
+ }
+
+ public function test_add()
+ {
+ try
+ {
+ $this->tool->add('new', true);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('new', true));
+ $this->assertEquals(false, $this->tool->exists('new', false));
+
+ try
+ {
+ $this->tool->add('new', false);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('new', false));
+
+ // Should fail (duplicate)
+ try
+ {
+ $this->tool->add('new', true);
+ $this->fail('Did not throw exception on duplicate');
+ }
+ catch (Exception $e) {}
+ }
+
+ public function test_remove()
+ {
+ try
+ {
+ $this->tool->remove('global', true);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(false, $this->tool->exists('global', true));
+
+ try
+ {
+ $this->tool->remove('both', false);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(false, $this->tool->exists('both', false));
+
+ // Should fail (does not exist)
+ try
+ {
+ $this->tool->remove('new', true);
+ $this->fail('Did not throw exception on duplicate');
+ }
+ catch (Exception $e) {}
+ }
+
+ public function test_reverse()
+ {
+ try
+ {
+ $this->tool->reverse('remove', 'global_test', true);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertTrue($this->tool->exists('global_test', true));
+
+ try
+ {
+ $this->tool->reverse('add', 'global_test', true);
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertFalse($this->tool->exists('global_test', true));
+ }
+}