1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-25 11:01:48 +02:00

Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/11103

# By Nathan Guse (28) and others
# Via Andreas Fischer (9) and others
* 'develop' of https://github.com/phpbb/phpbb3: (90 commits)
  [ticket/11350] Do not pass $db by reference; typehint phpbb_db_driver
  [feature/migrations] Remove default values from necessary parameters
  [ticket/11201] Revert WLM dropping because it is still used in China.
  [ticket/11220] Improvement to the info pop-up from "list="
  [feature/migrations] Revert unrelated changes to functions.php
  [ticket/11233] prohibit selecting anonymous user as a PM recipient
  [ticket/11343] Remove spare parentheses.
  [ticket/11343] Remove spare space.
  [ticket/11343] Use === when checking stored user_actkey against user input.
  [ticket/11295] Correct cases: replace postgres with phpbb_db_driver_postgres.
  [ticket/10050] removing prosilver edits
  [ticket/9737] Fix some comments
  [ticket/11337] Abort setup-webserver.sh script when an error occurs.
  [ticket/11337] Only run functional tests on 5.3.19 or higher. No FPM otherwise.
  [ticket/11337] Silence nginx config file writing.
  [ticket/11337] php-fpm.conf is no longer owned by root.
  [ticket/11337] Run functional tests on travis using nginx and php-fpm.
  [ticket/11338] Travis CI: Install PHP extension for redis key-value store.
  [ticket/10050] adding .topicrow to template condition
  [ticket/9737] Fix a few minor things in migrations
  ...

Conflicts:
	phpBB/config/services.yml
	phpBB/config/tables.yml
This commit is contained in:
Nathaniel Guse
2013-02-11 21:37:15 -06:00
63 changed files with 4153 additions and 129 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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),
),
),
);
}
}

View File

@@ -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)),
);
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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)),
);
}
}

View File

@@ -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');
}
}

View File

@@ -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!');
}
}

View File

@@ -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');
}
}
}

View File

@@ -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']);
}
}

View File

@@ -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'));
}
}

View File

@@ -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));
}
}

View File

@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_groups">
<column>group_id</column>
<column>group_avatar</column>
<column>group_rank</column>
<column>group_desc</column>
<row>
<value>1</value>
<value>default</value>
<value>1</value>
<value></value>
</row>
<row>
<value>2</value>
<value></value>
<value>0</value>
<value></value>
</row>
<row>
<value>3</value>
<value>default2</value>
<value>3</value>
<value></value>
</row>
</table>
<table name="phpbb_users">
<column>user_id</column>
<column>group_id</column>
<column>user_avatar</column>
<column>user_rank</column>
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
<column>user_occ</column>
<column>user_interests</column>
<row>
<value>1</value>
<value>1</value>
<value></value>
<value>0</value>
<value>barfoo</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
<row>
<value>2</value>
<value>1</value>
<value>default</value>
<value>1</value>
<value>foobar</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
<row>
<value>3</value>
<value>1</value>
<value>custom</value>
<value>2</value>
<value>bertie</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
</table>
<table name="phpbb_user_group">
<column>user_id</column>
<column>group_id</column>
<column>user_pending</column>
<row>
<value>1</value>
<value>1</value>
<value>0</value>
</row>
<row>
<value>1</value>
<value>2</value>
<value>0</value>
</row>
<row>
<value>1</value>
<value>3</value>
<value>0</value>
</row>
<row>
<value>2</value>
<value>1</value>
<value>0</value>
</row>
<row>
<value>2</value>
<value>2</value>
<value>0</value>
</row>
<row>
<value>2</value>
<value>3</value>
<value>0</value>
</row>
<row>
<value>3</value>
<value>1</value>
<value>0</value>
</row>
<row>
<value>3</value>
<value>2</value>
<value>0</value>
</row>
<row>
<value>3</value>
<value>3</value>
<value>0</value>
</row>
</table>
</dataset>

View File

@@ -0,0 +1,156 @@
<?php
/**
*
* @package testing
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_functions_user_group_user_attributes_test extends phpbb_database_test_case
{
public function getDataSet()
{
return $this->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, $phpbb_container;
$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');
$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);
$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);
}
}

View File

@@ -186,6 +186,16 @@ class phpbb_database_test_connection_manager
$this->purge_extras();
break;
case 'phpbb_db_driver_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);
@@ -418,6 +428,19 @@ class phpbb_database_test_connection_manager
$queries[] = 'DROP SEQUENCE ' . current($row);
}
break;
case 'phpbb_db_driver_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)