public function StemmerTest::testPreprocessSearchQuery in Snowball Stemmer 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Plugin/Processor/StemmerTest.php \Drupal\Tests\snowball_stemmer\Unit\Plugin\Processor\StemmerTest::testPreprocessSearchQuery()
Tests preprocessSearchQuery() method.
@covers ::preprocessIndexItems
File
- tests/
src/ Unit/ Plugin/ Processor/ StemmerTest.php, line 190
Class
- StemmerTest
- Tests the "Stemmer" processor.
Namespace
Drupal\Tests\snowball_stemmer\Unit\Plugin\ProcessorCode
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);
$language = $this
->createMock(LanguageInterface::class);
$language
->expects($this
->any())
->method('getId')
->will($this
->returnValue('en'));
$this->languageManager
->expects($this
->any())
->method('getCurrentLanguage')
->will($this
->returnValue($language));
$this->stemmerService
->expects($this
->once())
->method('setLanguage')
->with('en')
->will($this
->returnValue(TRUE));
$this->stemmerService
->expects($this
->exactly(4))
->method('stem')
->withConsecutive([
'fooing',
], [
'bar',
], [
'bary',
], [
'foo',
])
->will($this
->onConsecutiveCalls('foo', 'bar', 'bar', 'foo'));
$query = \Drupal::getContainer()
->get('search_api.query_helper')
->createQuery($index);
$keys = [
'#conjunction' => 'AND',
'fooing',
'bar',
'bary foo',
];
$query
->keys($keys);
$this->processor
->preprocessSearchQuery($query);
$this
->assertEquals([
'#conjunction' => 'AND',
'foo',
'bar',
'bar foo',
], $query
->getKeys());
}