You are here

public function AcquiaAgentTestCase::testAcquiaAgentSiteStatus in Acquia Connector 7.2

Same name and namespace in other branches
  1. 7.3 acquia_agent/tests/acquia_agent.test \AcquiaAgentTestCase::testAcquiaAgentSiteStatus()

Tests the site status callback.

File

acquia_agent/tests/acquia_agent.test, line 323

Class

AcquiaAgentTestCase
Tests the functionality of the Acquia Agent module.

Code

public function testAcquiaAgentSiteStatus() {
  module_load_include('inc', 'acquia_agent', 'acquia_agent.pages');
  $uuid = '0dee0d07-4032-44ea-a2f2-84182dc10d54';
  $test_url = "https://insight.acquia.com/node/uuid/{$uuid}/dashboard";
  $variable_keys = array(
    'maintenance_mode',
    'cache',
    'block_cache',
  );
  $test_data = array(
    'active' => 1,
    'href' => $test_url,
  );

  // Set some sample test data.
  variable_set('acquia_subscription_data', $test_data);

  // Test _acquia_agent_get_id_from_url().
  $key = _acquia_agent_get_id_from_sub($test_data);
  $this
    ->assertIdentical($key, $uuid);

  // Add a 'uuid' key to the data and make sure that is returned.
  $test_data['uuid'] = $uuid;
  $test_data['href'] = 'http://example.com';
  $key = _acquia_agent_get_id_from_sub($test_data);
  $this
    ->assertIdentical($key, $uuid);
  $query = array(
    'key' => hash('sha1', "{$key}:test"),
    'nonce' => 'test',
  );
  $json = $this
    ->drupalGetAJAX('system/acquia-connector-status', array(
    'query' => $query,
  ));

  // Test the version.
  $this
    ->assertIdentical($json['version'], '1.0', 'Correct API version found.');

  // Test all of the original values match.
  foreach ($variable_keys as $variable) {
    $this
      ->assertEqual($json['data'][$variable], variable_get($variable));
  }

  // Set the variables to TRUE.
  foreach ($variable_keys as $variable) {
    variable_set($variable, true);
  }
  $json = $this
    ->drupalGetAJAX('system/acquia-connector-status', array(
    'query' => $query,
  ));

  // Test the the values again.
  foreach ($variable_keys as $variable) {
    $this
      ->assertEqual($json['data'][$variable], variable_get($variable));
  }

  // Test invalid query string parameters for access.
  // A random key value should fail.
  $query['key'] = $this
    ->randomString(16);
  $this
    ->drupalGetAJAX('system/acquia-connector-status', array(
    'query' => $query,
  ));
  $this
    ->assertResponse(403);
}