You are here

public function ParanoiaSanitizeTestCase::testDecideWhatToDo in Paranoia 7

Confirm the decisions are made properly.

File

paranoiasanitize/paranoiasanitize.test, line 24
Contains ParanoiaSanitizeTestCase.

Class

ParanoiaSanitizeTestCase
@file Contains ParanoiaSanitizeTestCase.

Code

public function testDecideWhatToDo() {
  $existing_tables = array(
    'both_whitelist_covered' => array(
      'queries' => array(
        'existing',
      ),
      'fields' => array(
        'nid',
        'gid',
        'realm',
      ),
    ),
    'both_whitelist_not_covered' => array(
      'queries' => array(
        'existing',
      ),
      'fields' => array(
        'nid',
        'vid',
        'uid',
        'title',
        'log',
      ),
    ),
    'existing_db_only' => array(
      'queries' => array(
        'existing',
      ),
      'fields' => array(
        'type',
        'name',
        'base',
      ),
    ),
  );
  $whitelist_tables = array(
    'whitelist_not_db' => array(
      'queries' => array(
        'whitelist',
      ),
      'fields' => array(
        'pajamas',
        'manteca_de_mani',
      ),
    ),
    'both_whitelist_covered' => array(
      'queries' => array(
        'whitelist',
      ),
      'fields' => array(
        'nid',
        'gid',
        'realm',
      ),
    ),
    'both_whitelist_not_covered' => array(
      'queries' => array(
        'whitelist',
      ),
      'fields' => array(
        'nid',
        'vid',
        'uid',
        'title',
      ),
    ),
  );
  $derived_changes = _paranoiasanitize_decide_what_to_do($existing_tables, $whitelist_tables);

  // If a table exists in whitelist & not in existing tables, don't return it.
  $this
    ->assertFalse(array_key_exists('whitelist_not_db', $derived_changes), t('If whitelist has a nonexistent table, remove it from the work to do.'));

  // If a whitelist record covers all columns in the table, do that work.
  $this
    ->assertEqual('whitelist', $derived_changes['both_whitelist_covered']['queries'][0], t('If whitelist covers all columns of real table, do that work.'));

  // If the suggested whitelist changes do not cover all the columns in
  // the table, instead truncate the table and log an error.
  $this
    ->assertEqual('TRUNCATE both_whitelist_not_covered', $derived_changes['both_whitelist_not_covered']['queries'][0], t('If whitelist does not cover all columns, truncate the table.'));

  // If a record exists in the db and not the changes to do, truncate it.
  $this
    ->assertEqual('TRUNCATE existing_db_only', $derived_changes['existing_db_only']['queries'][0], t('If whitelist does not have a table, truncate the table.'));
}