View source
<?php
namespace Drupal\Tests\facets\Functional;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Processor\SortProcessorInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\search_api\Item\Field;
class ProcessorIntegrationTest extends FacetsTestBase {
protected $editForm;
public static $modules = [
'facets_custom_widget',
'options',
];
public function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminUser);
$this
->setUpExampleStructure();
$this
->insertExampleContent();
$this
->assertEquals($this
->indexItems($this->indexId), 5, '5 items were indexed.');
$this
->insertExampleContent();
$this
->assertEquals($this
->indexItems($this->indexId), 5, '5 items were indexed.');
}
public function testProcessorAdmin() {
$facet_name = "Guanaco";
$facet_id = "guanaco";
$this
->createFacet($facet_name, $facet_id);
$this
->drupalGet('admin/config/search/facets/' . $facet_id . '/edit');
$this
->assertSession()
->checkboxNotChecked('edit-facet-settings-count-limit-status');
$form = [
'facet_settings[count_limit][status]' => TRUE,
];
$this
->drupalPostForm(NULL, $form, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxChecked('edit-facet-settings-count-limit-status');
$form = [
'facet_sorting[active_widget_order][status]' => TRUE,
'facet_sorting[active_widget_order][settings][sort]' => 'DESC',
];
$this
->drupalPostForm(NULL, $form, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxChecked('edit-facet-sorting-active-widget-order-status');
$this
->assertSession()
->checkboxChecked('edit-facet-sorting-active-widget-order-settings-sort-desc');
$form = [
'facet_settings[hide_non_narrowing_result_processor][status]' => TRUE,
'facet_settings[count_limit][status]' => TRUE,
];
$this
->drupalPostForm(NULL, $form, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxChecked('edit-facet-settings-count-limit-status');
$this
->assertSession()
->checkboxChecked('edit-facet-settings-hide-non-narrowing-result-processor-status');
$this
->assertOptionSelected('edit-processors-count-limit-weights-build', 50);
$this
->assertOptionSelected('edit-processors-hide-non-narrowing-result-processor-weights-build', 40);
$form = [
'facet_settings[hide_non_narrowing_result_processor][status]' => TRUE,
'facet_settings[count_limit][status]' => TRUE,
'processors[hide_non_narrowing_result_processor][weights][build]' => 5,
];
$this
->drupalPostForm(NULL, $form, 'Save');
$this
->assertSession()
->checkboxChecked('edit-facet-settings-count-limit-status');
$this
->assertSession()
->checkboxChecked('edit-facet-settings-hide-non-narrowing-result-processor-status');
$this
->assertOptionSelected('edit-processors-count-limit-weights-build', 50);
$this
->assertOptionSelected('edit-processors-hide-non-narrowing-result-processor-weights-build', 5);
}
public function testProcessorIntegration() {
$facet_name = "Vicuña";
$facet_id = "vicuna";
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet($facet_name, $facet_id, 'keywords');
$this
->drupalPostForm($this->editForm, [
'facet_settings[query_operator]' => 'and',
], 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 10 search results');
$this
->assertSession()
->pageTextContains('grape');
$this
->assertSession()
->pageTextContains('orange');
$this
->assertSession()
->pageTextContains('apple');
$this
->assertSession()
->pageTextContains('strawberry');
$this
->assertSession()
->pageTextContains('banana');
$this
->checkCountLimitProcessor();
$this
->checkExcludeItems();
$this
->checkHideNonNarrowingProcessor();
$this
->checkHideActiveItems();
}
public function testBooleanProcessorIntegration() {
$field_name = 'field_boolean';
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test_mulrev_changed',
'type' => 'boolean',
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'item',
]);
$field
->save();
$index = $this
->getIndex();
$boolean_field = new Field($index, $field_name);
$boolean_field
->setType('integer');
$boolean_field
->setPropertyPath($field_name);
$boolean_field
->setDatasourceId('entity:entity_test_mulrev_changed');
$boolean_field
->setLabel('BooleanField');
$index
->addField($boolean_field);
$index
->save();
$this
->indexItems($this->indexId);
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed');
$entity_test_storage
->create([
'name' => 'foo bar baz',
'body' => 'test test',
'type' => 'item',
'keywords' => [
'orange',
],
'category' => 'item_category',
$field_name => TRUE,
])
->save();
$entity_test_storage
->create([
'name' => 'quux quuux',
'body' => 'test test',
'type' => 'item',
'keywords' => [
'apple',
],
'category' => 'item_category',
$field_name => FALSE,
])
->save();
$this
->indexItems($this->indexId);
$facet_name = "Boolean";
$facet_id = "boolean";
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet($facet_name, $facet_id, $field_name);
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('1');
$this
->assertFacetLabel('0');
$form = [
'facet_settings[boolean_item][status]' => TRUE,
'facet_settings[boolean_item][settings][on_value]' => 'Yes',
'facet_settings[boolean_item][settings][off_value]' => 'No',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxChecked('edit-facet-settings-boolean-item-status');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('Yes');
$this
->assertFacetLabel('No');
$form = [
'facet_settings[boolean_item][status]' => TRUE,
'facet_settings[boolean_item][settings][on_value]' => 'Øn',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('Øn');
$this
->assertEmpty($this
->findFacetLink('1'));
$this
->assertEmpty($this
->findFacetLink('0'));
$form = [
'facet_settings[boolean_item][status]' => TRUE,
'facet_settings[boolean_item][settings][off_value]' => 'Øff',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('Øff');
$this
->assertEmpty($this
->findFacetLink('1'));
$this
->assertEmpty($this
->findFacetLink('0'));
}
public function testNumericGranularity() {
$field_name = 'field_integer';
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test_mulrev_changed',
'type' => 'integer',
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'item',
]);
$field
->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'article',
]);
$field
->save();
$index = $this
->getIndex();
$integerField = new Field($index, $field_name);
$integerField
->setType('integer');
$integerField
->setPropertyPath($field_name);
$integerField
->setDatasourceId('entity:entity_test_mulrev_changed');
$integerField
->setLabel('IntegerField');
$index
->addField($integerField);
$index
->save();
$this
->indexItems($this->indexId);
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed');
foreach ([
30,
35,
40,
100,
] as $val) {
$entity_test_storage
->create([
'name' => 'foo bar baz',
'body' => 'test test int',
'type' => 'item',
'keywords' => [
'orange',
],
'category' => 'item_category',
$field_name => $val,
])
->save();
}
$this
->indexItems($this->indexId);
$facet_id = "integer";
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet("Integer", $facet_id, $field_name);
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('100');
$this
->assertFacetLabel('30');
$this
->assertFacetLabel('35');
$this
->assertFacetLabel('40');
$form = [
'facet_settings[granularity_item][status]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('30 - 31 (1)');
$this
->assertFacetLabel('35 - 36');
$this
->assertFacetLabel('40 - 41');
$this
->assertFacetLabel('100 - 101');
$form = [
'facet_settings[granularity_item][status]' => TRUE,
'facet_settings[granularity_item][settings][granularity]' => 10,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertFacetLabel('30 - 40 (2)');
$this
->assertEmpty($this
->findFacetLink('35 - 36'));
$this
->assertFacetLabel('40 - 50');
$this
->assertFacetLabel('100 - 110');
}
public function testSortingWidgets() {
$facet_name = "Huacaya alpaca";
$facet_id = "huacaya_alpaca";
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet($facet_name, $facet_id, 'keywords');
$this
->checkSortByActive();
$this
->checkSortByCount();
$this
->checkSortByDisplay();
$this
->checkSortByRaw();
}
public function testResultSorting() {
$id = 'burrowing_owl';
$name = 'Burrowing owl';
$this->editForm = 'admin/config/search/facets/' . $id . '/edit';
$this
->createFacet($name, $id, 'keywords');
$this
->disableAllFacetSorts();
$values = [
'facet_sorting[display_value_widget_order][status]' => TRUE,
'widget_config[show_numbers]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $values, 'Save');
$expected_results = [
'apple',
'banana',
'grape',
'orange',
'strawberry',
];
$this
->drupalGet('search-api-test-fulltext');
foreach ($expected_results as $k => $link) {
if ($k > 0) {
$x = $expected_results[$k - 1];
$y = $expected_results[$k];
$this
->assertStringPosition($x, $y);
}
}
$values['facet_sorting[count_widget_order][status]'] = TRUE;
$values['facet_sorting[count_widget_order][settings][sort]'] = 'ASC';
$values['processors[count_widget_order][weights][sort]'] = 1;
$values['facet_sorting[display_value_widget_order][status]'] = TRUE;
$values['processors[display_value_widget_order][weights][sort]'] = 2;
$this
->disableAllFacetSorts();
$this
->drupalPostForm($this->editForm, $values, 'Save');
$expected_results = [
'banana',
'apple',
'strawberry',
'grape',
'orange',
];
$this
->drupalGet('search-api-test-fulltext');
foreach ($expected_results as $k => $link) {
if ($k > 0) {
$x = $expected_results[$k - 1];
$y = $expected_results[$k];
$this
->assertStringPosition($x, $y);
}
}
$values['facet_sorting[display_value_widget_order][status]'] = TRUE;
$values['facet_sorting[count_widget_order][status]'] = TRUE;
$values['facet_sorting[count_widget_order][settings][sort]'] = 'ASC';
$this
->drupalPostForm($this->editForm, $values, 'Save');
$this
->assertSession()
->checkboxChecked('edit-facet-sorting-display-value-widget-order-status');
$this
->assertSession()
->checkboxChecked('edit-facet-sorting-count-widget-order-status');
$expected_results = [
'banana',
'apple',
'strawberry',
'grape',
'orange',
];
$this
->drupalGet('search-api-test-fulltext');
foreach ($expected_results as $k => $link) {
if ($k > 0) {
$x = $expected_results[$k - 1];
$y = $expected_results[$k];
$this
->assertStringPosition($x, $y);
}
}
}
protected function checkCountLimitProcessor() {
$this
->drupalGet($this->editForm);
$form = [
'widget_config[show_numbers]' => TRUE,
'facet_settings[count_limit][status]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxChecked('edit-facet-settings-count-limit-status');
$form = [
'widget_config[show_numbers]' => TRUE,
'facet_settings[count_limit][status]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$form = [
'widget_config[show_numbers]' => TRUE,
'facet_settings[count_limit][status]' => TRUE,
'facet_settings[count_limit][settings][minimum_items]' => 5,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 10 search results');
$this
->assertFacetLabel('grape (6)');
$this
->assertSession()
->pageTextNotContains('apple');
$form = [
'widget_config[show_numbers]' => TRUE,
'facet_settings[count_limit][status]' => TRUE,
'facet_settings[count_limit][settings][minimum_items]' => 1,
'facet_settings[count_limit][settings][maximum_items]' => 5,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 10 search results');
$this
->assertSession()
->pageTextNotContains('grape');
$this
->assertFacetLabel('apple (4)');
$form = [
'widget_config[show_numbers]' => FALSE,
'facet_settings[count_limit][status]' => FALSE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
}
protected function checkExcludeItems() {
$form = [
'facet_settings[exclude_specified_items][status]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$form = [
'facet_settings[exclude_specified_items][status]' => TRUE,
'facet_settings[exclude_specified_items][settings][exclude]' => 'banana',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 10 search results');
$this
->assertSession()
->pageTextContains('grape');
$this
->assertSession()
->pageTextNotContains('banana');
$form = [
'facet_settings[exclude_specified_items][status]' => TRUE,
'facet_settings[exclude_specified_items][settings][exclude]' => '(.*)berry',
'facet_settings[exclude_specified_items][settings][regex]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 10 search results');
$this
->assertSession()
->pageTextNotContains('strawberry');
$this
->assertSession()
->pageTextContains('grape');
$form = [
'facet_settings[exclude_specified_items][status]' => FALSE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
}
protected function checkHideNonNarrowingProcessor() {
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 10 search results');
$this
->assertFacetLabel('apple');
$this
->clickLink('apple');
$this
->assertSession()
->pageTextContains('Displaying 4 search results');
$this
->assertFacetLabel('grape');
$form = [
'facet_settings[hide_non_narrowing_result_processor][status]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 10 search results');
$this
->assertFacetLabel('apple');
$this
->clickLink('apple');
$this
->assertSession()
->pageTextContains('Displaying 4 search results');
$this
->assertSession()
->linkNotExists('grape');
$form = [
'facet_settings[hide_non_narrowing_result_processor][status]' => FALSE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
}
protected function checkHideActiveItems() {
$form = [
'facet_settings[hide_active_items_processor][status]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 10 search results');
$this
->assertFacetLabel('grape');
$this
->assertFacetLabel('banana');
$this
->clickLink('grape');
$this
->assertSession()
->pageTextContains('Displaying 6 search results');
$this
->assertSession()
->linkNotExists('grape');
$this
->assertFacetLabel('banana');
$form = [
'facet_settings[hide_active_items_processor][status]' => FALSE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
}
protected function checkSortByActive() {
$this
->disableAllFacetSorts();
$form = [
'facet_sorting[active_widget_order][status]' => TRUE,
'facet_sorting[active_widget_order][settings][sort]' => 'ASC',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->clickLink('strawberry');
$this
->assertStringPosition('strawberry', 'grape');
$form = [
'facet_sorting[active_widget_order][status]' => TRUE,
'facet_sorting[active_widget_order][settings][sort]' => 'DESC',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->clickLink('strawberry');
$this
->assertStringPosition('grape', 'strawberry');
$form = [
'facet_sorting[active_widget_order][status]' => FALSE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
}
protected function checkSortByCount() {
$this
->disableAllFacetSorts();
$form = [
'widget_config[show_numbers]' => TRUE,
'facet_sorting[count_widget_order][status]' => TRUE,
'facet_sorting[count_widget_order][settings][sort]' => 'ASC',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertStringPosition('banana', 'apple');
$this
->assertStringPosition('banana', 'strawberry');
$this
->assertStringPosition('apple', 'orange');
$form = [
'facet_sorting[count_widget_order][status]' => TRUE,
'facet_sorting[count_widget_order][settings][sort]' => 'DESC',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertStringPosition('apple', 'banana');
$this
->assertStringPosition('strawberry', 'banana');
$this
->assertStringPosition('orange', 'apple');
$form = [
'widget_config[show_numbers]' => FALSE,
'facet_sorting[count_widget_order][status]' => FALSE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
}
protected function checkSortByDisplay() {
$this
->disableAllFacetSorts();
$form = [
'facet_sorting[display_value_widget_order][status]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertStringPosition('grape', 'strawberry');
$this
->assertStringPosition('apple', 'banana');
$form = [
'facet_sorting[display_value_widget_order][status]' => TRUE,
'facet_sorting[display_value_widget_order][settings][sort]' => 'DESC',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertStringPosition('strawberry', 'grape');
$this
->assertStringPosition('banana', 'apple');
$form = [
'facet_sorting[display_value_widget_order][status]' => FALSE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
}
protected function checkSortByRaw() {
$this
->disableAllFacetSorts();
$form = [
'facet_sorting[raw_value_widget_order][status]' => TRUE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertStringPosition('grape', 'strawberry');
$this
->assertStringPosition('apple', 'banana');
$form = [
'facet_sorting[raw_value_widget_order][status]' => TRUE,
'facet_sorting[raw_value_widget_order][settings][sort]' => 'DESC',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertStringPosition('strawberry', 'grape');
$this
->assertStringPosition('banana', 'apple');
$form = [
'facet_sorting[raw_value_widget_order][status]' => FALSE,
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
}
protected function disableAllFacetSorts($path = FALSE) {
$settings = [
'facet_sorting[raw_value_widget_order][status]' => FALSE,
'facet_sorting[display_value_widget_order][status]' => FALSE,
'facet_sorting[count_widget_order][status]' => FALSE,
'facet_sorting[active_widget_order][status]' => FALSE,
];
if (!$path) {
$path = $this->editForm;
}
$this
->drupalPostForm($path, $settings, 'Save');
}
public function testListProcessor() {
entity_test_create_bundle('basic', "Basic page", 'entity_test_mulrev_changed');
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed');
$entity_test_storage
->create([
'name' => 'AC0871108',
'body' => 'Eamus Catuli',
'type' => 'basic',
])
->save();
$this
->indexItems($this->indexId);
$facet_name = "Eamus Catuli";
$facet_id = "eamus_catuli";
$editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet($facet_name, $facet_id);
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 11 search results');
$this
->assertFacetLabel('basic');
$edit = [
'facet_settings[list_item][status]' => TRUE,
];
$this
->drupalPostForm($editForm, $edit, 'Save');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxChecked('edit-facet-settings-list-item-status');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 11 search results');
$this
->assertFacetLabel('Basic page');
}
public function testPreQueryProcessor() {
$facet_name = "Eamus Catuli";
$facet_id = "eamus_catuli";
$editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet($facet_name, $facet_id);
$edit = [
'facet_settings[test_pre_query][status]' => TRUE,
'facet_settings[test_pre_query][settings][test_value]' => 'Llama',
];
$this
->drupalPostForm($editForm, $edit, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Llama');
}
public function testSupportsFacet() {
$id = 'masked_owl';
$this
->createFacet('Australian masked owl', $id);
$this
->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this
->assertSession()
->pageTextContains('test pre query');
\Drupal::state()
->set('facets_test_supports_facet', FALSE);
$this
->drupalGet('admin/config/search/facets/' . $id . '/edit');
$this
->assertSession()
->pageTextNotContains('test pre query');
}
public function testHideOnlyOneItemProcessor() {
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed');
$all = $entity_test_storage
->loadMultiple();
foreach ($all as $item) {
$item
->delete();
}
$entity_test_storage
->create([
'name' => 'baz baz',
'body' => 'foo test',
'type' => 'article',
'keywords' => [
'kiwi',
],
'category' => 'article_category',
])
->save();
$this
->indexItems($this->indexId);
$facet_name = 'Drupalcon Vienna';
$facet_id = 'drupalcon_vienna';
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet($facet_name, $facet_id, 'keywords');
$form = [
'facet_settings[hide_1_result_facet][status]' => TRUE,
'facet_settings[query_operator]' => 'and',
];
$this
->drupalPostForm($this->editForm, $form, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 1 search results');
$this
->assertNoFacetBlocksAppear();
}
public function testHiddenProcessors() {
$facet_id = 'alpaca';
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet('Alpaca', $facet_id);
$this
->drupalGet($this->editForm);
$this
->assertSession()
->pageTextNotContains('Boolean item label');
$this
->assertSession()
->pageTextNotContains('Transform UID to user name');
$this
->assertSession()
->pageTextNotContains('Transform entity ID to label');
$this
->assertSession()
->pageTextNotContains('Sort by taxonomy term weight');
}
public function testProcessorConfig() {
$this
->createFacet('Llama', 'llama');
$facet_id = 'alpaca';
$this->editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet('Alpaca', $facet_id);
$this
->drupalGet($this->editForm);
$facet = Facet::load($facet_id);
foreach ($facet
->getProcessors(FALSE) as $processor) {
if ($processor instanceof SortProcessorInterface) {
continue;
}
$hiddenProcessors = [
'boolean_item',
'translate_entity',
'translate_entity_aggregated_fields',
'uid_to_username_callback',
];
if (in_array($processor
->getPluginId(), $hiddenProcessors)) {
continue;
}
$this
->drupalPostForm(NULL, [
"facet_settings[{$processor->getPluginId()}][status]" => '1',
], 'Save');
$this
->assertSession()
->statusCodeEquals(200);
}
}
public function testEntityTranslateWithUnderScores() {
entity_test_create_bundle('test_with_underscore', "Test with underscore", 'entity_test_mulrev_changed');
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed');
$entity_test_storage
->create([
'name' => 'llama',
'body' => 'llama.',
'type' => 'test_with_underscore',
])
->save();
$this
->indexItems($this->indexId);
$facet_id = 'owl';
$editForm = 'admin/config/search/facets/' . $facet_id . '/edit';
$this
->createFacet('Owl', $facet_id);
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 11 search results');
$this
->assertFacetLabel('test_with_underscore');
$edit = [
'facet_settings[list_item][status]' => TRUE,
];
$this
->drupalPostForm($editForm, $edit, 'Save');
$this
->drupalGet('search-api-test-fulltext');
$this
->assertSession()
->pageTextContains('Displaying 11 search results');
$this
->assertFacetLabel('Test with underscore');
}
}