MDL-29071 ddl: unittest for objects name length
This commit is contained in:
@@ -1892,6 +1892,59 @@ class ddl_testcase extends database_driver_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
public function test_object_name() {
|
||||
$gen = $this->tdb->get_manager()->generator;
|
||||
|
||||
// This will form short object name and max length should not be exceeded.
|
||||
$table = 'tablename';
|
||||
$fields = 'id';
|
||||
$suffix = 'pk';
|
||||
for ($i=0; $i<12; $i++) {
|
||||
$this->assertLessThanOrEqual($gen->names_max_length,
|
||||
strlen($gen->getNameForObject($table, $fields, $suffix)),
|
||||
'Generated object name is too long. $i = '.$i);
|
||||
}
|
||||
|
||||
// This will form too long object name always and it must be trimmed to exactly 30 chars.
|
||||
$table = 'aaaa_bbbb_cccc_dddd_eeee_ffff_gggg';
|
||||
$fields = 'aaaaa,bbbbb,ccccc,ddddd';
|
||||
$suffix = 'idx';
|
||||
for ($i=0; $i<12; $i++) {
|
||||
$this->assertEquals($gen->names_max_length,
|
||||
strlen($gen->getNameForObject($table, $fields, $suffix)),
|
||||
'Generated object name is too long. $i = '.$i);
|
||||
}
|
||||
|
||||
// Same test without suffix.
|
||||
$table = 'bbbb_cccc_dddd_eeee_ffff_gggg_hhhh';
|
||||
$fields = 'aaaaa,bbbbb,ccccc,ddddd';
|
||||
$suffix = '';
|
||||
for ($i=0; $i<12; $i++) {
|
||||
$this->assertEquals($gen->names_max_length,
|
||||
strlen($gen->getNameForObject($table, $fields, $suffix)),
|
||||
'Generated object name is too long. $i = '.$i);
|
||||
}
|
||||
|
||||
// This must only trim name when counter is 10 or more.
|
||||
$table = 'cccc_dddd_eeee_ffff_gggg_hhhh_iiii';
|
||||
$fields = 'id';
|
||||
$suffix = 'idx';
|
||||
// Since we don't know how long prefix is, loop to generate tablename that gives exactly maxlengh-1 length.
|
||||
// Skip this test if prefix is too long.
|
||||
while (strlen($table) && strlen($gen->prefix.preg_replace('/_/','',$table).'_id_'.$suffix) >= $gen->names_max_length) {
|
||||
$table = rtrim(substr($table, 0, strlen($table) - 1), '_');
|
||||
}
|
||||
if (strlen($table)) {
|
||||
$this->assertEquals($gen->names_max_length - 1,
|
||||
strlen($gen->getNameForObject($table, $fields, $suffix)));
|
||||
for ($i=0; $i<12; $i++) {
|
||||
$this->assertEquals($gen->names_max_length,
|
||||
strlen($gen->getNameForObject($table, $fields, $suffix)),
|
||||
'Generated object name is too long. $i = '.$i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Following methods are not supported == Do not test
|
||||
/*
|
||||
public function testRenameIndex() {
|
||||
|
||||
Reference in New Issue
Block a user