View source
<?php
namespace Drupal\Tests\acquia_search\Functional;
use Drupal\search_api\Entity\Server;
use Drupal\Tests\BrowserTestBase;
class AcquiaConnectorSearchTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected $id;
protected $key;
protected $salt;
protected $server;
protected $index;
protected $settingsPath;
public static $modules = [
'acquia_connector',
'search_api',
'search_api_solr',
'toolbar',
'acquia_connector_test',
'node',
'path_alias',
'views',
];
protected function setUp() {
parent::setUp();
$this->id = $this
->randomString(10);
$this->key = $this
->randomString(32);
$this->salt = $this
->randomString(32);
$this->server = 'acquia_search_server';
$this->index = 'acquia_search_index';
$this->settingsPath = 'admin/config/search/search-api';
$content_type = $this
->drupalCreateContentType();
$node_data = [
'type' => $content_type
->id(),
];
$this
->drupalCreateNode($node_data);
$this
->connect();
}
public function connect() {
\Drupal::configFactory()
->getEditable('acquia_connector.settings')
->set('spi.ssl_verify', FALSE)
->save();
\Drupal::configFactory()
->getEditable('acquia_connector.settings')
->set('spi.ssl_override', TRUE)
->save();
$admin_user = $this
->createAdminUser();
$this
->drupalLogin($admin_user);
$edit_fields = [
'acquia_identifier' => $this
->randomString(8),
'acquia_key' => $this
->randomString(8),
];
$submit_button = 'Connect';
$this
->drupalPostForm('admin/config/system/acquia-connector/credentials', $edit_fields, $submit_button);
\Drupal::service('module_installer')
->install([
'acquia_search',
]);
}
public function createAdminUser() {
$permissions = [
'administer site configuration',
'access administration pages',
'access toolbar',
'administer search_api',
];
return $this
->drupalCreateUser($permissions);
}
public function testEnvironment() {
$this
->drupalGet('admin/config/search/search-api');
$environment = Server::load('acquia_search_server');
$this
->assertInstanceOf(Server::class, $environment, t('Acquia Search environment saved.'));
}
public function testEnvironmentUi() {
$this
->drupalGet($this->settingsPath);
$this
->assertLinkByHref('/admin/config/search/search-api/server/' . $this->server, 0, t('The Acquia Search Server is displayed in the UI.'));
$this
->assertLinkByHref('/admin/config/search/search-api/index/' . $this->index, 0, t('The Acquia Search Index is displayed in the UI.'));
$this
->drupalGet('/admin/config/search/search-api/server/' . $this->server . '/edit');
$this
->clickLink('Delete', 0);
$this
->assertResponse(403, t('The Acquia Search environment cannot be deleted via the UI.'));
}
public function testAcquiaSearchServerUi() {
$settings_path = 'admin/config/search/search-api';
$this
->drupalGet($settings_path);
$this
->clickLink('Edit', 0);
$this
->assertText('Backend', t('The Backend checkbox label exists'), 'Acquia Search');
$this
->assertFieldChecked('edit-backend-config-connector-solr-acquia-connector', t('Is used as a Solr Connector: Acquia'), 'Acquia Search');
$this
->assertText('Solr server URI', t('The Solr server URI label exist'), 'Acquia Search');
$this
->assertText('HTTP protocol', t('The HTTP protocol label exists'), 'Acquia Search');
$this
->assertOptionSelected('edit-backend-config-connector-config-scheme', 'http', t('By default selected HTTP protocol'), 'Acquia Search');
$this
->assertNoText('Solr host', t('The Solr host label does not exist'), 'Acquia Search');
$this
->assertNoText('Solr port', t('The Solr port label does not exist'), 'Acquia Search');
$this
->assertNoText('Solr path', t('The Solr path label does not exist'), 'Acquia Search');
$this
->assertNoText('Basic HTTP authentication', t('The basic HTTP authentication label does not exist'), 'Acquia Search');
$this
->assertText('Solr version override', t('The selectbox "Solr version label" exist'), 'Acquia Search');
$this
->assertOptionByText('edit-backend-config-connector-config-workarounds-solr-version', 'Determine automatically', t('By default selected Solr version "Determine automatically"'), 'Acquia Search');
$this
->assertText('HTTP method', t('The HTTP method label exist'));
$this
->assertOptionSelected('edit-backend-config-connector-config-workarounds-http-method', 'AUTO', t('By default selected AUTO HTTP method'), 'Acquia Search');
$this
->drupalPostForm('/admin/config/search/search-api/server/' . $this->server . '/edit', [], 'Save');
$this
->drupalGet('/admin/config/search/search-api/server/' . $this->server . '/delete');
$this
->assertResponse(403, t('The Acquia Search Server cannot be deleted via the UI.'));
}
public function testAcquiaSearchIndexUi() {
$settings_path = 'admin/config/search/search-api';
$this
->drupalGet($settings_path);
$this
->clickLink('Edit', 1);
$this
->assertText('Datasources', t('The Data types label exist'), 'Acquia Search');
$this
->assertFieldChecked('edit-server-acquia-search-server', t('By default selected Acquia Search Server'), 'Acquia Search');
$this
->drupalGet('/admin/config/search/search-api/index/' . $this->index . '/fields');
$this
->assertOptionSelected('edit-fields-body-type', 'text', t('Body used for searching'), t('Acquia Search'));
$this
->assertOptionSelected('edit-fields-title-type', 'text', t('Title used for searching'), 'Acquia Search');
$this
->drupalPostForm('/admin/config/search/search-api/index/' . $this->index . '/edit', [], 'Save');
$this
->drupalGet('/admin/config/search/search-api/index/' . $this->index . '/delete');
$this
->assertResponse(403, t('The Acquia Search Server cannot be deleted via the UI.'));
}
}