Commit a2bdf80a authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2899947 by dragos-dumi, borisson_: Date list breaks when using exclude

parent 2e1aa7c3
......@@ -38,3 +38,19 @@ facet.widget.config.links:
# "soft limit" and "show counts".
facet.widget.config.checkbox:
type: facet.widget.config.links
# Config schema for datebasic, you can find the implementation in
# Drupal\facets\Plugin\facets\widget\DateBasicWidget.
facet.widget.config.datebasic:
type: facet.widget.default_config
label: 'List of dates configuration'
mapping:
display_relative:
type: boolean
label: 'Display relative'
granularity:
type: integer
label: 'Granularity'
date_display:
type: string
label: 'Date display'
......@@ -37,7 +37,7 @@ abstract class QueryTypeRangeBase extends QueryTypePluginBase {
foreach ($active_items as $value) {
$range = $this->calculateRange($value);
$item_filter = $query->createConditionGroup('AND', ['facet:' . $field_identifier]);
$item_filter = $query->createConditionGroup($exclude ? 'OR' : 'AND', ['facet:' . $field_identifier]);
$item_filter->addCondition($this->facet->getFieldIdentifier(), $range['start'], $exclude ? '<' : '>=');
$item_filter->addCondition($this->facet->getFieldIdentifier(), $range['stop'], $exclude ? '>' : '<=');
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\facets\Functional;
use Drupal\Core\Url;
use Drupal\facets\Plugin\facets\query_type\SearchApiDate;
use Drupal\views\Entity\View;
use Drupal\views\Views;
......@@ -444,6 +445,70 @@ class IntegrationTest extends FacetsTestBase {
$this->assertSession()->pageTextNotContains('foo baz');
}
/**
* Tests the facet's exclude functionality for a date field.
*/
public function testExcludeFacetDate() {
$field_name = 'created';
$entity_test_storage = \Drupal::entityTypeManager()
->getStorage('entity_test_mulrev_changed');
$entity_test_storage->create([
'name' => 'foo new',
'body' => 'test test',
'type' => 'item',
'keywords' => ['orange'],
'category' => 'item_category',
$field_name => 1490000000,
])->save();
$entity_test_storage->create([
'name' => 'foo old',
'body' => 'test test',
'type' => 'item',
'keywords' => ['orange'],
'category' => 'item_category',
$field_name => 1460000000,
])->save();
$this->indexItems($this->indexId);
$facet_name = "Created";
$facet_id = "created";
// Create facet.
$facet_edit_page = 'admin/config/search/facets/' . $facet_id . '/edit';
$this->createFacet($facet_name, $facet_id, $field_name);
$form = [
'widget' => 'datebasic',
'widget_config[granularity]' => SearchApiDate::FACETAPI_DATE_MONTH,
'widget_config[display_relative]' => 0,
];
$this->drupalGet($facet_edit_page);
$this->drupalPostForm(NULL, ['widget' => 'datebasic'], 'Configure widget');
$this->drupalPostForm(NULL, $form, 'Save');
$this->drupalGet('search-api-test-fulltext');
$this->assertText('foo old');
$this->assertText('foo new');
$this->clickLink('March 2017');
$this->checkFacetIsActive('March 2017');
$this->assertText('foo new');
$this->assertNoText('foo old');
$this->drupalGet($facet_edit_page);
$this->assertNoFieldChecked('edit-facet-settings-exclude');
$form['facet_settings[exclude]'] = TRUE;
$this->drupalPostForm(NULL, $form, 'Save');
$this->assertFieldChecked('edit-facet-settings-exclude');
$this->drupalGet('search-api-test-fulltext');
$this->clickLink('March 2017');
$this->checkFacetIsActive('March 2017');
$this->assertText('foo old');
$this->assertNoText('foo new');
}
/**
* Tests allow only one active item.
*/
......
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