-
Notifications
You must be signed in to change notification settings - Fork 17
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
1 changed file
with
116 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
modules/thunder_gqls/tests/src/Kernel/DataProducer/ThunderSearchApiTest.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,116 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\thunder_gqls\Kernel\DataProducer; | ||
|
||
use Drupal\search_api\Entity\Index; | ||
use Drupal\search_api\Entity\Server; | ||
use Drupal\Tests\graphql\Kernel\GraphQLTestBase; | ||
|
||
/** | ||
* Test entities_with_term data producer. | ||
* | ||
* @group Thunder | ||
*/ | ||
class ThunderSearchApiTest extends GraphQLTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'search_api', | ||
'search_api_test', | ||
'thunder_gqls', | ||
]; | ||
|
||
/** | ||
* The search server used for testing. | ||
* | ||
* @var \Drupal\search_api\ServerInterface | ||
*/ | ||
protected $server; | ||
|
||
/** | ||
* The search index used for testing. | ||
* | ||
* @var \Drupal\search_api\IndexInterface | ||
*/ | ||
protected $index; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->installSchema('search_api', [ | ||
'search_api_item', | ||
]); | ||
$this->installEntitySchema('search_api_task'); | ||
$this->installConfig('search_api'); | ||
|
||
// Create a test server. | ||
$this->server = Server::create([ | ||
'name' => 'Test Server', | ||
'id' => 'test_server', | ||
'status' => 1, | ||
'backend' => 'search_api_test', | ||
]); | ||
$this->server->save(); | ||
|
||
$this->index = Index::create([ | ||
'name' => 'Test Index', | ||
'id' => 'test_index', | ||
'status' => 1, | ||
'tracker_settings' => [ | ||
'default' => [], | ||
], | ||
'datasource_settings' => [ | ||
'entity:node' => [], | ||
], | ||
'server' => $this->server->id(), | ||
'options' => ['index_directly' => FALSE], | ||
]); | ||
$this->index->save(); | ||
|
||
$schema = <<<GQL | ||
type Query { | ||
search: SearchApiResult | ||
} | ||
type SearchApiResult { | ||
total: Int! | ||
} | ||
GQL; | ||
|
||
$this->setUpSchema($schema); | ||
} | ||
|
||
/** | ||
* Test cache metadata for the query. | ||
*/ | ||
public function testQueryCacheMetadata(): void { | ||
$query = <<<GQL | ||
query { | ||
search { | ||
total | ||
} | ||
} | ||
GQL; | ||
|
||
$this->mockResolver('Query', 'search', | ||
$this->builder->produce('thunder_search_api') | ||
->map('index', $this->builder->fromValue('test_index')) | ||
->map('offset', $this->builder->fromValue(0)) | ||
->map('limit', $this->builder->fromValue(20)) | ||
); | ||
$this->mockResolver('SearchApiResult', 'total', $this->builder->fromValue(1)); | ||
|
||
$metadata = $this->defaultCacheMetaData(); | ||
$metadata->setCacheContexts(['languages:language_interface', 'user.permissions', 'user.node_grants:view']); | ||
$metadata->addCacheTags(['config:search_api.index.test_index', 'node_list']); | ||
|
||
$this->assertResults($query, [], [ | ||
'search' => ['total' => '1'], | ||
], $metadata); | ||
} | ||
|
||
} |