class StopwordsTest in Search API 8
Tests the "Stopwords" processor.
@group search_api
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\search_api\Unit\Processor\StopwordsTest uses ProcessorTestTrait
Expanded class hierarchy of StopwordsTest
See also
\Drupal\search_api\Plugin\search_api\processor\Stopwords
File
- tests/
src/ Unit/ Processor/ StopwordsTest.php, line 16
Namespace
Drupal\Tests\search_api\Unit\ProcessorView source
class StopwordsTest extends UnitTestCase {
use ProcessorTestTrait, TestItemsTrait;
/**
* Creates a new processor object for use in the tests.
*/
protected function setUp() {
parent::setUp();
$this
->setUpMockContainer();
$this->processor = new Stopwords([], 'stopwords', []);
}
/**
* Tests the process() method of the Stopwords processor.
*
* @param string $passed_value
* The string that should be passed to process().
* @param string $expected_value
* The expected altered string.
* @param string[] $stopwords
* The stopwords with which to configure the test processor.
*
* @dataProvider processDataProvider
*/
public function testProcess($passed_value, $expected_value, array $stopwords) {
$this->processor
->setConfiguration([
'stopwords' => $stopwords,
]);
$this
->invokeMethod('process', [
&$passed_value,
]);
$this
->assertEquals($expected_value, $passed_value);
}
/**
* Data provider for testStopwords().
*
* Processor checks for exact case, and tokenized content.
*/
public function processDataProvider() {
return [
[
'or',
'',
[
'or',
],
],
[
'orb',
'orb',
[
'or',
],
],
[
'for',
'for',
[
'or',
],
],
[
'ordor',
'ordor',
[
'or',
],
],
[
'ÄÖÜÀÁ<>»«û',
'ÄÖÜÀÁ<>»«û',
[
'stopword1',
'ÄÖÜÀÁ<>»«',
'stopword3',
],
],
[
'ÄÖÜÀÁ',
'',
[
'stopword1',
'ÄÖÜÀÁ',
'stopword3',
],
],
[
'ÄÖÜÀÁ stopword1',
'ÄÖÜÀÁ stopword1',
[
'stopword1',
'ÄÖÜÀÁ',
'stopword3',
],
],
];
}
/**
* Tests the processor's preprocessSearchQuery() method.
*/
public function testPreprocessSearchQuery() {
$index = $this
->createMock(IndexInterface::class);
$index
->expects($this
->any())
->method('status')
->will($this
->returnValue(TRUE));
/** @var \Drupal\search_api\IndexInterface $index */
$this->processor
->setIndex($index);
$query = \Drupal::getContainer()
->get('search_api.query_helper')
->createQuery($index);
$keys = [
'#conjunction' => 'AND',
'foo',
'bar',
'bar foo',
];
$query
->keys($keys);
$configuration = [
'stopwords' => [
'foobar',
'bar',
'barfoo',
],
];
$this->processor
->setConfiguration($configuration);
$this->processor
->preprocessSearchQuery($query);
unset($keys[1]);
$this
->assertEquals($keys, $query
->getKeys());
$this
->assertEquals([
'bar',
], $query
->getResults()
->getIgnoredSearchKeys());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
ProcessorTestTrait:: |
protected | property | The tested processor. | |
ProcessorTestTrait:: |
protected | function | Invokes a method on the processor. | |
StopwordsTest:: |
public | function | Data provider for testStopwords(). | |
StopwordsTest:: |
protected | function |
Creates a new processor object for use in the tests. Overrides UnitTestCase:: |
|
StopwordsTest:: |
public | function | Tests the processor's preprocessSearchQuery() method. | |
StopwordsTest:: |
public | function | Tests the process() method of the Stopwords processor. | |
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. |