class HtmlFilterTest in Search API Solr 4.x
Same name in this branch
- 4.x tests/src/Kernel/Processor/HtmlFilterTest.php \Drupal\Tests\search_api_solr\Kernel\Processor\HtmlFilterTest
- 4.x modules/search_api_solr_legacy/tests/src/Kernel/Processor/HtmlFilterTest.php \Drupal\Tests\search_api_solr_legacy\Kernel\Processor\HtmlFilterTest
Same name and namespace in other branches
- 8.3 tests/src/Kernel/Processor/HtmlFilterTest.php \Drupal\Tests\search_api_solr\Kernel\Processor\HtmlFilterTest
Tests usages of Solr payloads.
@group search_api_solr
Hierarchy
- class \Drupal\Tests\search_api_solr\Kernel\Processor\HtmlFilterTest extends \Drupal\Tests\search_api\Kernel\Processor\ProcessorTestBase uses NodeCreationTrait, SolrBackendTrait
Expanded class hierarchy of HtmlFilterTest
See also
\Drupal\search_api\Plugin\search_api\processor\HtmlFilter
1 file declares its use of HtmlFilterTest
- HtmlFilterTest.php in modules/
search_api_solr_legacy/ tests/ src/ Kernel/ Processor/ HtmlFilterTest.php
File
- tests/
src/ Kernel/ Processor/ HtmlFilterTest.php, line 18
Namespace
Drupal\Tests\search_api_solr\Kernel\ProcessorView source
class HtmlFilterTest extends ProcessorTestBase {
use NodeCreationTrait;
use SolrBackendTrait;
/**
* The nodes created for testing.
*
* @var \Drupal\node\Entity\Node[]
*/
protected $nodes;
/**
* {@inheritdoc}
*/
public static $modules = [
'filter',
'search_api_solr',
'search_api_solr_test',
];
/**
* {@inheritdoc}
*/
public function setUp($processor = NULL) : void {
parent::setUp('html_filter');
$this
->enableSolrServer();
$this
->installConfig([
'filter',
]);
// Create a node type for testing.
$type = NodeType::create([
'type' => 'page',
'name' => 'page',
]);
$type
->save();
}
/**
* Tests term boosts.
*/
public function testBoostTerms() {
$solr_major_version = $this->server
->getBackend()
->getSolrConnector()
->getSolrMajorVersion();
if (version_compare($solr_major_version, '6', '<')) {
$this
->markTestSkipped('Term boosting requires Solr >= 6.');
return;
}
$this
->assertArrayHasKey('html_filter', $this->index
->getProcessors(), 'HTML filter processor is added.');
$this
->createNode([
'type' => 'page',
'title' => 'Beautiful Page 1',
]);
$this
->createNode([
'type' => 'page',
'title' => 'Beautiful <b>Page</b> 2',
]);
$this
->createNode([
'type' => 'page',
'title' => 'Beautiful Page 3',
]);
$this->index
->reindex();
$this
->indexItems();
$query = new Query($this->index);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$query
->getParseMode()
->setConjunction('OR');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/1:en',
'entity:node/2:en',
'entity:node/3:en',
], array_keys($result
->getResultItems()));
$query = new Query($this->index);
$query
->keys([
'beautiful',
]);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$query
->getParseMode()
->setConjunction('OR');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/1:en',
'entity:node/2:en',
'entity:node/3:en',
], array_keys($result
->getResultItems()));
// Rerank query based on payloads for HTML tags boosts on match.
$query = new Query($this->index);
$query
->keys([
'page',
]);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$query
->getParseMode()
->setConjunction('OR');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/2:en',
'entity:node/1:en',
'entity:node/3:en',
], array_keys($result
->getResultItems()));
$this
->createNode([
'type' => 'page',
'title' => "d'avion",
]);
$this
->createNode([
'type' => 'page',
'title' => "<b>d'avion<b>",
]);
$this
->createNode([
'type' => 'page',
'title' => '๐๐๐พ',
]);
$this
->createNode([
'type' => 'page',
'title' => '<b>More| strange " characters ๐๐๐พ<b>',
]);
$this
->createNode([
'type' => 'page',
'title' => 'More| strange " characters ๐๐๐พ',
]);
$this
->indexItems();
$query = new Query($this->index);
$query
->keys([
"d'avion",
]);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$query
->getParseMode()
->setConjunction('OR');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/5:en',
'entity:node/4:en',
], array_keys($result
->getResultItems()));
$query = new Query($this->index);
$query
->keys([
'๐๐๐พ',
]);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$query
->getParseMode()
->setConjunction('OR');
$result = $query
->execute();
$this
->assertEquals([
'entity:node/7:en',
'entity:node/6:en',
'entity:node/8:en',
], array_keys($result
->getResultItems()));
$this
->createNode([
'type' => 'page',
'title' => "<b>VeryLongStingsWithMoreThanOneHoundredCharactersShouldNotNeitherBeIndexedAsTextNorAsBoostedTokenAndShouldNotLeadToExceptionsDuringIndexing<b>",
]);
$this
->indexItems();
$query = new Query($this->index);
$query
->keys([
'VeryLongStingsWithMoreThanOneHoundredCharactersShouldNotNeitherBeIndexedAsTextNorAsBoostedTokenAndShouldNotLeadToExceptionsDuringIndexing',
]);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$query
->getParseMode()
->setConjunction('OR');
$result = $query
->execute();
$this
->assertEquals([], array_keys($result
->getResultItems()));
$this
->createNode([
'type' => 'page',
'title' => "<b>VeryLongStingsWithMoreThanOneHoundredCharactersShouldNotNeitherBeIndexedAsTextNorAsBoostedTokenAndShouldNotLeadToExceptionsDuringIndexing<b>",
]);
$this
->indexItems();
$query = new Query($this->index);
$query
->keys([
'VeryLongStingsWithMoreThanOneHoundredCharactersShouldNotNeitherBeIndexedAsTextNorAsBoostedTokenAndShouldNotLeadToExceptionsDuringIndexing',
]);
$query
->sort('search_api_relevance', QueryInterface::SORT_DESC);
$query
->sort('search_api_id');
$query
->getParseMode()
->setConjunction('OR');
$result = $query
->execute();
$this
->assertEquals([], array_keys($result
->getResultItems()));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HtmlFilterTest:: |
public static | property | 1 | |
HtmlFilterTest:: |
protected | property | The nodes created for testing. | |
HtmlFilterTest:: |
public | function | ||
HtmlFilterTest:: |
public | function | Tests term boosts. | |
NodeCreationTrait:: |
protected | function | Creates a node based on default settings. | |
NodeCreationTrait:: |
public | function | Get a node from the database based on its title. | |
SolrBackendTrait:: |
protected | function | Swap the DB backend for a Solr backend. | 3 |
SolrBackendTrait:: |
protected | function | ||
SolrBackendTrait:: |
protected | function | ||
SolrCommitTrait:: |
protected | function | Explicitly sends a commit command to a Solr server. |