From 4b420cc2eae351bd12abf5cba233d7735105cf60 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Wed, 20 Nov 2024 19:22:02 +0200 Subject: [PATCH] UHF-10990: Add test --- composer.json | 2 + .../Functional/ElasticsearchConnectorTest.php | 86 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/src/Functional/ElasticsearchConnectorTest.php diff --git a/composer.json b/composer.json index ac49bd6..62c933a 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,8 @@ "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "dg/bypass-finals": "^1.0", "drupal/coder": "^8.3", + "drupal/search_api": "^1.0", + "drupal/elasticsearch_connector": "^8.0@alpha", "donatj/mock-webserver": "dev-master" } } diff --git a/tests/src/Functional/ElasticsearchConnectorTest.php b/tests/src/Functional/ElasticsearchConnectorTest.php new file mode 100644 index 0000000..3a7f8da --- /dev/null +++ b/tests/src/Functional/ElasticsearchConnectorTest.php @@ -0,0 +1,86 @@ +drupalCreateUser([ + 'access administration pages', + 'administer search_api', + ]); + $this->drupalLogin($admin_user); + } + + /** + * Tests custom elasticsearch connector. + */ + public function testSearchApiConnector() { + // Add elasticsearch server configuration. + $config = $this->config('search_api.server.default'); + $config->setData([ + 'status' => TRUE, + 'id' => 'default', + 'name' => 'elasticsearch_server', + 'description' => 'Test server', + 'backend' => 'elasticsearch', + 'backend_config' => [ + 'connector' => 'helfi_connector', + 'connector_config' => [ + 'url' => 'http://elasticsearch.example.com:9200', + 'username' => '123', + 'password' => '456', + ], + ], + ]); + $config->save(); + + /** @var \Drupal\search_api\ServerInterface $server */ + $server = $this->container + ->get(EntityTypeManagerInterface::class) + ->getStorage('search_api_server') + ->load('default'); + + $backend = $server->getBackend(); + assert($backend instanceof ElasticSearchBackend); + $this->assertInstanceOf(HelfiConnector::class, $backend->getConnector()); + + $assert_session = $this->assertSession(); + $this->drupalGet(Url::fromRoute('entity.search_api_server.edit_form', [ + 'search_api_server' => 'default', + ])); + $assert_session->statusCodeEquals(200); + $assert_session->pageTextContains('Helfi Connector'); + } + +}