You are here

public function SearchApiAcquiaUnitTestCase::testApacheSolrOverrideWithUnderscoreInDb in Acquia Search for Search API 7.2

Tests that Search API Acquia properly overrides the connection details to avoid unintended writing to a wrong search index and db.

File

tests/search_api_acquia.test, line 195
Tests for the Search API Acquia module.

Class

SearchApiAcquiaUnitTestCase
Unit tests of the functionality of the Search API Acquia module.

Code

public function testApacheSolrOverrideWithUnderscoreInDb() {
  global $conf;
  $acquia_identifier = $this->id;
  $site_folder = $this
    ->randomName(32);
  $solr_hostname = $this
    ->randomName(10) . '.acquia-search.com';
  $available_cores = array(
    array(
      'balancer' => $solr_hostname,
      'core_id' => "{$acquia_identifier}.dev.{$site_folder}",
    ),
    array(
      'balancer' => $solr_hostname,
      'core_id' => "{$acquia_identifier}.dev.test_db_name",
    ),
    array(
      'balancer' => $solr_hostname,
      'core_id' => "{$acquia_identifier}",
    ),
  );
  $server_id = 'ACQUIA';

  // Acquia dev environment and a DB name with '_'.
  unset($conf['search_api_acquia_overrides']);
  $ah_env = 'dev';
  $ah_db_name = 'test_db_name';
  $core_service = new SAPIPreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
  search_api_acquia_override_server($core_service, $server_id);
  $this
    ->assertIdentical($conf['search_api_acquia_overrides']['ACQUIA']['overridden_by_acquia_search'], SEARCH_API_ACQUIA_OVERRIDE_AUTO_SET);
  $this
    ->assertTrue(!empty($conf['search_api_acquia_overrides']['ACQUIA']['derived_key']));
  $this
    ->assertIdentical($conf['search_api_acquia_overrides']['ACQUIA']['host'], $solr_hostname);
  $this
    ->assertIdentical($conf['search_api_acquia_overrides']['ACQUIA']['path'], "/solr/{$acquia_identifier}.dev.{$ah_db_name}");

  // Acquia dev environment and a DB name with '-' .
  unset($conf['search_api_acquia_overrides']);
  $ah_env = 'dev';
  $ah_db_name = 'test-db-name';
  $core_service = new SAPIPreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
  search_api_acquia_override_server($core_service, $server_id);
  $this
    ->assertIdentical($conf['search_api_acquia_overrides']['ACQUIA']['overridden_by_acquia_search'], SEARCH_API_ACQUIA_OVERRIDE_AUTO_SET);
  $this
    ->assertTrue(!empty($conf['search_api_acquia_overrides']['ACQUIA']['derived_key']));
  $this
    ->assertIdentical($conf['search_api_acquia_overrides']['ACQUIA']['host'], $solr_hostname);
  $this
    ->assertTrue($conf['search_api_acquia_overrides']['ACQUIA']['path'], "A database with a dash(-) is an invalid database");
}