From 343f0ebbe84c483fc6891cb0456641e227ca2098 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Thu, 21 Nov 2024 12:42:21 +0200 Subject: [PATCH] UHF-10990: Kernel test --- .../ElasticsearchConnectorTest.php | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) rename tests/src/{Functional => Kernel}/ElasticsearchConnectorTest.php (66%) diff --git a/tests/src/Functional/ElasticsearchConnectorTest.php b/tests/src/Kernel/ElasticsearchConnectorTest.php similarity index 66% rename from tests/src/Functional/ElasticsearchConnectorTest.php rename to tests/src/Kernel/ElasticsearchConnectorTest.php index 3a7f8da..221b3de 100644 --- a/tests/src/Functional/ElasticsearchConnectorTest.php +++ b/tests/src/Kernel/ElasticsearchConnectorTest.php @@ -2,17 +2,18 @@ declare(strict_types=1); -namespace Drupal\Tests\helfi_api_base\Functional; +namespace Drupal\Tests\helfi_api_base\Kernel; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Url; +use Drupal\KernelTests\KernelTestBase; use Drupal\elasticsearch_connector\Plugin\search_api\backend\ElasticSearchBackend; use Drupal\helfi_api_base\Plugin\ElasticSearch\Connector\HelfiConnector; +use Elastic\Elasticsearch\Client; /** * Test for elasticsearch connector plugin. */ -class ElasticsearchConnectorTest extends BrowserTestBase { +class ElasticsearchConnectorTest extends KernelTestBase { /** * {@inheritdoc} @@ -23,23 +24,13 @@ class ElasticsearchConnectorTest extends BrowserTestBase { 'helfi_api_base', ]; - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - /** * {@inheritdoc} */ public function setUp(): void { parent::setUp(); - // Create an admin user. - $admin_user = $this->drupalCreateUser([ - 'access administration pages', - 'administer search_api', - ]); - $this->drupalLogin($admin_user); + $this->installEntitySchema('search_api_server'); } /** @@ -73,14 +64,9 @@ public function testSearchApiConnector() { $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'); + $connector = $backend->getConnector(); + $this->assertInstanceOf(HelfiConnector::class, $connector); + $this->assertInstanceOf(Client::class, $connector->getClient()); } }