class SearchApiBackendUnitTest in Search API Solr 8.3
Same name and namespace in other branches
- 8 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest
- 8.2 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest
- 4.x tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest
Tests functionality of the backend.
@coversDefaultClass \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend
@group search_api_solr
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest uses InvokeMethodTrait
Expanded class hierarchy of SearchApiBackendUnitTest
File
- tests/
src/ Unit/ SearchApiBackendUnitTest.php, line 29
Namespace
Drupal\Tests\search_api_solr\UnitView source
class SearchApiBackendUnitTest extends UnitTestCase {
use InvokeMethodTrait;
/**
* @var \Drupal\search_api_solr\Controller\AbstractSolrEntityListBuilder|\Prophecy\Prophecy\ObjectProphecy
*/
protected $listBuilder;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $entityTypeManager;
/**
* @var \Solarium\Core\Query\Helper
*/
protected $queryHelper;
/**
* @var \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend
*/
protected $backend;
/**
*
*/
public function setUp() {
parent::setUp();
$this->listBuilder = $this
->prophesize(AbstractSolrEntityListBuilder::class);
$this->listBuilder
->getAllNotRecommendedEntities()
->willReturn([]);
$this->entityTypeManager = $this
->prophesize(EntityTypeManagerInterface::class);
$this->entityTypeManager
->getListBuilder('solr_field_type')
->willReturn($this->listBuilder
->reveal());
$this->entityTypeManager
->getListBuilder('solr_cache')
->willReturn($this->listBuilder
->reveal());
$this->entityTypeManager
->getListBuilder('solr_request_handler')
->willReturn($this->listBuilder
->reveal());
$this->entityTypeManager
->getListBuilder('solr_request_dispatcher')
->willReturn($this->listBuilder
->reveal());
// This helper is actually used.
$this->queryHelper = new Helper();
$this->backend = new SearchApiSolrBackend([], NULL, [], $this
->prophesize(ModuleHandlerInterface::class)
->reveal(), $this
->prophesize(Config::class)
->reveal(), $this
->prophesize(LanguageManagerInterface::class)
->reveal(), $this
->prophesize(SolrConnectorPluginManager::class)
->reveal(), $this
->prophesize(FieldsHelperInterface::class)
->reveal(), $this
->prophesize(DataTypeHelperInterface::class)
->reveal(), $this->queryHelper, $this->entityTypeManager
->reveal());
}
/**
* @covers ::addIndexField
*
* @dataProvider addIndexFieldDataProvider
*
* @param mixed $input
* Field value.
*
* @param string $type
* Field type.
*
* @param mixed $expected
* Expected result.
*/
public function testIndexField($input, $type, $expected) {
$field = 'testField';
$document = $this
->prophesize(Document::class);
if (NULL !== $expected) {
if (is_array($expected)) {
$document
->addField($field, $expected[0], $expected[1])
->shouldBeCalled();
}
else {
$document
->addField($field, $expected)
->shouldBeCalled();
}
}
else {
$document
->addField($field, $expected)
->shouldNotBeCalled();
}
$args = [
$document
->reveal(),
$field,
[
$input,
],
$type,
];
// addIndexField() should convert the $input according to $type and call
// Document::addField() with the correctly converted $input.
$this
->invokeMethod($this->backend, 'addIndexField', $args, []);
}
/**
*
*/
public function testFormatDate() {
$this
->assertFalse($this->backend
->formatDate('asdf'));
$this
->assertEquals('1992-08-27T00:00:00Z', $this->backend
->formatDate('1992-08-27'));
}
/**
* Data provider for testIndexField method.
*/
public function addIndexFieldDataProvider() {
return [
// addIndexField() should be called.
[
'0',
'boolean',
'false',
],
[
'1',
'boolean',
'true',
],
[
0,
'boolean',
'false',
],
[
1,
'boolean',
'true',
],
[
FALSE,
'boolean',
'false',
],
[
TRUE,
'boolean',
'true',
],
[
'2016-05-25T14:00:00+10',
'date',
'2016-05-25T04:00:00Z',
],
[
'1465819200',
'date',
'2016-06-13T12:00:00Z',
],
[
new DateRangeValue('2016-05-25T14:00:00+10', '2017-05-25T14:00:00+10'),
'solr_date_range',
'[2016-05-25T04:00:00Z TO 2017-05-25T04:00:00Z]',
],
[
-1,
'integer',
-1,
],
[
0,
'integer',
0,
],
[
1,
'integer',
1,
],
[
-1.0,
'decimal',
-1.0,
],
[
0.0,
'decimal',
0.0,
],
[
1.3,
'decimal',
1.3,
],
[
'foo',
'string',
'foo',
],
[
new TextValue('foo bar'),
'text',
'foo bar',
],
[
(new TextValue(''))
->setTokens([
new TextToken('bar'),
]),
'text',
'bar',
],
// addIndexField() should not be called.
[
NULL,
'boolean',
NULL,
],
[
NULL,
'date',
NULL,
],
[
NULL,
'solr_date_range',
NULL,
],
[
NULL,
'integer',
NULL,
],
[
NULL,
'decimal',
NULL,
],
[
NULL,
'string',
NULL,
],
[
'',
'string',
NULL,
],
[
new TextValue(''),
'text',
NULL,
],
[
(new TextValue(''))
->setTokens([
new TextToken(''),
]),
'text',
NULL,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InvokeMethodTrait:: |
protected | function | Calls protected/private method of a class. | |
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. | |
SearchApiBackendUnitTest:: |
protected | property | ||
SearchApiBackendUnitTest:: |
protected | property | ||
SearchApiBackendUnitTest:: |
protected | property | ||
SearchApiBackendUnitTest:: |
protected | property | ||
SearchApiBackendUnitTest:: |
public | function | Data provider for testIndexField method. | |
SearchApiBackendUnitTest:: |
public | function |
Overrides UnitTestCase:: |
|
SearchApiBackendUnitTest:: |
public | function | ||
SearchApiBackendUnitTest:: |
public | function | @covers ::addIndexField | |
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. |