-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tests/modules/oe_search_test/config/install/search_api.index.europa_search_index.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- entity_test | ||
- search_api | ||
config: | ||
- search_api.server.europa_search_server | ||
id: europa_search_index | ||
name: 'Europa search index' | ||
description: 'Test index.' | ||
read_only: false | ||
field_settings: | ||
id: | ||
label: ID | ||
type: integer | ||
datasource_id: 'entity:entity_test_mulrev_changed' | ||
property_path: id | ||
name: | ||
label: Name | ||
type: text | ||
datasource_id: 'entity:entity_test_mulrev_changed' | ||
property_path: name | ||
boost: 5.0 | ||
created: | ||
label: Authored on | ||
type: date | ||
datasource_id: 'entity:entity_test_mulrev_changed' | ||
property_path: created | ||
body: | ||
label: Body | ||
type: text | ||
datasource_id: 'entity:entity_test_mulrev_changed' | ||
property_path: body | ||
datasource_settings: | ||
'entity:entity_test_mulrev_changed': { } | ||
processor_settings: | ||
add_url: { } | ||
aggregated_field: { } | ||
language_with_fallback: { } | ||
rendered_item: { } | ||
tracker_settings: | ||
default: | ||
indexing_order: fifo | ||
options: | ||
index_directly: true | ||
cron_limit: 50 | ||
server: europa_search_server |
20 changes: 20 additions & 0 deletions
20
tests/modules/oe_search_test/config/install/search_api.server.europa_search_server.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- oe_search | ||
id: europa_search_server | ||
name: 'Europa search server' | ||
description: 'Test server.' | ||
backend: search_api_europa_search | ||
backend_config: | ||
api_key: api-key | ||
enable_ingestion: true | ||
database: db | ||
text_ingestion_api_endpoint: 'http://example.com/ingest/text' | ||
file_ingestion_api_endpoint: 'http://example.com/ingest' | ||
delete_api_endpoint: 'http://example.com/document' | ||
token_api_endpoint: 'http://example.com/token' | ||
search_api_endpoint: 'http://example.com/search' | ||
facets_api_endpoint: 'http://example.com/search/facets' | ||
info_api_endpoint: 'http://example.com/search/info' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: 'OpenEuropa Search Test' | ||
description: 'Test module for the OpenEuropa Search.' | ||
package: Testing | ||
|
||
type: module | ||
core_version_requirement: ^8.9 || ^9 | ||
|
||
dependencies: | ||
- oe_search:oe_search |
38 changes: 38 additions & 0 deletions
38
tests/modules/oe_search_test/src/Plugin/ServiceMock/EuropaSearchServerResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\http_request_mock\Plugin\ServiceMock; | ||
|
||
use Drupal\Core\Plugin\PluginBase; | ||
use Drupal\http_request_mock\ServiceMockPluginInterface; | ||
use GuzzleHttp\Psr7\Response; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* Intercepts any HTTP request made to example.com. | ||
* | ||
* @ServiceMock( | ||
* id = "europa_search_server_response", | ||
* label = @Translation("Europa Search mocked server responses for tesing."), | ||
* weight = 0, | ||
* ) | ||
*/ | ||
class EuropaSearchServerResponse extends PluginBase implements ServiceMockPluginInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function applies(RequestInterface $request, array $options): bool { | ||
return $request->getUri()->getHost() === 'example.com'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getResponse(RequestInterface $request, array $options): ResponseInterface { | ||
return new Response(200, [], 'Mocking example.com response'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\oe_search\Tests; | ||
|
||
use Drupal\KernelTests\KernelTestBase; | ||
use Drupal\search_api\Entity\Index; | ||
use Drupal\search_api\Entity\Server; | ||
use Drupal\search_api\Utility\Utility; | ||
use Drupal\Tests\search_api\Functional\ExampleContentTrait; | ||
|
||
/** | ||
* Class for testing Europa Search drupal integration. | ||
*/ | ||
class BackendTest extends KernelTestBase { | ||
use ExampleContentTrait; | ||
|
||
/** | ||
* A Search API server ID. | ||
* | ||
* @var string | ||
*/ | ||
protected $serverId = 'europa_search_server'; | ||
|
||
/** | ||
* A Search API index ID. | ||
* | ||
* @var string | ||
*/ | ||
protected $indexId = 'europa_search_index'; | ||
|
||
/** | ||
* Modules to enable. | ||
* | ||
* @var array | ||
*/ | ||
protected static $modules = [ | ||
'field', | ||
'user', | ||
'system', | ||
'entity_test', | ||
'search_api', | ||
'oe_search', | ||
'oe_search_test', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->installSchema('search_api', ['search_api_item']); | ||
$this->installSchema('user', ['users_data']); | ||
$this->installEntitySchema('entity_test_mulrev_changed'); | ||
$this->installEntitySchema('search_api_task'); | ||
$this->installConfig([ | ||
'search_api', | ||
'oe_search', | ||
'oe_search_test', | ||
]); | ||
|
||
// Do not use a batch for tracking the initial items after creating an | ||
// index when running the tests via the GUI. Otherwise, it seems Drupal's | ||
// Batch API gets confused and the test fails. | ||
if (!Utility::isRunningInCli()) { | ||
\Drupal::state()->set('search_api_use_tracking_batch', FALSE); | ||
} | ||
|
||
entity_test_create_bundle('item', NULL, 'entity_test_mulrev_changed'); | ||
} | ||
|
||
/** | ||
* Test Ingestion. | ||
*/ | ||
public function testIndexItems(): void { | ||
$backend = Server::load($this->serverId)->getBackend(); | ||
$index = Index::load($this->indexId); | ||
$items = []; | ||
$backend->indexItems($index, $items); | ||
$this->assertTrue(TRUE); | ||
} | ||
|
||
} |