You are here

public function AcquiaSPITestCase::testAcquiaSpiSetVariables in Acquia Connector 7.3

Same name and namespace in other branches
  1. 7.2 acquia_spi/tests/acquia_spi.test \AcquiaSPITestCase::testAcquiaSPISetVariables()

Needs comment.

File

acquia_spi/tests/acquia_spi.test, line 424

Class

AcquiaSPITestCase
Tests the functionality of the Acquia SPI module.

Code

public function testAcquiaSpiSetVariables() {
  $spi_data = acquia_spi_get();
  $vars = drupal_json_decode($spi_data['system_vars']);
  $this
    ->assertTrue(empty($vars['acquia_spi_saved_variables']), 'Have not saved any variables');

  // Set error reporting so variable is saved.
  $edit = array(
    'error_level' => 2,
  );
  $this
    ->drupalPost('admin/config/development/logging', $edit, 'Save configuration');

  // Turn off error reporting.
  $set_variables = array(
    'error_level' => 0,
  );
  acquia_spi_set_variables($set_variables);
  $new = variable_get('error_level', '2');
  $this
    ->assertTrue($new === 0, 'Set error reporting to log only');
  $vars = drupal_json_decode(acquia_spi_get_variables_data());
  $this
    ->assertTrue(in_array('error_level', $vars['acquia_spi_saved_variables']['variables']), 'SPI data reports error level was saved');
  $this
    ->assertTrue(isset($vars['acquia_spi_saved_variables']['time']), 'Set time for saved variables');

  // Attemp to set variable that is not whitelisted.
  $current = variable_get('clean_url', 'test');
  $set_variables = array(
    'clean_url' => 0,
  );
  acquia_spi_set_variables($set_variables);
  $after = variable_get('clean_url', 'set');
  $this
    ->assertIdentical($current, $after, 'Non-whitelisted variable cannot be automatically set');
  $vars = drupal_json_decode(acquia_spi_get_variables_data());
  $this
    ->assertFalse(in_array('clean_url', $vars['acquia_spi_saved_variables']['variables']), 'SPI data does not include anything about trying to save clean url');

  // Test override of approved variable list.
  $set_variables = array(
    'acquia_spi_set_variables_automatic' => array(
      'test_variable',
    ),
  );
  acquia_spi_set_variables($set_variables);
  $vars = drupal_json_decode(acquia_spi_get_variables_data());
  $this
    ->assertFalse(isset($vars['acquia_spi_set_variables_automatic']), 'Using default list of approved list of variables');
  variable_set('acquia_spi_set_variables_override', 1);
  $set_variables = array(
    'acquia_spi_set_variables_automatic' => array(
      'test_variable',
    ),
  );
  acquia_spi_set_variables($set_variables);
  $vars = drupal_json_decode(acquia_spi_get_variables_data());
  $this
    ->assertIdentical($vars['acquia_spi_set_variables_automatic'], array(
    'test_variable',
  ), 'Altered approved list of variables that can be set');
}