mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-30 19:24:13 +02:00
Merge pull request #2474 from PayBas/ticket/12561
[ticket/12561] Add "after" check to schema_generator for columns_add * PayBas/ticket/12561: [ticket/12561] Reworked tests by nickvergessen [ticket/12561] Added tests for "after last", "after missing" and "empty" [ticket/12561] Add check to see if "after" column actually exists [ticket/12561] Added test for "after" [ticket/12561] Add "after" check to schema_generator for columns_add
This commit is contained in:
commit
033df350d9
@ -109,7 +109,25 @@ class schema_generator
|
||||
{
|
||||
foreach ($add_columns as $column => $column_data)
|
||||
{
|
||||
$this->tables[$table]['COLUMNS'][$column] = $column_data;
|
||||
if (isset($column_data['after']))
|
||||
{
|
||||
$columns = $this->tables[$table]['COLUMNS'];
|
||||
$offset = array_search($column_data['after'], array_keys($columns));
|
||||
unset($column_data['after']);
|
||||
|
||||
if ($offset === false)
|
||||
{
|
||||
$this->tables[$table]['COLUMNS'][$column] = array_values($column_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->tables[$table]['COLUMNS'] = array_merge(array_slice($columns, 0, $offset + 1, true), array($column => array_values($column_data)), array_slice($columns, $offset));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->tables[$table]['COLUMNS'][$column] = $column_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
tests/dbal/migration/dummy_order.php
Normal file
26
tests/dbal/migration/dummy_order.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_dummy_order extends \phpbb\db\migration\migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_tables' => array(
|
||||
$this->table_prefix . 'column_order_test1' => array(
|
||||
'COLUMNS' => array(
|
||||
'foobar1' => array('BOOL', 0),
|
||||
'foobar3' => array('BOOL', 0),
|
||||
),
|
||||
'PRIMARY_KEY' => array('foobar1'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
22
tests/dbal/migration/dummy_order_0.php
Normal file
22
tests/dbal/migration/dummy_order_0.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_dummy_order_0 extends \phpbb\db\migration\migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'column_order_test1' => array(
|
||||
'foobar2' => array('BOOL', 0, 'after' => 'foobar1'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
22
tests/dbal/migration/dummy_order_1.php
Normal file
22
tests/dbal/migration/dummy_order_1.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_dummy_order_1 extends \phpbb\db\migration\migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'column_order_test1' => array(
|
||||
'foobar4' => array('BOOL', 0, 'after' => 'foobar3'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
22
tests/dbal/migration/dummy_order_2.php
Normal file
22
tests/dbal/migration/dummy_order_2.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_dummy_order_2 extends \phpbb\db\migration\migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'column_order_test1' => array(
|
||||
'foobar5' => array('BOOL', 0, 'after' => 'non-existing'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
22
tests/dbal/migration/dummy_order_3.php
Normal file
22
tests/dbal/migration/dummy_order_3.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_dummy_order_3 extends \phpbb\db\migration\migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'column_order_test1' => array(
|
||||
'foobar6' => array('BOOL', 0, 'after' => ''),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
22
tests/dbal/migration/dummy_order_4.php
Normal file
22
tests/dbal/migration/dummy_order_4.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_dummy_order_4 extends \phpbb\db\migration\migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'column_order_test1' => array(
|
||||
'foobar7' => array('BOOL', 0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
23
tests/dbal/migration/dummy_order_5.php
Normal file
23
tests/dbal/migration/dummy_order_5.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_dummy_order_5 extends \phpbb\db\migration\migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'column_order_test1' => array(
|
||||
'foobar8' => array('BOOL', 0, 'after' => 'foobar3'),
|
||||
'foobar9' => array('BOOL', 0, 'after' => 'foobar3'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -11,8 +11,19 @@
|
||||
*
|
||||
*/
|
||||
|
||||
class schmema_generator_test extends phpbb_test_case
|
||||
require_once __DIR__ . '/../dbal/migration/dummy_order.php';
|
||||
require_once __DIR__ . '/../dbal/migration/dummy_order_0.php';
|
||||
require_once __DIR__ . '/../dbal/migration/dummy_order_1.php';
|
||||
require_once __DIR__ . '/../dbal/migration/dummy_order_2.php';
|
||||
require_once __DIR__ . '/../dbal/migration/dummy_order_3.php';
|
||||
require_once __DIR__ . '/../dbal/migration/dummy_order_4.php';
|
||||
require_once __DIR__ . '/../dbal/migration/dummy_order_5.php';
|
||||
|
||||
class schema_generator_test extends phpbb_test_case
|
||||
{
|
||||
/** @var \phpbb\db\migration\schema_generator */
|
||||
protected $generator;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@ -50,4 +61,78 @@ class schmema_generator_test extends phpbb_test_case
|
||||
|
||||
$this->assertArrayHasKey('phpbb_users', $this->generator->get_schema());
|
||||
}
|
||||
|
||||
public function column_add_after_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'phpbb_dbal_migration_dummy_order_0',
|
||||
array(
|
||||
'foobar1',
|
||||
'foobar2',
|
||||
'foobar3',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_dbal_migration_dummy_order_1',
|
||||
array(
|
||||
'foobar1',
|
||||
'foobar3',
|
||||
'foobar4',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_dbal_migration_dummy_order_2',
|
||||
array(
|
||||
'foobar1',
|
||||
'foobar3',
|
||||
'foobar5',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_dbal_migration_dummy_order_3',
|
||||
array(
|
||||
'foobar1',
|
||||
'foobar3',
|
||||
'foobar6',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_dbal_migration_dummy_order_4',
|
||||
array(
|
||||
'foobar1',
|
||||
'foobar3',
|
||||
'foobar7',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'phpbb_dbal_migration_dummy_order_5',
|
||||
array(
|
||||
'foobar1',
|
||||
'foobar3',
|
||||
'foobar9',
|
||||
'foobar8',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider column_add_after_data
|
||||
*/
|
||||
public function test_column_add_after($migration, $expected)
|
||||
{
|
||||
$this->get_schema_generator(array(
|
||||
'phpbb_dbal_migration_dummy_order',
|
||||
$migration,
|
||||
));
|
||||
|
||||
$tables = $this->generator->get_schema();
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
array_keys($tables[$this->table_prefix . 'column_order_test1']['COLUMNS']),
|
||||
'The schema generator could not position the column correctly, using the "after" option in the migration script.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user