From 02a1777fcbc550b4d91aaa585cffa9c052e4c525 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 26 Dec 2012 00:30:20 -0500 Subject: [ticket/11295] Drop tables rather than database for postgres in test suite. Doing so allows: 1. User running the tests no longer needs create database privilege. 2. Test database may be located in a non-default tablespace and generally have site-specific options applied to it. PHPBB3-11295 --- .../phpbb_database_test_connection_manager.php | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index d7c2804aa7..3b8c2e99ae 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -186,6 +186,16 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; + case 'postgres': + $this->connect(); + // Drop all of the tables + foreach ($this->get_tables() as $table) + { + $this->pdo->exec('DROP TABLE ' . $table . ' CASCADE'); + } + $this->purge_extras(); + break; + default: $this->connect(false); @@ -293,7 +303,7 @@ class phpbb_database_test_connection_manager protected function load_schema_from_file($directory) { $schema = $this->dbms['SCHEMA']; - + if ($this->config['dbms'] == 'mysql') { $sth = $this->pdo->query('SELECT VERSION() AS version'); @@ -313,7 +323,7 @@ class phpbb_database_test_connection_manager $queries = file_get_contents($filename); $sql = phpbb_remove_comments($queries); - + $sql = split_sql_file($sql, $this->dbms['DELIM']); foreach ($sql as $query) @@ -419,6 +429,19 @@ class phpbb_database_test_connection_manager $queries[] = 'DROP SEQUENCE ' . current($row); } break; + + case 'postgres': + $sql = 'SELECT sequence_name + FROM information_schema.sequences'; + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_NUM)) + { + $queries[] = 'DROP SEQUENCE ' . current($row); + } + + $queries[] = 'DROP TYPE IF EXISTS varchar_ci CASCADE'; + break; } foreach ($queries as $query) -- cgit v1.2.1 From f817e20f287a21e2dddfba9721f5e02dce162d29 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 15 Jul 2011 11:57:53 -0400 Subject: [feature/migrations] Basic migrations with schema and data changes The migrator takes care of applying migrations as necessary. RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41337 PHPBB3-9737 --- tests/dbal/fixtures/migrator.xml | 27 ++++++++++++ tests/dbal/migration/dummy.php | 26 +++++++++++ tests/dbal/migration/unfulfillable.php | 26 +++++++++++ tests/dbal/migrator_test.php | 80 ++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 tests/dbal/fixtures/migrator.xml create mode 100644 tests/dbal/migration/dummy.php create mode 100644 tests/dbal/migration/unfulfillable.php create mode 100644 tests/dbal/migrator_test.php (limited to 'tests') diff --git a/tests/dbal/fixtures/migrator.xml b/tests/dbal/fixtures/migrator.xml new file mode 100644 index 0000000000..1f9079c811 --- /dev/null +++ b/tests/dbal/fixtures/migrator.xml @@ -0,0 +1,27 @@ + + + + migration_name + migration_schema_done + migration_data_done + migration_data_state + migration_start_time + migration_end_time + + installed_migration + 1 + 1 + + 1234 + 5678 + +
+ + config_name + config_value + + foo + bar + +
+
diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php new file mode 100644 index 0000000000..b286d44f77 --- /dev/null +++ b/tests/dbal/migration/dummy.php @@ -0,0 +1,26 @@ +db_column_add('phpbb_config', 'extra_column', array('UINT', 0)); + } + + function update_data() + { + $this->db->sql_query('UPDATE phpbb_config SET extra_column = 1'); + } +} diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php new file mode 100644 index 0000000000..84136ffe6d --- /dev/null +++ b/tests/dbal/migration/unfulfillable.php @@ -0,0 +1,26 @@ +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->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE); + } + + public function test_update() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy')); + + // schema + $this->migrator->update(); + $this->assertFalse($this->migrator->finished()); + + // 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.' + ); + + // 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.' + ); + + // cleanup + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } +} -- cgit v1.2.1 From d304b6449db6e7c6f3c9058062aca0c641f023a4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 7 Aug 2011 19:10:38 -0400 Subject: [feature/migrations] Store start and end time of migrations PHPBB3-9737 --- tests/dbal/migrator_test.php | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 1e7d1343fc..dd194d7c05 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -26,7 +26,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml'); } - public function setup() + public function setUp() { parent::setup(); @@ -35,6 +35,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE); } + public function tearDown() + { + // cleanup + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } + public function test_update() { $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy')); @@ -43,6 +49,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $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()); @@ -53,8 +69,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'Dummy migration created extra_column with value 1 in all rows.' ); - // cleanup - $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + $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' + ); } public function test_unfulfillable() @@ -73,8 +97,5 @@ 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.' ); - - // cleanup - $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); } } -- cgit v1.2.1 From 8645321f40d0b13de6201688c69f9f05bc649dcf Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 12:26:44 -0700 Subject: [feature/migrations] Return schema changes in database update style array Returning the set of schema changes allows potentially aggregating to generate the overall install schema automatically from a set of migrations PHPBB3-9737 --- tests/dbal/migration/dummy.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index b286d44f77..0567b50740 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -16,7 +16,13 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration function update_schema() { - $this->db_column_add('phpbb_config', 'extra_column', array('UINT', 0)); + return array( + 'add_columns' => array( + 'phpbb_config' => array( + 'extra_column' => array('UINT', 0), + ), + ), + ); } function update_data() -- cgit v1.2.1 From c802f2a66c577781036b7bfd6d6689159028c3a6 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 13:02:56 -0700 Subject: [feature/migrations] Standard vars for migrations and run sql with feedback PHPBB3-9737 --- tests/dbal/migrator_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index dd194d7c05..898a197dfd 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -32,7 +32,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->db_tools = new phpbb_db_tools($this->db); - $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE); + $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, 'phpbb_', MIGRATIONS_TABLE, 'phpBB/', '.php'); } public function tearDown() -- cgit v1.2.1 From 41de95bc11c0b64eafa294f03432f619d3d712d5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 12:12:05 +0100 Subject: [feature/migrations] Process migration steps and move to PHP5 code --- tests/dbal/migration/dummy.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index 0567b50740..942c499bb5 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -27,6 +27,13 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration function update_data() { - $this->db->sql_query('UPDATE phpbb_config SET extra_column = 1'); + return array( + array('if', array(true, array('custom', array(array($this, 'set_extra_column'))))), + ); + } + + public function set_extra_column() + { + $this->sql_query('UPDATE phpbb_config SET extra_column = 1'); } } -- cgit v1.2.1 From 5c91e2569cb3a400acd20bf06cc0e609dd63a778 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:09:14 -0600 Subject: [feature/migrations] Migrations now somewhat works PHPBB3-9737 --- tests/dbal/fixtures/migrator_module.xml | 42 +++++++++ tests/dbal/fixtures/migrator_permission.xml | 31 +++++++ tests/dbal/migrator_test.php | 12 ++- tests/dbal/migrator_tool_config_test.php | 97 ++++++++++++++++++++ tests/dbal/migrator_tool_module.php | 128 ++++++++++++++++++++++++++ tests/dbal/migrator_tool_permission.php | 136 ++++++++++++++++++++++++++++ 6 files changed, 443 insertions(+), 3 deletions(-) create mode 100644 tests/dbal/fixtures/migrator_module.xml create mode 100644 tests/dbal/fixtures/migrator_permission.xml create mode 100644 tests/dbal/migrator_tool_config_test.php create mode 100644 tests/dbal/migrator_tool_module.php create mode 100644 tests/dbal/migrator_tool_permission.php (limited to 'tests') 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 @@ + + + + module_id + module_enabled + module_display + module_basename + module_class + parent_id + left_id + right_id + module_langname + module_mode + module_auth + + 1 + 1 + 1 + + acp + 0 + 1 + 4 + ACP_CAT + + + + + 2 + 1 + 1 + acp_test + acp + 1 + 2 + 3 + ACP_MODULE + test + + +
+
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 @@ + + + + auth_option_id + auth_option + is_global + is_local + founder_only + + 1 + global + 1 + 0 + 0 + + + 2 + local + 0 + 1 + 0 + + + 3 + both + 1 + 1 + 0 + +
+
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 898a197dfd..463cf9fcec 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -9,7 +9,7 @@ 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.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'; @@ -28,11 +28,17 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case public function setUp() { - parent::setup(); + parent::setUp(); $this->db = $this->new_dbal(); $this->db_tools = new phpbb_db_tools($this->db); - $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, 'phpbb_', MIGRATIONS_TABLE, 'phpBB/', '.php'); + + $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 tearDown() diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php new file mode 100644 index 0000000000..27511519ca --- /dev/null +++ b/tests/dbal/migrator_tool_config_test.php @@ -0,0 +1,97 @@ +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'])); + } +} diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php new file mode 100644 index 0000000000..0b57cbfbcb --- /dev/null +++ b/tests/dbal/migrator_tool_module.php @@ -0,0 +1,128 @@ +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()); + $user = $this->user = new phpbb_user(); + + $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx); + } + + 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')); + } +} diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php new file mode 100644 index 0000000000..2229576cd9 --- /dev/null +++ b/tests/dbal/migrator_tool_permission.php @@ -0,0 +1,136 @@ +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()); + $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) {} + } +} -- cgit v1.2.1 From 445667a62e80c42b5406c981d1116ef99a23df3b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 16:31:56 -0600 Subject: [feature/migrations] Fix if method (and create a test for it) PHPBB3-9737 --- tests/dbal/migration/dummy.php | 14 +----------- tests/dbal/migration/if.php | 49 ++++++++++++++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 35 ++++++++++++++++++++++++------ 3 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 tests/dbal/migration/if.php (limited to 'tests') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index 942c499bb5..e542493f9f 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -19,21 +19,9 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration return array( 'add_columns' => array( 'phpbb_config' => array( - 'extra_column' => array('UINT', 0), + 'extra_column' => array('UINT', 1), ), ), ); } - - function update_data() - { - return array( - array('if', array(true, array('custom', array(array($this, 'set_extra_column'))))), - ); - } - - public function set_extra_column() - { - $this->sql_query('UPDATE phpbb_config SET extra_column = 1'); - } } diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php new file mode 100644 index 0000000000..aa9a5dab87 --- /dev/null +++ b/tests/dbal/migration/if.php @@ -0,0 +1,49 @@ +migrator = new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools); } - public function tearDown() - { - // cleanup - $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); - } - public function test_update() { $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy')); @@ -85,6 +80,9 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 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() @@ -104,4 +102,29 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'Dummy migration was run, even though an unfulfillable migration was found.' ); } + + 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'); + } + } } -- cgit v1.2.1 From 3d4c00619f1c96df7a4c6f8bc1c03eb21abf49d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:24:32 -0600 Subject: [feature/migrations] Reverse data functionality If data step fails, attempt to roll back any previous calls from the migration that failed. Fix some failing tests PHPBB3-9737 --- tests/dbal/migrator_tool_config_test.php | 27 +++++++++++++++++++++++++++ tests/dbal/migrator_tool_module.php | 28 +++++++++++++++++++++++++--- tests/dbal/migrator_tool_permission.php | 25 ++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index 27511519ca..7d582f230b 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -94,4 +94,31 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case } $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 index 0b57cbfbcb..6937b6f8c5 100644 --- a/tests/dbal/migrator_tool_module.php +++ b/tests/dbal/migrator_tool_module.php @@ -29,10 +29,10 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $skip_add_log = true; $db = $this->db = $this->new_dbal(); - $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null()); + $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); + $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); } public function exists_data() @@ -99,7 +99,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case try { - $this->tool->add('acp', ACP_NEW_CAT, array( + $this->tool->add('acp', 'ACP_NEW_CAT', array( 'module_basename' => 'acp_new_module', 'module_langname' => 'ACP_NEW_MODULE', 'module_mode' => 'test', @@ -125,4 +125,26 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case } $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 index 2229576cd9..438ab2b28e 100644 --- a/tests/dbal/migrator_tool_permission.php +++ b/tests/dbal/migrator_tool_permission.php @@ -26,7 +26,7 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case parent::setup(); $db = $this->db = $this->new_dbal(); - $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null()); + $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); @@ -133,4 +133,27 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case } 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)); + } } -- cgit v1.2.1 From ddb1eaab6868cfac70b7b202468cab29315b794d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 12:49:13 -0600 Subject: [feature/migrations] Test for calling a step multiple times This is used when a long-running process is needed during an update. For example, iterating over all posts and applying some transformation. This allows the process to be broken apart into multiple shorter steps to prevent hitting the time limit. PHPBB3-9737 --- tests/dbal/migration/recall.php | 43 +++++++++++++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 23 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/dbal/migration/recall.php (limited to 'tests') diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php new file mode 100644 index 0000000000..18d8b4a6d2 --- /dev/null +++ b/tests/dbal/migration/recall.php @@ -0,0 +1,43 @@ +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); + } } -- cgit v1.2.1 From 00385aa742da17678f7d147b6d71fa759fcd7e78 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 13:52:11 -0600 Subject: [feature/migrations] Basic reverting test PHPBB3-9737 --- tests/dbal/migration/revert.php | 45 +++++++++++++++++++++ tests/dbal/migration/revert_with_dependency.php | 16 ++++++++ tests/dbal/migrator_test.php | 54 +++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 tests/dbal/migration/revert.php create mode 100644 tests/dbal/migration/revert_with_dependency.php (limited to 'tests') 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) {} + } } -- cgit v1.2.1 From d50500860fe44a78c8f29e0f2382b96da17c0b62 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 15:09:51 -0600 Subject: [feature/migrations] Store depends on in the database (serialized) This is required so that when migrations are reverted we can check through all installed migrations and make sure that all dependencies are handled properly and so that we are only required to load the migrations files that could be dependent on the ones installed. I believe in normal proper use the old way might have worked, but in case something happens and an unrelated migration file is installed, but cannot be loaded, this makes sure we do not stop everything unless we absolutely must (one of those files is dependent on something we want to revert). PHPBB3-9737 --- tests/dbal/fixtures/migrator.xml | 2 ++ tests/dbal/migration/fail.php | 46 ++++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 57 ++++++++++++++++++++++++++++++---------- 3 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 tests/dbal/migration/fail.php (limited to 'tests') diff --git a/tests/dbal/fixtures/migrator.xml b/tests/dbal/fixtures/migrator.xml index 1f9079c811..25be4d4129 100644 --- a/tests/dbal/fixtures/migrator.xml +++ b/tests/dbal/fixtures/migrator.xml @@ -2,6 +2,7 @@ migration_name + migration_depends_onmigration_schema_donemigration_data_donemigration_data_state @@ -9,6 +10,7 @@ migration_end_time installed_migration + 1 1 diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php new file mode 100644 index 0000000000..8b5c521e09 --- /dev/null +++ b/tests/dbal/migration/fail.php @@ -0,0 +1,46 @@ + 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/migrator_test.php b/tests/dbal/migrator_test.php index 84bcb109b2..69db7ca047 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -18,6 +18,7 @@ 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'; class phpbb_dbal_migrator_test extends phpbb_database_test_case { @@ -163,8 +164,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $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')); + $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()) @@ -172,8 +173,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $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->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')), @@ -183,25 +184,53 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertTrue(isset($this->config['foobartest'])); - while ($this->migrator->migration_installed('phpbb_dbal_migration_revert')) + while ($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false) { $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($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 { - // Should cause an error - $this->assertSqlResultEquals( - false, - "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", - 'Revert did not remove bar_column.' - ); + 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.'); } - catch (Exception $e) {} } } -- cgit v1.2.1 From 9f38dc67a80b5fc2a8bb0d01825d7655915e3319 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 22:48:31 -0600 Subject: [feature/migrations] Make the test depends_on methods static PHPBB3-11318 --- tests/dbal/migration/dummy.php | 2 +- tests/dbal/migration/fail.php | 5 ----- tests/dbal/migration/if.php | 5 ----- tests/dbal/migration/recall.php | 5 ----- tests/dbal/migration/revert.php | 5 ----- tests/dbal/migration/revert_with_dependency.php | 2 +- tests/dbal/migration/unfulfillable.php | 2 +- 7 files changed, 3 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index e542493f9f..0ac6e733a1 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -9,7 +9,7 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('installed_migration'); } diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php index 8b5c521e09..f88d8169f5 100644 --- a/tests/dbal/migration/fail.php +++ b/tests/dbal/migration/fail.php @@ -9,11 +9,6 @@ class phpbb_dbal_migration_fail extends phpbb_db_migration { - function depends_on() - { - return array(); - } - function update_schema() { return array( diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php index aa9a5dab87..83fe21bd21 100644 --- a/tests/dbal/migration/if.php +++ b/tests/dbal/migration/if.php @@ -9,11 +9,6 @@ class phpbb_dbal_migration_if extends phpbb_db_migration { - function depends_on() - { - return array(); - } - function update_schema() { return array(); diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php index 18d8b4a6d2..6c2f04bf08 100644 --- a/tests/dbal/migration/recall.php +++ b/tests/dbal/migration/recall.php @@ -9,11 +9,6 @@ class phpbb_dbal_migration_recall extends phpbb_db_migration { - function depends_on() - { - return array(); - } - function update_schema() { return array(); diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index 2bb23e31c2..ac01987cd4 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -9,11 +9,6 @@ class phpbb_dbal_migration_revert extends phpbb_db_migration { - function depends_on() - { - return array(); - } - function update_schema() { return array( diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php index f6820dbf3f..ca2c070e8c 100644 --- a/tests/dbal/migration/revert_with_dependency.php +++ b/tests/dbal/migration/revert_with_dependency.php @@ -9,7 +9,7 @@ class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration { - function depends_on() + 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 index 84136ffe6d..6d375e6880 100644 --- a/tests/dbal/migration/unfulfillable.php +++ b/tests/dbal/migration/unfulfillable.php @@ -9,7 +9,7 @@ class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration'); } -- cgit v1.2.1 From 26c16559c3496f5496ad6e83e55c40f03edda5bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 12:39:08 -0600 Subject: [feature/migrations] Function effectively_installed() in migrations Allows you to check if the migration is effectively installed (entirely optionall) This function is intended to help moving to migrations from a previous database updater, where some migrations may have been installed already even though they are not yet listed in the migrations table. PHPBB3-9737 --- tests/dbal/migration/installed.php | 30 ++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 21 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/dbal/migration/installed.php (limited to 'tests') 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 @@ +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'); + } + } } -- cgit v1.2.1 From 90235754b3919eafcb47047a8aac0fa0f075087e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 13 Jan 2013 18:28:51 -0500 Subject: [ticket/11323] Backport include_define test to olympus. PHPBB3-11323 --- tests/template/template_test.php | 7 +++++++ tests/template/templates/include_define.html | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 tests/template/templates/include_define.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 9b3c6ac245..83af63cdd9 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -232,6 +232,13 @@ class phpbb_template_template_test extends phpbb_test_case array(), 'value', ), + array( + 'include_define.html', + array('VARIABLE' => 'value'), + array(), + array(), + 'value', + ), array( 'loop_vars.html', array(), diff --git a/tests/template/templates/include_define.html b/tests/template/templates/include_define.html new file mode 100644 index 0000000000..2419c8cba1 --- /dev/null +++ b/tests/template/templates/include_define.html @@ -0,0 +1,2 @@ + + -- cgit v1.2.1 From 50542a389cfb6189334ed704c1d5c984f3ddf76b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:35:37 +0100 Subject: [ticket/9492] Add unit tests for custom ranks and avatars PHPBB3-9492 --- .../fixtures/group_user_attributes.xml | 121 +++++++++++++++++ .../functions_user/group_user_attributes_test.php | 149 +++++++++++++++++++++ 2 files changed, 270 insertions(+) create mode 100644 tests/functions_user/fixtures/group_user_attributes.xml create mode 100644 tests/functions_user/group_user_attributes_test.php (limited to 'tests') diff --git a/tests/functions_user/fixtures/group_user_attributes.xml b/tests/functions_user/fixtures/group_user_attributes.xml new file mode 100644 index 0000000000..f4edbdca49 --- /dev/null +++ b/tests/functions_user/fixtures/group_user_attributes.xml @@ -0,0 +1,121 @@ + + +
+ group_id + group_avatar + group_rank + group_desc + + 1 + default + 1 + + + + 2 + + 0 + + + + 3 + default2 + 3 + + +
+ + user_id + group_id + user_avatar + user_rank + username_clean + user_permissions + user_sig + user_occ + user_interests + + 1 + 1 + + 0 + barfoo + + + + + + + 2 + 1 + default + 1 + foobar + + + + + + + 3 + 1 + custom + 2 + bertie + + + + + +
+ + user_id + group_id + user_pending + + 1 + 1 + 0 + + + 1 + 2 + 0 + + + 1 + 3 + 0 + + + 2 + 1 + 0 + + + 2 + 2 + 0 + + + 2 + 3 + 0 + + + 3 + 1 + 0 + + + 3 + 2 + 0 + + + 3 + 3 + 0 + +
+
diff --git a/tests/functions_user/group_user_attributes_test.php b/tests/functions_user/group_user_attributes_test.php new file mode 100644 index 0000000000..35d0b9e348 --- /dev/null +++ b/tests/functions_user/group_user_attributes_test.php @@ -0,0 +1,149 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/group_user_attributes.xml'); + } + + public function group_user_attributes_data() + { + return array( + array( + 'Setting new default group without settings for user with no settings - no change', + 1, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => '', + 'user_rank' => 0, + ), + ), + array( + 'Setting new default group without settings for user with default settings - user settings overwritten', + 2, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => '', + 'user_rank' => 0, + ), + ), + array( + 'Setting new default group without settings for user with custom settings - no change', + 3, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => 'custom', + 'user_rank' => 2, + ), + ), + array( + 'Setting new default group with settings for user with no settings - user settings overwritten', + 1, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'default2', + 'user_rank' => 3, + ), + ), + array( + 'Setting new default group with settings for user with default settings - user settings overwritten', + 2, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'default2', + 'user_rank' => 3, + ), + ), + array( + 'Setting new default group with settings for user with custom settings - no change', + 3, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'custom', + 'user_rank' => 2, + ), + ), + ); + } + + /** + * @dataProvider group_user_attributes_data + */ + public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected) + { + global $auth, $cache, $db, $phpbb_dispatcher, $user; + + $user->ip = ''; + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_clear_prefetch'); + + group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row); + + $sql = 'SELECT user_avatar, user_rank + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . $user_id; + $result = $db->sql_query($sql); + + $this->assertEquals(array($expected), $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } +} -- cgit v1.2.1 From ddec4e00d54c3c6e409cdf005442d36ccd9cf120 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Jan 2013 20:59:27 +0100 Subject: [ticket/9492] Fix missing phpbb_container in unit tests PHPBB3-9492 --- tests/functions_user/group_user_attributes_test.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functions_user/group_user_attributes_test.php b/tests/functions_user/group_user_attributes_test.php index 35d0b9e348..f13156c2cc 100644 --- a/tests/functions_user/group_user_attributes_test.php +++ b/tests/functions_user/group_user_attributes_test.php @@ -125,7 +125,7 @@ class phpbb_functions_user_group_user_attributes_test extends phpbb_database_tes */ public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected) { - global $auth, $cache, $db, $phpbb_dispatcher, $user; + global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container; $user->ip = ''; $cache = new phpbb_mock_cache; @@ -134,6 +134,13 @@ class phpbb_functions_user_group_user_attributes_test extends phpbb_database_tes $auth = $this->getMock('phpbb_auth'); $auth->expects($this->any()) ->method('acl_clear_prefetch'); + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row); -- cgit v1.2.1 From 7203f39f87b7910d8565eccca2523313cacf828f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Jan 2013 17:10:43 +0100 Subject: [ticket/11295] Correct cases: replace postgres with phpbb_db_driver_postgres. PHPBB3-11295 --- tests/test_framework/phpbb_database_test_connection_manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index c9bdd185d6..29058cc815 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -186,7 +186,7 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; - case 'postgres': + case 'phpbb_db_driver_postgres': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -429,7 +429,7 @@ class phpbb_database_test_connection_manager } break; - case 'postgres': + case 'phpbb_db_driver_postgres': $sql = 'SELECT sequence_name FROM information_schema.sequences'; $result = $this->pdo->query($sql); -- cgit v1.2.1