mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/10714
* 'develop' of https://github.com/phpbb/phpbb3: (119 commits) [ticket/10986] message.id fallback to SERVER_NAME or phpbb.generated [ticket/11358] Changed the name of post parameter. [ticket/11358] Changed the action parameter value to represent the link. [ticket/11358] Enabled link making all users default for a group. [ticket/11358] Removed redundant code and referred proper variable. [ticket/11358] Success message even without selecting a user. [ticket/11355] Referred proper variable when validating selection. [ticket/11355] Wrong error message when no user is selected. [ticket/10896] Add missing email validation lost in develop merge [ticket/7262] Add note about set_config() not updating is_dynamic. [ticket/7262] Add $is_dynamic example to set_config() and set_config_count(). [ticket/7262] Backport set_config() and set_config_count() docs from develop. [ticket/11122] Move rxu to 'Former Contributors' section. [ticket/11122] Add EXreaction to docs/AUTHORS. [ticket/11298] Fix typo in language key; EXTENSIONS -> EXTENSION [ticket/11361] Make sure that array passed to strtr() has the proper format. [ticket/11179] remove extra & in function call [ticket/11179] correct start parameter in sphinx search [ticket/11179] correct start parameter in native author search [ticket/11179] correct start parameter in native keyword search ... Conflicts: phpBB/config/tables.yml
This commit is contained in:
29
tests/dbal/fixtures/migrator.xml
Normal file
29
tests/dbal/fixtures/migrator.xml
Normal 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>
|
42
tests/dbal/fixtures/migrator_module.xml
Normal file
42
tests/dbal/fixtures/migrator_module.xml
Normal 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>
|
31
tests/dbal/fixtures/migrator_permission.xml
Normal file
31
tests/dbal/fixtures/migrator_permission.xml
Normal 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>
|
27
tests/dbal/migration/dummy.php
Normal file
27
tests/dbal/migration/dummy.php
Normal 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),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
41
tests/dbal/migration/fail.php
Normal file
41
tests/dbal/migration/fail.php
Normal 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)),
|
||||
);
|
||||
}
|
||||
}
|
44
tests/dbal/migration/if.php
Normal file
44
tests/dbal/migration/if.php
Normal 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;
|
||||
}
|
||||
}
|
30
tests/dbal/migration/installed.php
Normal file
30
tests/dbal/migration/installed.php
Normal 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;
|
||||
}
|
||||
}
|
38
tests/dbal/migration/recall.php
Normal file
38
tests/dbal/migration/recall.php
Normal 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;
|
||||
}
|
||||
}
|
40
tests/dbal/migration/revert.php
Normal file
40
tests/dbal/migration/revert.php
Normal 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)),
|
||||
);
|
||||
}
|
||||
}
|
16
tests/dbal/migration/revert_with_dependency.php
Normal file
16
tests/dbal/migration/revert_with_dependency.php
Normal 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');
|
||||
}
|
||||
}
|
26
tests/dbal/migration/unfulfillable.php
Normal file
26
tests/dbal/migration/unfulfillable.php
Normal 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!');
|
||||
}
|
||||
}
|
257
tests/dbal/migrator_test.php
Normal file
257
tests/dbal/migrator_test.php
Normal 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');
|
||||
}
|
||||
}
|
||||
}
|
124
tests/dbal/migrator_tool_config_test.php
Normal file
124
tests/dbal/migrator_tool_config_test.php
Normal 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']);
|
||||
}
|
||||
}
|
150
tests/dbal/migrator_tool_module.php
Normal file
150
tests/dbal/migrator_tool_module.php
Normal 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'));
|
||||
}
|
||||
}
|
159
tests/dbal/migrator_tool_permission.php
Normal file
159
tests/dbal/migrator_tool_permission.php
Normal 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));
|
||||
}
|
||||
}
|
@@ -25,14 +25,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->extension_manager = new phpbb_extension_manager(
|
||||
$this->new_dbal(),
|
||||
new phpbb_config(array()),
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.php',
|
||||
new phpbb_mock_cache
|
||||
);
|
||||
$this->extension_manager = $this->create_extension_manager();
|
||||
}
|
||||
|
||||
public function test_available()
|
||||
@@ -89,15 +82,30 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
|
||||
public function test_enabled_no_cache()
|
||||
{
|
||||
$extension_manager = new phpbb_extension_manager(
|
||||
$this->new_dbal(),
|
||||
new phpbb_config(array()),
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.php'
|
||||
);
|
||||
$extension_manager = $this->create_extension_manager(false);
|
||||
|
||||
$this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled()));
|
||||
}
|
||||
|
||||
protected function create_extension_manager($with_cache = true)
|
||||
{
|
||||
|
||||
$config = new phpbb_config(array());
|
||||
$db = $this->new_dbal();
|
||||
$db_tools = new phpbb_db_tools($db);
|
||||
$phpbb_root_path = __DIR__ . './../../phpBB/';
|
||||
$php_ext = 'php';
|
||||
$table_prefix = 'phpbb_';
|
||||
|
||||
return new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$db,
|
||||
$config,
|
||||
new phpbb_db_migrator($config, $db, $db_tools, 'phpbb_migrations', $phpbb_root_path, $php_ext, $table_prefix, array()),
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.' . $php_ext,
|
||||
($with_cache) ? new phpbb_mock_cache() : null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -34,9 +34,11 @@ class metadata_manager_test extends phpbb_database_test_case
|
||||
'version' => '3.1.0',
|
||||
));
|
||||
$this->db = $this->new_dbal();
|
||||
$this->db_tools = new phpbb_db_tools($this->db);
|
||||
$this->phpbb_root_path = dirname(__FILE__) . '/';
|
||||
$this->phpEx = '.php';
|
||||
$this->user = new phpbb_user();
|
||||
$this->table_prefix = 'phpbb_';
|
||||
|
||||
$this->template = new phpbb_template(
|
||||
$this->phpbb_root_path,
|
||||
@@ -48,8 +50,10 @@ class metadata_manager_test extends phpbb_database_test_case
|
||||
);
|
||||
|
||||
$this->extension_manager = new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$this->db,
|
||||
$this->config,
|
||||
new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', $this->phpbb_root_path, $this->php_ext, $this->table_prefix, array()),
|
||||
'phpbb_ext',
|
||||
$this->phpbb_root_path,
|
||||
$this->phpEx,
|
||||
|
@@ -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)
|
||||
|
@@ -134,19 +134,20 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
if (!$this->extension_manager)
|
||||
{
|
||||
$this->extension_manager = new phpbb_extension_manager(
|
||||
$this->get_db(),
|
||||
new phpbb_config(array()),
|
||||
self::$config['table_prefix'] . 'ext',
|
||||
$phpbb_root_path,
|
||||
".$phpEx",
|
||||
$this->get_cache_driver()
|
||||
);
|
||||
}
|
||||
$config = new phpbb_config(array());
|
||||
$db = $this->get_db();
|
||||
$db_tools = new phpbb_db_tools($db);
|
||||
|
||||
return $this->extension_manager;
|
||||
return new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$db,
|
||||
$config,
|
||||
new phpbb_db_migrator($config, $db, $db_tools, self::$config['table_prefix'] . 'migrations', $phpbb_root_path, $php_ext, self::$config['table_prefix'], array()),
|
||||
self::$config['table_prefix'] . 'ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.' . $php_ext,
|
||||
$this->get_cache_driver()
|
||||
);
|
||||
}
|
||||
|
||||
static protected function install_board()
|
||||
|
Reference in New Issue
Block a user