You are here

public function ParanoiaSanitizeTestCase::testDecideTablePrefixing in Paranoia 7

Confirm prefixes are properly added to tables.

File

paranoiasanitize/paranoiasanitize.test, line 72
Contains ParanoiaSanitizeTestCase.

Class

ParanoiaSanitizeTestCase
@file Contains ParanoiaSanitizeTestCase.

Code

public function testDecideTablePrefixing() {

  // Test a default prefix, a table without prefix, a table with a prefix.
  $fake_databases['default']['default']['prefix'] = array(
    'default' => 'dpx_',
    'no_prefix_table' => '',
    'yes_prefix_table' => 'yes_',
  );
  $table_names = array(
    array(
      'original' => 'some_table',
      'prefixed' => 'dpx_some_table',
      'description' => t('Default prefix applied to a table'),
    ),
    array(
      'original' => 'no_prefix_table',
      'prefixed' => 'no_prefix_table',
      'description' => t('Table without prefix stays without prefix'),
    ),
    array(
      'original' => 'yes_prefix_table',
      'prefixed' => 'yes_yes_prefix_table',
      'description' => t('Table with prefix gets the prefix'),
    ),
  );
  foreach ($table_names as $table_name_pair) {
    $prefixed_table_name = _paranoiasanitize_apply_db_prefix($table_name_pair['original'], $fake_databases);
    $this
      ->assertEqual($prefixed_table_name, $table_name_pair['prefixed'], $table_name_pair['description']);
  }

  // Now confirm that the code works without a default prefix.
  $fake_databases['default']['default']['prefix']['default'] = '';
  $table_names = array(
    array(
      'original' => 'some_table',
      'prefixed' => 'some_table',
      'description' => t('Empty default prefix applied to a table'),
    ),
    array(
      'original' => 'no_prefix_table',
      'prefixed' => 'no_prefix_table',
      'description' => t('Table without prefix stays without prefix'),
    ),
    array(
      'original' => 'yes_prefix_table',
      'prefixed' => 'yes_yes_prefix_table',
      'description' => t('Table with prefix gets the prefix'),
    ),
  );
  foreach ($table_names as $table_name_pair) {
    $prefixed_table_name = _paranoiasanitize_apply_db_prefix($table_name_pair['original'], $fake_databases);
    $this
      ->assertEqual($prefixed_table_name, $table_name_pair['prefixed'], $table_name_pair['description']);
  }
}