You are here

public function DoubleQuoteWorkaroundTest::testDoubleQuoteWorkaround in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/Processor/DoubleQuoteWorkaroundTest.php \Drupal\Tests\search_api_solr\Kernel\Processor\DoubleQuoteWorkaroundTest::testDoubleQuoteWorkaround()
  2. 8.2 tests/src/Kernel/Processor/DoubleQuoteWorkaroundTest.php \Drupal\Tests\search_api_solr\Kernel\Processor\DoubleQuoteWorkaroundTest::testDoubleQuoteWorkaround()

Tests double quote workaround.

File

tests/src/Kernel/Processor/DoubleQuoteWorkaroundTest.php, line 53

Class

DoubleQuoteWorkaroundTest
Tests the "Double Quote Workaround" processor.

Namespace

Drupal\Tests\search_api_solr\Kernel\Processor

Code

public function testDoubleQuoteWorkaround() {
  $processor = $this->index
    ->getProcessor('double_quote_workaround');
  $configuration = $processor
    ->getConfiguration();
  $replacement = $configuration['replacement'];
  $this
    ->assertEquals('|9999999998|', $replacement);

  // Set fields to process.
  $configuration['fields'] = [
    'title',
  ];
  $processor
    ->setConfiguration($configuration);
  $this->index
    ->setProcessors([
    'double_quote_workaround' => $processor,
  ]);
  $this->index
    ->save();
  $streaming_expression = $this->exp
    ->search($this->exp
    ->_collection(), 'q=' . $this->exp
    ->_field_escaped_value('search_api_datasource', 'entity:entity_test_mulrev_changed'), 'fq="' . $this->exp
    ->_field_escaped_value('title', 'double "quotes" within the text', FALSE) . '"', 'fl="' . $this->exp
    ->_field('title') . '"', 'sort="' . $this->exp
    ->_field('search_api_id') . ' DESC"', 'qt="/export"');
  $this
    ->assertEquals('search(drupal, q=ss_search_api_datasource:entity\\:entity_test_mulrev_changed, fq="tm_X3b_und_title:\\"double ' . $replacement . 'quotes' . $replacement . ' within the text\\"", fl="tm_X3b_und_title", sort="ss_search_api_id DESC", qt="/export")', $streaming_expression);
  $this
    ->assertEquals('double "quotes" within the text', $this->processor
    ->decodeStreamingExpressionValue('double ' . $replacement . 'quotes' . $replacement . ' within the text'));
}