class BackendPluginBaseTest in Search API 8
Tests methods provided by the backend plugin base class.
@coversDefaultClass \Drupal\search_api\Backend\BackendPluginBase
@group search_api
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\search_api\Unit\BackendPluginBaseTest
Expanded class hierarchy of BackendPluginBaseTest
File
- tests/
src/ Unit/ BackendPluginBaseTest.php, line 17
Namespace
Drupal\Tests\search_api\UnitView source
class BackendPluginBaseTest extends UnitTestCase {
/**
* Tests whether fulltext fields are correctly extracted from queries.
*
* @param string[]|null $query_fields
* The fulltext fields set explicitly on the query, if any.
* @param string[] $expected
* The field IDs that are expected to be returned.
*
* @covers ::getQueryFulltextFields
*
* @dataProvider getQueryFulltextFieldsDataProvider
*/
public function testGetQueryFulltextFields($query_fields, array $expected) {
$index = $this
->createMock(IndexInterface::class);
$index
->method('getFulltextFields')
->willReturn([
'field1',
'field2',
]);
$query = $this
->createMock(QueryInterface::class);
$query
->method('getFulltextFields')
->willReturn($query_fields);
$query
->method('getIndex')
->willReturn($index);
$backend = new TestBackend([], '', []);
$class = new \ReflectionClass(TestBackend::class);
$method = $class
->getMethod('getQueryFulltextFields');
$method
->setAccessible(TRUE);
$this
->assertEquals($expected, $method
->invokeArgs($backend, [
$query,
]));
}
/**
* Provides test data for testGetQueryFulltextFields().
*
* @return array[]
* An array of argument arrays for testGetQueryFulltextFields().
*/
public function getQueryFulltextFieldsDataProvider() {
return [
'null fields' => [
NULL,
[
'field1',
'field2',
],
],
'field1' => [
[
'field1',
],
[
'field1',
],
],
'field2' => [
[
'field2',
],
[
'field2',
],
],
'all fields' => [
[
'field1',
'field2',
],
[
'field1',
'field2',
],
],
'invalid fields' => [
[
'field1',
'foo',
],
[
'field1',
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BackendPluginBaseTest:: |
public | function | Provides test data for testGetQueryFulltextFields(). | |
BackendPluginBaseTest:: |
public | function | Tests whether fulltext fields are correctly extracted from queries. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |