mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[ticket/12561] Added tests for "after last", "after missing" and "empty"
Also removed tabs PHPBB3-12561
This commit is contained in:
parent
c51b926631
commit
3cabe5fd79
3 changed files with 111 additions and 9 deletions
|
@ -112,8 +112,8 @@ class schema_generator
|
||||||
$columns = $this->tables[$table]['COLUMNS'];
|
$columns = $this->tables[$table]['COLUMNS'];
|
||||||
$offset = array_search($column_data['after'], array_keys($columns));
|
$offset = array_search($column_data['after'], array_keys($columns));
|
||||||
unset($column_data['after']);
|
unset($column_data['after']);
|
||||||
|
|
||||||
if ($offset == false)
|
if ($offset === false)
|
||||||
{
|
{
|
||||||
$this->tables[$table]['COLUMNS'][$column] = array_values($column_data);
|
$this->tables[$table]['COLUMNS'][$column] = array_values($column_data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ class phpbb_dbal_migration_dummy_order extends \phpbb\db\migration\migration
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'add_tables' => array(
|
'add_tables' => array(
|
||||||
$this->table_prefix . 'column_order_test' => array(
|
$this->table_prefix . 'column_order_test1' => array(
|
||||||
'COLUMNS' => array(
|
'COLUMNS' => array(
|
||||||
'foobar1' => array('BOOL', 0),
|
'foobar1' => array('BOOL', 0),
|
||||||
'foobar3' => array('BOOL', 0),
|
'foobar3' => array('BOOL', 0),
|
||||||
|
@ -22,10 +22,55 @@ class phpbb_dbal_migration_dummy_order extends \phpbb\db\migration\migration
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'add_columns' => array(
|
'add_columns' => array(
|
||||||
$this->table_prefix . 'column_order_test' => array(
|
$this->table_prefix . 'column_order_test1' => array(
|
||||||
'foobar2' => array('BOOL', 0, 'after' => 'foobar1'),
|
'foobar2' => array('BOOL', 0, 'after' => 'foobar1'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'add_tables' => array(
|
||||||
|
$this->table_prefix . 'column_order_test2' => array(
|
||||||
|
'COLUMNS' => array(
|
||||||
|
'foobar1' => array('BOOL', 0),
|
||||||
|
'foobar3' => array('BOOL', 0),
|
||||||
|
),
|
||||||
|
'PRIMARY_KEY' => array('foobar1'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'add_columns' => array(
|
||||||
|
$this->table_prefix . 'column_order_test2' => array(
|
||||||
|
'foobar4' => array('BOOL', 0, 'after' => 'foobar3'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'add_tables' => array(
|
||||||
|
$this->table_prefix . 'column_order_test3' => array(
|
||||||
|
'COLUMNS' => array(
|
||||||
|
'foobar1' => array('BOOL', 0),
|
||||||
|
'foobar3' => array('BOOL', 0),
|
||||||
|
),
|
||||||
|
'PRIMARY_KEY' => array('foobar1'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'add_columns' => array(
|
||||||
|
$this->table_prefix . 'column_order_test3' => array(
|
||||||
|
'foobar5' => array('BOOL', 0, 'after' => 'non-existing'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'add_tables' => array(
|
||||||
|
$this->table_prefix . 'column_order_test4' => array(
|
||||||
|
'COLUMNS' => array(
|
||||||
|
'foobar1' => array('BOOL', 0),
|
||||||
|
'foobar3' => array('BOOL', 0),
|
||||||
|
),
|
||||||
|
'PRIMARY_KEY' => array('foobar1'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'add_columns' => array(
|
||||||
|
$this->table_prefix . 'column_order_test4' => array(
|
||||||
|
'foobar5' => array('BOOL', 0, 'after' => ''),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,18 +49,75 @@ class schmema_generator_test extends phpbb_test_case
|
||||||
$this->assertArrayHasKey('phpbb_users', $this->generator->get_schema());
|
$this->assertArrayHasKey('phpbb_users', $this->generator->get_schema());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_check_column_position_success()
|
protected $expected_results_between = array(
|
||||||
|
'foobar1' => array('BOOL', 0),
|
||||||
|
'foobar2' => array('BOOL', 0),
|
||||||
|
'foobar3' => array('BOOL', 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
public function test_check_column_position_between_success()
|
||||||
{
|
{
|
||||||
$this->get_schema_generator(array(
|
$this->get_schema_generator(array(
|
||||||
'phpbb_dbal_migration_dummy_order',
|
'phpbb_dbal_migration_dummy_order',
|
||||||
));
|
));
|
||||||
|
|
||||||
$tables = $this->generator->get_schema();
|
$tables = $this->generator->get_schema();
|
||||||
$columns = $tables[$this->table_prefix . 'column_order_test']['COLUMNS'];
|
$columns = $tables[$this->table_prefix . 'column_order_test1']['COLUMNS'];
|
||||||
|
|
||||||
$offset1 = array_search('foobar1', array_keys($columns));
|
$this->assertEquals($columns, $expected_results_between, 'The schema generator could not position the column correctly between column 1 and 3, using the "after" option in the migration script.');
|
||||||
$offset2 = array_search('foobar2', array_keys($columns));
|
}
|
||||||
|
|
||||||
$this->assertEquals($offset1 + 1, $offset2, 'The schema generator could not position the column correctly, using the "after" option in the migration script.');
|
protected $expected_results_after_last = array(
|
||||||
|
'foobar1' => array('BOOL', 0),
|
||||||
|
'foobar3' => array('BOOL', 0),
|
||||||
|
'foobar4' => array('BOOL', 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
public function test_check_column_position_after_last_success()
|
||||||
|
{
|
||||||
|
$this->get_schema_generator(array(
|
||||||
|
'phpbb_dbal_migration_dummy_order',
|
||||||
|
));
|
||||||
|
|
||||||
|
$tables = $this->generator->get_schema();
|
||||||
|
$columns = $tables[$this->table_prefix . 'column_order_test2']['COLUMNS'];
|
||||||
|
|
||||||
|
$this->assertEquals($columns, $expected_results_after_last, 'The schema generator could not position the column correctly after the last column, using the "after" option in the migration script.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $expected_results_after_missing = array(
|
||||||
|
'foobar1' => array('BOOL', 0),
|
||||||
|
'foobar3' => array('BOOL', 0),
|
||||||
|
'foobar5' => array('BOOL', 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
public function test_check_column_position_after_missing_success()
|
||||||
|
{
|
||||||
|
$this->get_schema_generator(array(
|
||||||
|
'phpbb_dbal_migration_dummy_order',
|
||||||
|
));
|
||||||
|
|
||||||
|
$tables = $this->generator->get_schema();
|
||||||
|
$columns = $tables[$this->table_prefix . 'column_order_test3']['COLUMNS'];
|
||||||
|
|
||||||
|
$this->assertEquals($columns, $expected_results_after_missing, 'The schema generator could not position the column after a "missing" column value, using the "after" option in the migration script.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $expected_results_after_empty = array(
|
||||||
|
'foobar1' => array('BOOL', 0),
|
||||||
|
'foobar3' => array('BOOL', 0),
|
||||||
|
'foobar5' => array('BOOL', 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
public function test_check_column_position_after_empty_success()
|
||||||
|
{
|
||||||
|
$this->get_schema_generator(array(
|
||||||
|
'phpbb_dbal_migration_dummy_order',
|
||||||
|
));
|
||||||
|
|
||||||
|
$tables = $this->generator->get_schema();
|
||||||
|
$columns = $tables[$this->table_prefix . 'column_order_test4']['COLUMNS'];
|
||||||
|
|
||||||
|
$this->assertEquals($columns, $expected_results_after_empty, 'The schema generator could not position the column after an "empty" column value, using the "after" option in the migration script.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue