diff --git a/src/Plugin/Condition/OtherFacet.php b/src/Plugin/Condition/OtherFacet.php index 75f210b..b9f1440 100644 --- a/src/Plugin/Condition/OtherFacet.php +++ b/src/Plugin/Condition/OtherFacet.php @@ -184,12 +184,10 @@ class OtherFacet extends ConditionPluginBase implements ContainerFactoryPluginIn $facet = $this->facetManager->returnProcessedFacet($facet_id); - foreach ($facet->getResults() as $result) { - if ($result->getRawValue() == $allowed_facet_value || $result->getDisplayValue() == $allowed_facet_value) { - if ($result->isActive() && !$this->isNegated()) { - return TRUE; - } - if (!$result->isActive() && $this->isNegated()) { + if (!$this->isNegated()) { + foreach ($facet->getResults() as $result) { + $is_value = $result->getRawValue() == $allowed_facet_value || $result->getDisplayValue() == $allowed_facet_value; + if ($is_value && $result->isActive()) { return TRUE; } } diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index 15e8a34..7f4a6ec 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -213,9 +213,12 @@ class IntegrationTest extends FacetWebTestBase { $depending_facet_id = "dependingfacet"; $this->addFacet($depending_facet_name, 'keywords'); + // Create both facets as blocks and add them on the page. $this->createFacetBlock($facet_id); $this->createFacetBlock($depending_facet_id); + // Go the the view and test that both facets are shown. Item and article + // come from the DependableFacet, orange and grape come from DependingFacet. $this->drupalGet('search-api-test-fulltext'); $this->assertLink('grape'); $this->assertLink('orange'); @@ -223,6 +226,7 @@ class IntegrationTest extends FacetWebTestBase { $this->assertLink('article'); $this->assertFacetBlocksAppear(); + // Change the visiblity settings of the DependingFacet. $this->drupalGet('admin/structure/block/manage/dependingfacet'); $edit = [ 'visibility[other_facet][facets]' => 'facet_block:dependablefacet', @@ -230,17 +234,53 @@ class IntegrationTest extends FacetWebTestBase { ]; $this->drupalPostForm(NULL, $edit, $this->t('Save block')); $this->assertText('The block configuration has been saved.'); - $this->drupalGet('admin/structure/block/manage/dependingfacet'); + // Go to the view and test that only the types are shown. $this->drupalGet('search-api-test-fulltext'); $this->assertNoLink('grape'); $this->assertNoLink('orange'); $this->assertLink('item'); $this->assertLink('article'); + // Click on the item, and test that this shows the keywords. $this->clickLink('item'); $this->assertLink('grape'); $this->assertLink('orange'); + + // Go back to the view, click on article and test that the keywords are + // hidden. + $this->drupalGet('search-api-test-fulltext'); + $this->clickLink('article'); + $this->assertNoLink('grape'); + $this->assertNoLink('orange'); + + // Change the visibility settings to negate the previous settings. + $this->drupalGet('admin/structure/block/manage/dependingfacet'); + $edit = [ + 'visibility[other_facet][facets]' => 'facet_block:dependablefacet', + 'visibility[other_facet][facet_value]' => 'item', + 'visibility[other_facet][negate]' => TRUE, + ]; + $this->drupalPostForm(NULL, $edit, $this->t('Save block')); + + // Go the the view and test only the type facet is shown. + $this->drupalGet('search-api-test-fulltext'); + $this->assertLink('item'); + $this->assertLink('article'); + $this->assertNoLink('grape'); + $this->assertNoLink('orange'); + + // Click on the article, and test that this shows the keywords. + $this->clickLink('article'); + $this->assertLink('grape'); + $this->assertLink('orange'); + + // Go back to the view, click on item and test that the keywords are + // hidden. + $this->drupalGet('search-api-test-fulltext'); + $this->clickLink('article'); + $this->assertNoLink('grape'); + $this->assertNoLink('orange'); } /**