You are here

function BackupMigrateUnitTest::testGetTableNames in Backup and Migrate 5

File

tests/BackupMigrateUnitTest.test, line 621

Class

BackupMigrateUnitTest
Unit tests for Backup and Migrate module.

Code

function testGetTableNames() {

  // Make sure the return value is an array of plausible table names
  $safe_pattern = "/[a-z\\_]+/";
  $test_table = $this
    ->randomName(10, 'testtable_');
  db_query("CREATE TABLE {$test_table} (testid int(10));");
  $tables = _backup_migrate_get_table_names();
  $this
    ->assertTrue(is_array($tables), t('Testing that default exclude tables is an array'));
  $this
    ->assertTrue(count($tables) > 0, t('Testing at least one table is present'));
  foreach ($tables as $table) {
    $this
      ->assertTrue(is_string($table), t('Testing that table name is a string'));
    $this
      ->assertTrue(preg_match($safe_pattern, $table), t('Testing that table name: %name is valid', array(
      '%name' => $name,
    )));
  }
  $this
    ->assertTrue(in_array($test_table, $tables), t('Testing that the test table is present'));
  db_query("DROP TABLE {$test_table};");
}