You are here

public function SearchApiElasticsearchElasticaAdministrationTest::testCreateElasticsearchCluster in Search API Elasticsearch 7

Test creation of an Elasticsearch server cluster in Search API.

File

modules/elastica/tests/functional/search_api_elasticsearch_elastica.test, line 45
Contains basic functionality tests for Search API Elasticsearch/

Class

SearchApiElasticsearchElasticaAdministrationTest
Test administration interface for Search API Elasticsearch Elastica.

Code

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.');
}