diff --git a/src/Plugin/Condition/OtherFacet.php b/src/Plugin/Condition/OtherFacet.php index 4935155..75f210b 100644 --- a/src/Plugin/Condition/OtherFacet.php +++ b/src/Plugin/Condition/OtherFacet.php @@ -178,6 +178,10 @@ class OtherFacet extends ConditionPluginBase implements ContainerFactoryPluginIn $block_plugin_id = $block_plugin->getPluginId(); $facet_id = explode(PluginBase::DERIVATIVE_SEPARATOR, $block_plugin_id)[1]; + /** @var \Drupal\facets\FacetInterface $facet */ + $facet = $this->facetStorage->load($facet_id); + $this->facetManager->setFacetSourceId($facet->getFacetSourceId()); + $facet = $this->facetManager->returnProcessedFacet($facet_id); foreach ($facet->getResults() as $result) { diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index 2bf9636..15e8a34 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -34,6 +34,7 @@ class IntegrationTest extends FacetWebTestBase { $this->setUpExampleStructure(); $this->insertExampleContent(); $this->assertEqual($this->indexItems($this->indexId), 5, '5 items were indexed.'); + $this->blocks = NULL; } /** @@ -201,6 +202,48 @@ class IntegrationTest extends FacetWebTestBase { } /** + * Tests facet dependencies. + */ + public function testFacetDependencies() { + $facet_name = "DependableFacet"; + $facet_id = 'dependablefacet'; + $this->addFacet($facet_name); + + $depending_facet_name = "DependingFacet"; + $depending_facet_id = "dependingfacet"; + $this->addFacet($depending_facet_name, 'keywords'); + + $this->createFacetBlock($facet_id); + $this->createFacetBlock($depending_facet_id); + + $this->drupalGet('search-api-test-fulltext'); + $this->assertLink('grape'); + $this->assertLink('orange'); + $this->assertLink('item'); + $this->assertLink('article'); + $this->assertFacetBlocksAppear(); + + $this->drupalGet('admin/structure/block/manage/dependingfacet'); + $edit = [ + 'visibility[other_facet][facets]' => 'facet_block:dependablefacet', + 'visibility[other_facet][facet_value]' => 'item', + ]; + $this->drupalPostForm(NULL, $edit, $this->t('Save block')); + $this->assertText('The block configuration has been saved.'); + $this->drupalGet('admin/structure/block/manage/dependingfacet'); + + $this->drupalGet('search-api-test-fulltext'); + $this->assertNoLink('grape'); + $this->assertNoLink('orange'); + $this->assertLink('item'); + $this->assertLink('article'); + + $this->clickLink('item'); + $this->assertLink('grape'); + $this->assertLink('orange'); + } + + /** * Deletes a facet block by id. * * @param string $id @@ -312,7 +355,7 @@ class IntegrationTest extends FacetWebTestBase { * @param string $facet_name * The name of the facet. */ - protected function addFacet($facet_name) { + protected function addFacet($facet_name, $facet_type = 'type') { $facet_id = $this->convertNameToMachineName($facet_name); // Go to the Add facet page and make sure that returns a 200. @@ -350,7 +393,7 @@ class IntegrationTest extends FacetWebTestBase { // longer shown. $facet_source_form = [ '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]' => 'type', + 'facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]' => $facet_type, ]; $this->drupalPostForm(NULL, $form_values + $facet_source_form, $this->t('Save')); $this->assertNoText('field is required.'); @@ -362,7 +405,6 @@ class IntegrationTest extends FacetWebTestBase { $this->drupalGet('admin/config/search/facets'); } - /** * Tests editing of a facet through the UI. * diff --git a/tests/src/Unit/Plugin/Condition/OtherFacetTest.php b/tests/src/Unit/Plugin/Condition/OtherFacetTest.php index 7209032..b25edbb 100644 --- a/tests/src/Unit/Plugin/Condition/OtherFacetTest.php +++ b/tests/src/Unit/Plugin/Condition/OtherFacetTest.php @@ -136,6 +136,10 @@ class OtherFacetTest extends UnitTestCase { ->method('getPluginId') ->willReturn('block:id'); $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface'); + $storage->expects($this->exactly(1)) + ->method('load') + ->with('id') + ->willReturn($facet); $manager = $this->getMockBuilder('\Drupal\Core\Block\BlockManager') ->disableOriginalConstructor() ->getMock();