search_api_elasticsearch_elastica.test in Search API Elasticsearch 7
Contains basic functionality tests for Search API Elasticsearch/
File
modules/elastica/tests/functional/search_api_elasticsearch_elastica.testView source
<?php
/**
* @file
*
* Contains basic functionality tests for Search API Elasticsearch/
*/
/**
* Test administration interface for Search API Elasticsearch Elastica.
*/
class SearchApiElasticsearchElasticaAdministrationTest extends DrupalWebTestCase {
/**
* Implements getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Search API Elasticsearch Elastica Administration'),
'description' => t('Test administration forms for Search API Elasticsearch Elastica.'),
'group' => t('Search API Elasticsearch'),
);
}
/**
* Implements setUp().
*/
public function setUp() {
$modules = array();
$modules[] = 'search_api_elasticsearch_elastica';
if (drupal_load('module', 'composer_manager')) {
$modules[] = 'composer_manager';
}
elseif (drupal_load('module', 'libraries')) {
$modules[] = 'libraries';
}
parent::setUp($modules);
$this->privileged_user = $this
->drupalCreateUser(array(
'administer search_api',
));
$this->unprivileged_user = $this
->drupalCreateUser();
}
/**
* Test creation of an Elasticsearch server cluster in Search API.
*/
public function testCreateElasticsearchCluster() {
$this
->drupalLogin($this->privileged_user);
$this
->drupalGet('admin/config/search/search_api/add_server');
$values = array(
'name' => 'Test Elasticsearch Cluster',
'machine_name' => 'test_es_cluster',
'class' => 'search_api_elasticsearch_elastica_service',
);
$this
->drupalPostAJAX(NULL, $values, 'class');
$this
->assertFieldByName('options[form][0][host]', '127.0.0.1', 'Host field for first Elasticsearch node loaded with default value of 127.0.0.1.');
$this
->assertFieldByName('options[form][0][port]', '9200', 'Port field for first Elasticsearch node loaded with default value of 3200.');
$this
->assertFieldByName('options[form][0][path]', '', 'Path field for first Elasticsearch node loaded with default value empty.');
$this
->assertFieldByName('options[form][0][url]', '', 'URL field for first Elasticsearch node loaded with default value empty.');
$this
->assertFieldByName('options[form][0][transport]', 'Http', 'Transport field for first Elasticsearch node loaded with default value of HTTP.');
$this
->assertFieldByName('options[form][0][persistent]', '1', 'Persistent field for first Elasticsearch node loaded with default value of 1.');
$this
->assertFieldByName('options[form][0][timeout]', '300', 'Timeout field for first Elasticsearch node loaded with default value of 300.');
$this
->assertFieldByName('options[form][0][retryOnConflict]', '0', 'retryOnConflict field for first Elasticsearch node loaded with default value of 0.');
$values2 = array(
'options[form][0][host]' => '127.0.0.1',
'options[form][0][port]' => '9200',
'options[form][0][path]' => '',
'options[form][0][url]' => '',
'options[form][0][transport]' => 'Http',
'options[form][0][persistent]' => 0,
'options[form][0][timeout]' => '300',
'options[form][0][retryOnConflict]' => 0,
);
$values += $values2;
/* $this->drupalPostAJAX(NULL, $values2, array('op' => '+'));
$this->assertFieldByName('options[form][0][host]', '127.0.0.1', 'Host for Node 1 is 127.0.0.1');
$this->assertFieldByName('options[form][0][port]', '9200', 'Port for Node 1 is 9200');
$this->assertFieldByName('options[form][0][path]', '', 'Path for Node 1 is empty');
$this->assertFieldByName('options[form][0][url]', '', 'URL for Node 1 is empty');
$this->assertFieldByName('options[form][0][transport]', 'Http', 'Transport for Node 1 is HTTP');
$this->assertFieldByName('options[form][0][persistent]', '0', 'Persistent for Node 1 is disabled');
$this->assertFieldByName('options[form][0][timeout]', '300', 'Timeout for Node 1 is 300ms');
$this->assertFieldByName('options[form][0][retryOnConflict]', '0', 'retryOnConflict for Node 1 is disabled');
/*
@TODO Add support for testing 3 node clusters.
$this->assertField('options[form][1][host]', 'Form for second Elasticsearch node loaded.');
$this->assertFieldByXPath('//*[@id="edit-options-form-1-host"]');
$values2 += array(
'options[form][1][host]' => '127.0.0.2',
'options[form][1][port]' => '9200',
'options[form][1][path]' => '',
'options[form][1][url]' => '',
'options[form][1][transport]' => 'Http',
'options[form][1][persistent]' => 0,
'options[form][1][timeout]' => '300',
'options[form][1][retryOnConflict]' => 0,
);
$values += $values2;
$this->drupalPostAJAX(NULL, $values2, array('op' => '+'));
for ($i = 1; $i < 3; $i++) {
$ii = $i + 1;
$values3[$i]["options[form][{$i}][host]"] = "127.0.0.{$ii}";
$values3[$i]["options[form][{$i}][port]"] = 9200;
$values3[$i]["options[form][{$i}][path]"] = '';
$values3[$i]["options[form][{$i}][url]"] = '';
$values3[$i]["options[form][{$i}][transport]"] = 'Http';
$values3[$i]["options[form][{$i}][persistent]"] = 0;
$values3[$i]["options[form][{$i}][timeout]"] = 300;
$values3[$i]["options[form][{$i}][retryOnConflict]"] = 0;
$this->drupalPostAJAX(NULL, $values3[$i], 'edit-options-form-add-more');
$values += $values3[$i];
}
*/
$this
->drupalPost(NULL, $values, t('Create server'));
$this
->assertText(t('The server was successfully created.'));
$found = strpos($this
->getUrl(), 'admin/config/search/search_api/server/test_es_cluster') !== FALSE;
$this
->assertTrue($found, 'Correct redirect.');
}
/**
* Test creation of an Elasticsearch server in Search API with HTTP
* Basic Authentation.
*/
public function testCreateElasticsearchServerAuth() {
$this
->drupalLogin($this->privileged_user);
$this
->drupalGet('admin/config/search/search_api/add_server');
$values = array(
'name' => 'Test Elasticsearch Server Auth',
'machine_name' => 'test_es_server_auth',
'class' => 'search_api_elasticsearch_elastica_service',
);
$this
->drupalPostAJAX(NULL, $values, 'class');
$this
->assertFieldByName('options[form][0][host]', '127.0.0.1', 'Host field for first Elasticsearch node loaded with default value of 127.0.0.1.');
$this
->assertFieldByName('options[form][0][port]', '9200', 'Port field for first Elasticsearch node loaded with default value of 3200.');
$this
->assertFieldByName('options[form][0][path]', '', 'Path field for first Elasticsearch node loaded with default value empty.');
$this
->assertFieldByName('options[form][0][url]', '', 'URL field for first Elasticsearch node loaded with default value empty.');
$this
->assertFieldByName('options[form][0][transport]', 'Http', 'Transport field for first Elasticsearch node loaded with default value of HTTP.');
$this
->assertFieldByName('options[form][0][persistent]', '1', 'Persistent field for first Elasticsearch node loaded with default value of 1.');
$this
->assertFieldByName('options[form][0][timeout]', '300', 'Timeout field for first Elasticsearch node loaded with default value of 300.');
$this
->assertFieldByName('options[form][0][retryOnConflict]', '0', 'retryOnConflict field for first Elasticsearch node loaded with default value of 0.');
$values2 = array(
'options[form][0][host]' => '127.0.0.1',
'options[form][0][port]' => '9201',
'options[form][0][path]' => '',
'options[form][0][url]' => '',
'options[form][0][transport]' => 'Http',
'options[form][0][persistent]' => 0,
'options[form][0][timeout]' => '300',
'options[form][0][retryOnConflict]' => 0,
'options[form][0][headers][http_user]' => 'testuser',
'options[form][0][headers][http_pass]' => 'testpassword',
);
$values += $values2;
$this
->drupalPost(NULL, $values, t('Create server'));
$this
->assertText(t('The server was successfully created.'));
$found = strpos($this
->getUrl(), 'admin/config/search/search_api/server/test_es_server_auth') !== FALSE;
$this
->assertTrue($found, 'Correct redirect.');
}
}
Classes
Name | Description |
---|---|
SearchApiElasticsearchElasticaAdministrationTest | Test administration interface for Search API Elasticsearch Elastica. |