public function AcquiaSearchUnitTestCase::testApacheSolrOverride in Acquia Connector 7.2
Same name and namespace in other branches
- 7.3 acquia_search/tests/acquia_search.test \AcquiaSearchUnitTestCase::testApacheSolrOverride()
Tests that Acquia Search properly overrides the Apachesolr connection details to avoid unintended writing to a wrong search index.
File
- acquia_search/
tests/ acquia_search.test, line 142 - Tests for the Acquia Search module.
Class
- AcquiaSearchUnitTestCase
- Unit tests of the functionality of the Acquia Search module.
Code
public function testApacheSolrOverride() {
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.testdbname",
),
array(
'balancer' => $solr_hostname,
'core_id' => "{$acquia_identifier}",
),
);
$environments = $this
->getMockedEnvironments();
// No Acquia hosting and DB detected - should override into Readonly.
unset($conf['apachesolr_environments']);
$ah_env = NULL;
$ah_db_name = '';
$core_service = new PreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
acquia_search_add_apachesolr_overrides($core_service, $environments);
$this
->assertTrue($conf['apachesolr_environments']['ACQUIA']['conf']['apachesolr_read_only']);
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['conf']['acquia_search_key']));
// Acquia Dev hosting environment detected - configs point to the index on the Dev environment.
unset($conf['apachesolr_environments']);
$ah_env = 'dev';
$core_service = new PreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
acquia_search_add_apachesolr_overrides($core_service, $environments);
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['conf']['apachesolr_read_only']));
$this
->assertTrue(!empty($conf['apachesolr_environments']['ACQUIA']['conf']['acquia_search_key']));
$this
->assertIdentical($conf['apachesolr_environments']['ACQUIA']['url'], "http://{$solr_hostname}/solr/{$acquia_identifier}.dev.{$site_folder}");
// Acquia dev environment and a DB name.
unset($conf['apachesolr_environments']);
$ah_env = 'dev';
$ah_db_name = 'testdbname';
$core_service = new PreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
acquia_search_add_apachesolr_overrides($core_service, $environments);
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['conf']['apachesolr_read_only']));
$this
->assertTrue(!empty($conf['apachesolr_environments']['ACQUIA']['conf']['acquia_search_key']));
$this
->assertIdentical($conf['apachesolr_environments']['ACQUIA']['url'], "http://{$solr_hostname}/solr/{$acquia_identifier}.dev.{$ah_db_name}");
// Acquia Test environment and a DB name. According to the mock, no cores available for the Test environment so it is read only.
unset($conf['apachesolr_environments']);
$ah_env = 'test';
$ah_db_name = 'testdbname';
$core_service = new PreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
acquia_search_add_apachesolr_overrides($core_service, $environments);
$this
->assertTrue($conf['apachesolr_environments']['ACQUIA']['conf']['apachesolr_read_only']);
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['conf']['acquia_search_key']));
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['url']));
// Acquia Prod environment and a DB name but AH_PRODUCTION isn't set - so read only.
unset($conf['apachesolr_environments']);
$ah_env = 'prod';
$ah_db_name = 'testdbname';
$core_service = new PreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
acquia_search_add_apachesolr_overrides($core_service, $environments);
$this
->assertTrue($conf['apachesolr_environments']['ACQUIA']['conf']['apachesolr_read_only']);
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['conf']['acquia_search_key']));
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['url']));
// Acquia Prod environment and a DB name and AH_PRODUCTION is set - so it should override to connect to the prod index.
unset($conf['apachesolr_environments']);
$_SERVER['AH_PRODUCTION'] = 1;
$ah_env = 'prod';
$ah_db_name = 'testdbname';
$core_service = new PreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
acquia_search_add_apachesolr_overrides($core_service, $environments);
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['conf']['apachesolr_read_only']));
$this
->assertTrue(!empty($conf['apachesolr_environments']['ACQUIA']['conf']['acquia_search_key']));
$this
->assertIdentical($conf['apachesolr_environments']['ACQUIA']['url'], "http://{$solr_hostname}/solr/{$acquia_identifier}");
// Trying to override already overridden settings should not succeed.
unset($_SERVER['AH_PRODUCTION']);
$ah_env = 'dev';
$ah_db_name = 'testdbname';
$core_service = new PreferredSearchCoreService($acquia_identifier, $ah_env, $site_folder, $ah_db_name, $available_cores);
acquia_search_add_apachesolr_overrides($core_service, $environments);
$this
->assertTrue(empty($conf['apachesolr_environments']['ACQUIA']['conf']['apachesolr_read_only']));
$this
->assertTrue(!empty($conf['apachesolr_environments']['ACQUIA']['conf']['acquia_search_key']));
$this
->assertIdentical($conf['apachesolr_environments']['ACQUIA']['url'], "http://{$solr_hostname}/solr/{$acquia_identifier}");
}