public function ProcessorIntegrationTest::testResultSorting in Facets 8
Tests sorting of results.
File
- tests/
src/ Functional/ ProcessorIntegrationTest.php, line 338
Class
- ProcessorIntegrationTest
- Tests the processor functionality.
Namespace
Drupal\Tests\facets\FunctionalCode
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);
}
}
// Sort by count, then by display value.
$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);
}
}
}