|
4 | 4 |
|
5 | 5 | use Drupal\Component\Render\FormattableMarkup;
|
6 | 6 | use Drupal\search_api\Entity\Server;
|
| 7 | +use Drupal\search_api\Plugin\search_api\data_type\value\TextToken; |
| 8 | +use Drupal\search_api\Plugin\search_api\data_type\value\TextValue; |
7 | 9 | use Drupal\search_api\Query\QueryInterface;
|
8 | 10 | use Drupal\search_api\SearchApiException;
|
| 11 | +use Drupal\search_api\Utility\Utility; |
9 | 12 | use Drupal\search_api_db\Plugin\search_api\backend\Database;
|
10 | 13 | use Drupal\search_api_db\Tests\DatabaseTestsTrait;
|
11 | 14 | use Drupal\Tests\search_api\Kernel\BackendTestBase;
|
@@ -80,6 +83,7 @@ protected function backendSpecificRegressionTests() {
|
80 | 83 | $this->regressionTest2557291();
|
81 | 84 | $this->regressionTest2511860();
|
82 | 85 | $this->regressionTest2846932();
|
| 86 | + $this->regressionTest2926733(); |
83 | 87 | }
|
84 | 88 |
|
85 | 89 | /**
|
@@ -476,6 +480,38 @@ protected function regressionTest2846932() {
|
476 | 480 | $index->save();
|
477 | 481 | }
|
478 | 482 |
|
| 483 | + /** |
| 484 | + * Tests indexing of text tokens with leading/trailing whitespace. |
| 485 | + * |
| 486 | + * @see https://www.drupal.org/node/2926733 |
| 487 | + */ |
| 488 | + protected function regressionTest2926733() { |
| 489 | + $index = $this->getIndex(); |
| 490 | + $item_id = $this->getItemIds([1])[0]; |
| 491 | + $fields_helper = \Drupal::getContainer() |
| 492 | + ->get('search_api.fields_helper'); |
| 493 | + $item = $fields_helper->createItem($index, $item_id); |
| 494 | + $field = clone $index->getField('body'); |
| 495 | + $value = new TextValue('test'); |
| 496 | + $tokens = []; |
| 497 | + foreach (['test', ' test', ' test', 'test ', ' test '] as $token) { |
| 498 | + $tokens[] = new TextToken($token); |
| 499 | + } |
| 500 | + $value->setTokens($tokens); |
| 501 | + $field->setValues([$value]); |
| 502 | + $item->setFields([ |
| 503 | + 'body' => $field, |
| 504 | + ]); |
| 505 | + $item->setFieldsExtracted(TRUE); |
| 506 | + $index->getServerInstance()->indexItems($index, [$item_id => $item]); |
| 507 | + |
| 508 | + // Make sure to re-index the proper version of the item to avoid confusing |
| 509 | + // the other tests. |
| 510 | + list($datasource_id, $raw_id) = Utility::splitCombinedId($item_id); |
| 511 | + $index->trackItemsUpdated($datasource_id, [$raw_id]); |
| 512 | + $this->indexItems($index->id()); |
| 513 | + } |
| 514 | + |
479 | 515 | /**
|
480 | 516 | * {@inheritdoc}
|
481 | 517 | */
|
|
0 commit comments