Skip to content
Snippets Groups Projects
Verified Commit 12f09143 authored by Dave Long's avatar Dave Long
Browse files

Issue #2559961 by angrytoast, Krzysztof Domański, drup16, Lendude, vasike,...

Issue #2559961 by angrytoast, Krzysztof Domański, drup16, Lendude, vasike, Leksat, sam711, tar_inet, mlncn, JordiK, adinac, Pascal-, joshua.boltz, froboy, oriol_e9g, alison, codesmith, luenemann, specky_rum, daffie: ManyToOneHelper ignores group configuration for some cases

(cherry picked from commit aec9cf8c)
parent 17d424fc
No related branches found
No related tags found
19 merge requests!11628Update file MediaLibraryWidget.php,!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!5427Issue #3338518: send credentials in ajax if configured in CORS settings.,!5395Issue #3387916 by fjgarlin, Spokje: Each GitLab job exposes user email,!5217Issue #3386607 by alexpott: Improve spell checking in commit-code-check.sh,!5064Issue #3379522 by finnsky, Gauravvvv, kostyashupenko, smustgrave, Chi: Revert...,!5040SDC ComponentElement: Transform slots scalar values to #plain_text instead of throwing an exception,!4958Issue #3392147: Whitelist IP for a Ban module.,!4894Issue #3280279: Add API to allow sites to opt in to upload SVG images in CKEditor 5,!4857Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4856Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4788Issue #3272985: RSS Feed header reverts to text/html when cached,!4716Issue #3362929: Improve 400 responses for broken/invalid image style routes,!3679Issue #115801: Allow password on registration without disabling e-mail verification,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->),!925Issue #2339235: Remove taxonomy hard dependency on node module,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links
......@@ -358,4 +358,137 @@ public function testExposedUnpublishedFilterOptions() {
$this->assertEmpty($this->cssSelect('option[value="' . $this->terms[1][0]->id() . '"]'));
}
/**
* Tests using the TaxonomyIndexTid in a filter group.
*/
public function testFilterGrouping() {
$node_type = $this->drupalCreateContentType(['type' => 'page']);
// Create the tag field itself.
$field_name = 'taxonomy_tags';
$this->createEntityReferenceField('node', $node_type->id(), $field_name, NULL, 'taxonomy_term');
// Create 4 nodes: 1 node without any tagging, 2 nodes tagged with 1 term,
// and 1 node with 2 tagged terms.
$node_no_term = $this->drupalCreateNode();
$node_with_term_1_0 = $this->drupalCreateNode([
$field_name => [['target_id' => $this->terms[1][0]->id()]],
]);
$node_with_terms_1_0_and_1_1 = $this->drupalCreateNode([
$field_name => [
['target_id' => $this->terms[1][0]->id()],
['target_id' => $this->terms[1][1]->id()],
],
]);
$node_with_term_2_0 = $this->drupalCreateNode([
$field_name => [['target_id' => $this->terms[2][0]->id()]],
]);
// Create two groups. The first group contains the published filter and set
// up the second group as an 'OR' group. The first subgroup of the second
// filter group will vary as follows:
// - multiple values vs single value
// - not vs or operator values
$view = View::load('test_filter_taxonomy_index_tid');
$display =& $view->getDisplay('default');
// Case 1:
// - filter "tid" with multiple terms as "is none of"
// - filter "tid_2" with a single term as "is one of"
$display['display_options']['filters']['tid']['value'][0] = $this->terms[1][0]->id();
$display['display_options']['filters']['tid']['value'][1] = $this->terms[1][1]->id();
$display['display_options']['filters']['tid']['operator'] = 'not';
$display['display_options']['filters']['tid']['group'] = 2;
$display['display_options']['filters']['tid_2'] = $display['display_options']['filters']['tid'];
$display['display_options']['filters']['tid_2']['id'] = 'tid_2';
$display['display_options']['filters']['tid_2']['value'][0] = $this->terms[2][0]->id();
$display['display_options']['filters']['tid_2']['operator'] = 'or';
$display['display_options']['filters']['tid_2']['group'] = 2;
$display['display_options']['filter_groups'] = [
'operator' => 'AND',
'groups' => [
1 => 'AND',
2 => 'OR',
],
];
$view->save();
$this->drupalGet('test-filter-taxonomy-index-tid');
// We expect no nodes tagged with term 1.0 or 1.1. The node tagged with
// term 2.0 and the untagged node will be shown.
$this->assertSession()->pageTextNotContains($node_with_term_1_0->label());
$this->assertSession()->pageTextNotContains($node_with_terms_1_0_and_1_1->label());
$this->assertSession()->pageTextContainsOnce($node_with_term_2_0->label());
$this->assertSession()->pageTextContainsOnce($node_no_term->label());
// Case 2:
// - filter "tid" with multiple terms as "is one of"
// - filter "tid_2" with a single term as "is one of"
$view = View::load('test_filter_taxonomy_index_tid');
$display =& $view->getDisplay('default');
$display['display_options']['filters']['tid']['value'][0] = $this->terms[1][0]->id();
$display['display_options']['filters']['tid']['value'][1] = $this->terms[1][1]->id();
$display['display_options']['filters']['tid']['operator'] = 'or';
$display['display_options']['filters']['tid']['group'] = 2;
$display['display_options']['filters']['tid_2'] = $display['display_options']['filters']['tid'];
$display['display_options']['filters']['tid_2']['id'] = 'tid_2';
$display['display_options']['filters']['tid_2']['value'][0] = $this->terms[2][0]->id();
$display['display_options']['filters']['tid_2']['operator'] = 'or';
$display['display_options']['filters']['tid_2']['group'] = 2;
$view->save();
$this->drupalGet('test-filter-taxonomy-index-tid');
// We expect all the tagged nodes but not the untagged node.
$this->assertSession()->pageTextContainsOnce($node_with_term_1_0->label());
// The view does not have DISTINCT query enabled, the node tagged with
// both 1.0 and 1.1 will appear twice.
$this->assertSession()->pageTextMatchesCount(2, "/{$node_with_terms_1_0_and_1_1->label()}/");
$this->assertSession()->pageTextContainsOnce($node_with_term_2_0->label());
$this->assertSession()->pageTextNotContains($node_no_term->label());
// Case 3:
// - filter "tid" with a single term as "is none of"
// - filter "tid_2" with a single term as "is one of"
$view = View::load('test_filter_taxonomy_index_tid');
$display =& $view->getDisplay('default');
$display['display_options']['filters']['tid']['value'] = [];
$display['display_options']['filters']['tid']['value'][0] = $this->terms[1][0]->id();
$display['display_options']['filters']['tid']['operator'] = 'not';
$display['display_options']['filters']['tid']['group'] = 2;
$display['display_options']['filters']['tid_2'] = $display['display_options']['filters']['tid'];
$display['display_options']['filters']['tid_2']['id'] = 'tid_2';
$display['display_options']['filters']['tid_2']['value'][0] = $this->terms[2][0]->id();
$display['display_options']['filters']['tid_2']['operator'] = 'or';
$display['display_options']['filters']['tid_2']['group'] = 2;
$view->save();
$this->drupalGet('test-filter-taxonomy-index-tid');
// We expect none of the nodes tagged with term 1.0. The node tagged with
// term 2.0 and the untagged node should be shown.
$this->assertSession()->pageTextNotContains($node_with_term_1_0->label());
$this->assertSession()->pageTextNotContains($node_with_terms_1_0_and_1_1->label());
$this->assertSession()->pageTextContainsOnce($node_with_term_2_0->label());
$this->assertSession()->pageTextContainsOnce($node_no_term->label());
// Case 4:
// - filter "tid" with a single term as "is one of"
// - filter "tid_2" with a single term as "is one of"
$view = View::load('test_filter_taxonomy_index_tid');
$display =& $view->getDisplay('default');
$display['display_options']['filters']['tid']['value'] = [];
$display['display_options']['filters']['tid']['value'][0] = $this->terms[1][0]->id();
$display['display_options']['filters']['tid']['operator'] = 'or';
$display['display_options']['filters']['tid']['group'] = 2;
$display['display_options']['filters']['tid_2'] = $display['display_options']['filters']['tid'];
$display['display_options']['filters']['tid_2']['id'] = 'tid_2';
$display['display_options']['filters']['tid_2']['value'][0] = $this->terms[2][0]->id();
$view->save();
$this->drupalGet('test-filter-taxonomy-index-tid');
// We expect all the tagged nodes to be shown but not the untagged node.
$this->assertSession()->pageTextContainsOnce($node_with_term_1_0->label());
$this->assertSession()->pageTextContainsOnce($node_with_terms_1_0_and_1_1->label());
$this->assertSession()->pageTextContainsOnce($node_with_term_2_0->label());
$this->assertSession()->pageTextNotContains($node_no_term->label());
}
}
......@@ -327,18 +327,18 @@ public function addFilter() {
$placeholder .= '[]';
if ($operator == 'IS NULL') {
$this->handler->query->addWhereExpression(0, "$field $operator");
$this->handler->query->addWhereExpression($options['group'], "$field $operator");
}
else {
$this->handler->query->addWhereExpression(0, "$field $operator($placeholder)", [$placeholder => $value]);
$this->handler->query->addWhereExpression($options['group'], "$field $operator($placeholder)", [$placeholder => $value]);
}
}
else {
if ($operator == 'IS NULL') {
$this->handler->query->addWhereExpression(0, "$field $operator");
$this->handler->query->addWhereExpression($options['group'], "$field $operator");
}
else {
$this->handler->query->addWhereExpression(0, "$field $operator $placeholder", [$placeholder => $value]);
$this->handler->query->addWhereExpression($options['group'], "$field $operator $placeholder", [$placeholder => $value]);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment