Commit 8474b9f6 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2680301 by borisson_: Expand processor test coverage

parent 8cde322f
......@@ -14,6 +14,17 @@ plugin.plugin_configuration.facets_processor.display_value_widget_order:
type: string
label: sort order
plugin.plugin_configuration.facets_processor.exclude_specified_items:
type: mapping
label: 'Exclude specified items'
mapping:
exclude:
type: string
label: Exclude
regex:
type: boolean
label: Regex
plugin.plugin_configuration.facets_processor.raw_value_widget_order:
type: mapping
label: 'Raw value widget order'
......@@ -30,6 +41,14 @@ plugin.plugin_configuration.facets_processor.active_widget_order:
type: string
label: sort order
plugin.plugin_configuration.facets_processor.count_widget_order:
type: mapping
label: 'Active widget order'
mapping:
sort:
type: string
label: sort order
plugin.plugin_configuration.facets_processor.count_limit:
type: mapping
label: 'Count limit widget'
......@@ -46,3 +65,6 @@ plugin.plugin_configuration.facets_processor.url_processor_handler:
plugin.plugin_configuration.facets_processor.hide_non_narrowing_result_processor:
type: config_object
plugin.plugin_configuration.facets_processor.hide_active_items_processor:
type: config_object
......@@ -7,6 +7,7 @@
namespace Drupal\facets\Tests;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\search_api\Entity\Index;
/**
......@@ -94,4 +95,54 @@ trait ExampleContentTrait {
return $index->indexItems();
}
/**
* Add a facet trough the UI.
*
* @param string $name
* The facet name.
* @param string $id
* The facet id.
* @param string $field
* The facet field.
*/
protected function createFacet($name, $id, $field = 'type') {
$facet_add_page = 'admin/config/search/facets/add-facet';
$this->drupalGet($facet_add_page);
$form_values = [
'id' => $id,
'status' => 1,
'url_alias' => $id,
'name' => $name,
'facet_source_id' => 'search_api_views:search_api_test_view:page_1',
'facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]' => $field,
];
$this->drupalPostForm(NULL, ['facet_source_id' => 'search_api_views:search_api_test_view:page_1'], $this->t('Configure facet source'));
$this->drupalPostForm(NULL, $form_values, $this->t('Save'));
}
/**
* Asserts that a string is found before another string in the source.
*
* This uses the simpletest's getRawContent method to search in the source of
* the page for the position of 2 strings and that the first argument is
* before the second argument's position.
*
* @param string $x
* A string.
* @param string $y
* Another string.
*/
protected function assertStringPosition($x, $y) {
$this->assertText($x);
$this->assertText($y);
$x_position = strpos($this->getRawContent(), $x);
$y_position = strpos($this->getRawContent(), $y);
$message = new FormattableMarkup('Assert that %x is before %y in the source', ['%x' => $x, '%y' => $y]);
$this->assertTrue($x_position < $y_position, $message);
}
}
......@@ -385,62 +385,6 @@ class IntegrationTest extends FacetWebTestBase {
$this->assertNoText($this->t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
}
/**
* Tests for processor integration.
*/
public function testProcessorIntegration() {
$facet_name = "Snowy owl~";
$facet_id = "snowy_owl_";
$this->addFacet($facet_name);
// Go to the processors form and check that the count limit processor is not
// checked.
$this->drupalGet('admin/config/search/facets/' . $facet_id . '/display');
$this->assertNoFieldChecked('edit-facet-settings-count-limit-status');
$form = ['facet_settings[count_limit][status]' => TRUE];
$this->drupalPostForm(NULL, $form, $this->t('Save'));
$this->assertResponse(200);
$this->assertFieldChecked('edit-facet-settings-count-limit-status');
// Enable the sort processor and change sort direction.
// Test that the sort settings change persisted.
$form = [
'facet_sorting[active_widget_order][status]' => TRUE,
'facet_sorting[active_widget_order][settings][sort]' => 'DESC',
];
$this->drupalPostForm(NULL, $form, $this->t('Save'));
$this->assertResponse(200);
$this->assertFieldChecked('edit-facet-sorting-active-widget-order-status');
$this->assertFieldChecked('edit-facet-sorting-active-widget-order-settings-sort-desc');
// Add an extra processor so we can test the weights as well.
$form = [
'facet_settings[hide_non_narrowing_result_processor][status]' => TRUE,
'facet_settings[count_limit][status]' => TRUE,
];
$this->drupalPostForm(NULL, $form, $this->t('Save'));
$this->assertResponse(200);
$this->assertFieldChecked('edit-facet-settings-count-limit-status');
$this->assertFieldChecked('edit-facet-settings-hide-non-narrowing-result-processor-status');
$this->assertOptionSelected('edit-processors-count-limit-weights-build', -10);
$this->assertOptionSelected('edit-processors-hide-non-narrowing-result-processor-weights-build', -10);
// Change the weight of one of the processors and test that the weight
// change persisted.
$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, $this->t('Save'));
$this->assertFieldChecked('edit-facet-settings-count-limit-status');
$this->assertFieldChecked('edit-facet-settings-hide-non-narrowing-result-processor-status');
$this->assertOptionSelected('edit-processors-count-limit-weights-build', -10);
$this->assertOptionSelected('edit-processors-hide-non-narrowing-result-processor-weights-build', 5);
}
/**
* Tests the facet's exclude functionality.
*/
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment