function SchemaUnitTestCase::testUnprefixTable in Schema 7
File
- tests/
schema.test, line 39 - Defines SchemaUnitTestCase.
Class
- SchemaUnitTestCase
- @file Defines SchemaUnitTestCase.
Code
function testUnprefixTable() {
$cases = array();
// Test without any prefixes.
$cases[] = array(
'options' => array(),
'cases' => array(
'a2' => 'a2',
'a3' => 'a3',
'b2' => 'b2',
'b3' => 'b3',
'test' => 'test',
'aa_test' => 'aa_test',
'aaa_test' => 'aaa_test',
),
);
// Test empty default prefix.
$cases[] = array(
'options' => array(
'prefix' => array(
'default' => '',
'a2' => 'aa_',
'a3' => 'aaa_',
'b2' => 'bb_',
'b3' => 'bbb_',
),
),
'cases' => array(
'aa_a2' => 'a2',
'aaa_a3' => 'a3',
'bb_b2' => 'b2',
'bbb_b3' => 'b3',
'test' => 'test',
'aa_test' => 'aa_test',
'aaa_test' => 'aaa_test',
),
);
// Test empty default prefix.
$cases[] = array(
'options' => array(
'prefix' => array(
'default' => 'test_',
'a2' => 'aa_',
'a3' => '',
'b2' => 'bb_',
'b3' => '',
),
),
'cases' => array(
'aa_a2' => 'a2',
'test_a3' => 'a3',
'bb_b2' => 'b2',
'test_b3' => 'b3',
'test' => 'test',
'test_test' => 'test',
),
);
foreach ($cases as $case) {
$connection = new SchemaTestDatabaseConnection($case['options']);
$connection
->setKey($this
->randomName());
foreach ($case['cases'] as $input => $expected) {
$result = schema_unprefix_table($input, $connection);
$this
->assertIdentical($result, $expected);
}
}
// Test the default connection object parameter.
$connection = Database::getConnection();
foreach (array(
'test',
) as $name) {
$input = $connection
->prefixTables('{' . $name . '}');
$result = schema_unprefix_table($input);
$this
->assertIdentical($result, $name);
}
}