diff options
author | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
---|---|---|
committer | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
commit | 8ea437e30605e0f66b5220bf904a61d7c1d11ddd (patch) | |
tree | e0db2bb4a012d5b06a633160b19f62f4868ecd28 /tests/dbal/db_tools_test.php | |
parent | 36bc1870f21fac04736a1049c1d5b8e127d729f4 (diff) | |
parent | 2fdd46b36431ae0f58bb2e78e42553168db9a0ff (diff) | |
download | forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.gz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.bz2 forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.xz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.zip |
Merge remote-tracking branch 'upstream/prep-release-3.2.9'
Diffstat (limited to 'tests/dbal/db_tools_test.php')
-rw-r--r-- | tests/dbal/db_tools_test.php | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 5832b966d8..0365463a48 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -11,13 +11,11 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - class phpbb_dbal_db_tools_test extends phpbb_database_test_case { /** @var \phpbb\db\driver\driver_interface */ protected $db; - /** @var \phpbb\db\tools */ + /** @var \phpbb\db\tools\tools_interface */ protected $tools; protected $table_exists; protected $table_data; @@ -32,7 +30,8 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->tools = new \phpbb\db\tools($this->db); + $factory = new \phpbb\db\tools\factory(); + $this->tools = $factory->get($this->db); $this->table_data = array( 'COLUMNS' => array( @@ -204,8 +203,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case public function test_list_columns() { + $config = $this->get_database_config(); + $table_columns = $this->table_data['COLUMNS']; + + if (strpos($config['dbms'], 'mssql') !== false) + { + ksort($table_columns); + } $this->assertEquals( - array_keys($this->table_data['COLUMNS']), + array_keys($table_columns), array_values($this->tools->sql_list_columns('prefix_table_name')) ); } @@ -340,7 +346,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case public function test_perform_schema_changes_drop_tables() { - $db_tools = $this->getMock('\phpbb\db\tools', array( + $db_tools = $this->getMock('\phpbb\db\tools\tools', array( 'sql_table_exists', 'sql_table_drop', ), array(&$this->db)); @@ -366,7 +372,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case public function test_perform_schema_changes_drop_columns() { - $db_tools = $this->getMock('\phpbb\db\tools', array( + $db_tools = $this->getMock('\phpbb\db\tools\tools', array( 'sql_column_exists', 'sql_column_remove', ), array(&$this->db)); @@ -422,4 +428,50 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_13282', array('TINT:2'))); $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282')); } + + public function test_create_index_with_long_name() + { + // This constant is being used for checking table prefix. + $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config) + + if (strlen($table_prefix) > 20) + { + $this->markTestIncomplete('The table prefix length is too long for proper testing of index shortening function.'); + } + + $max_index_length = 30; + + if ($this->tools instanceof \phpbb\db\tools\mssql) + { + $max_length_method = new ReflectionMethod('\phpbb\db\tools\mssql', 'get_max_index_name_length'); + $max_length_method->setAccessible(true); + $max_index_length = $max_length_method->invoke($this->tools); + } + + $table_suffix = str_repeat('a', 25 - strlen($table_prefix)); + $table_name = $table_prefix . $table_suffix; + + $this->tools->sql_create_table($table_name, $this->table_data); + + // Index name and table suffix and table prefix have > maximum index length chars in total. + // Index name and table suffix have <= maximum index length chars in total. + $long_index_name = str_repeat('i', $max_index_length - strlen($table_suffix)); + $this->assertFalse($this->tools->sql_index_exists($table_name, $long_index_name)); + $this->assertTrue($this->tools->sql_create_index($table_name, $long_index_name, array('c_timestamp'))); + $this->assertTrue($this->tools->sql_index_exists($table_name, $long_index_name)); + + // Index name and table suffix have > maximum index length chars in total. + $very_long_index_name = str_repeat('i', $max_index_length); + $this->assertFalse($this->tools->sql_index_exists($table_name, $very_long_index_name)); + $this->assertTrue($this->tools->sql_create_index($table_name, $very_long_index_name, array('c_timestamp'))); + $this->assertTrue($this->tools->sql_index_exists($table_name, $very_long_index_name)); + + $this->tools->sql_table_drop($table_name); + + // Index name has > maximum index length chars - that should not be possible. + $too_long_index_name = str_repeat('i', $max_index_length + 1); + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name)); + $this->setExpectedTriggerError(E_USER_ERROR); + $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp')); + } } |