diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 8a07deb..88148a5 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -1514,6 +1514,17 @@ class Index extends ConfigEntityBase implements IndexInterface { } } + $processors = $this->getOption('processors', array()); + foreach ($dependencies['module'] as $module) { + foreach ($this->getProcessors(FALSE) as $key => $processor) { + if ($processor->getPluginDefinition()['provider'] == $module) { + unset($processors[$key]); + $changed = TRUE; + } + } + } + $this->setOption('processors', $processors); + return $changed; } diff --git a/src/Entity/Server.php b/src/Entity/Server.php index b04cd1a..d2c74f2 100644 --- a/src/Entity/Server.php +++ b/src/Entity/Server.php @@ -440,8 +440,8 @@ class Server extends ConfigEntityBase implements ServerInterface { parent::calculateDependencies(); // Add the backend's dependencies. - if ($this->hasValidBackend() && ($backend = $this->getBackend())) { - $this->addDependencies($backend->calculateDependencies()); + if ($this->hasValidBackend()) { + $this->calculatePluginDependencies($this->getBackend()); } return $this->dependencies; diff --git a/src/Plugin/ConfigurablePluginBase.php b/src/Plugin/ConfigurablePluginBase.php index d3edd25..0ea2a32 100644 --- a/src/Plugin/ConfigurablePluginBase.php +++ b/src/Plugin/ConfigurablePluginBase.php @@ -100,8 +100,7 @@ abstract class ConfigurablePluginBase extends PluginBase implements Configurable * {@inheritdoc} */ public function calculateDependencies() { - $this->addDependency('module', $this->getPluginDefinition()['provider']); - return $this->dependencies; + return array(); } } diff --git a/src/Tests/DependencyRemovalTest.php b/src/Tests/DependencyRemovalTest.php new file mode 100644 index 0000000..f0f082d --- /dev/null +++ b/src/Tests/DependencyRemovalTest.php @@ -0,0 +1,100 @@ +drupalLogin($this->adminUser); + + // Create a server and index. + $this->getTestServer(); + $this->getTestIndex(); + } + + /** + * Tests whether removing dependencies of an index works correctly. + * + * Single test method to avoid the overhead of Drupal installation for each of + * the test methods. + */ + public function testDependencyRemoval() { + $this->checkProcessorRemoval(); + } + + /** + * Tests the reaction of an index when a processor's module is removed. + * + * When a module that provides a processor is uninstalled, it should not + * delete the indexes that processor is enabled on. This would cause a chain + * removal of facets and views as well. Instead, the processor should just be + * disabled and no longer be found on the processors tab. + */ + protected function checkProcessorRemoval() { + // Enable the dummy processor on the index. + $this->drupalGet($this->getIndexPath('processors')); + $this->assertText($this->t('Dummy processor')); + $this->drupalPostForm(NULL, array('status[dummy_processor]' => 1), $this->t('Save')); + $this->assertResponse(200); + $this->assertText($this->t('The indexing workflow was successfully edited.')); + + // Uninstall the module. + $this->drupalGet('admin/modules/uninstall'); + $this->drupalPostForm(NULL, array('uninstall[search_api_test_processor]' => 1), $this->t('Uninstall')); + // Make sure the index is not deleted when uninstalling the module. + $this->assertNoText($this->t('The listed configuration will be deleted.')); + $this->assertText($this->t('The listed configuration will be updated.')); + + $this->drupalPostForm(NULL, array(), $this->t('Uninstall')); + $this->assertText($this->t('The selected modules have been uninstalled.')); + + // Make sure the index is still actually present. + $this->drupalGet('admin/config/search/search-api'); + $this->assertText('WebTest Index'); + + // Make sure the processor is no longer found on the processors tab. + $this->drupalGet($this->getIndexPath('processors')); + $this->assertResponse(200); + $this->assertNoText('Dummy processor'); + } + +} diff --git a/src/Tests/HooksTest.php b/src/Tests/HooksTest.php index bc66fff..9f7ff4f 100644 --- a/src/Tests/HooksTest.php +++ b/src/Tests/HooksTest.php @@ -20,13 +20,6 @@ class HooksTest extends WebTestBase { public static $modules = array('node', 'search_api', 'search_api_test_backend', 'search_api_test_views', 'search_api_test_hooks'); /** - * The id of the index. - * - * @var string - */ - protected $indexId; - - /** * Tests various operations via the Search API's admin UI. */ public function testHooks() { @@ -41,8 +34,7 @@ class HooksTest extends WebTestBase { // Create an index and server to work with. $this->getTestServer(); - $index = $this->getTestIndex(); - $this->indexId = $index->id(); + $this->getTestIndex(); // hook_search_api_backend_info_alter was triggered. $this->drupalGet('admin/config/search/search-api/add-server'); @@ -89,21 +81,4 @@ class HooksTest extends WebTestBase { $this->assertText('Llama'); } - /** - * Returns the system path for the test index. - * - * @param string|null $tab - * (optional) If set, the path suffix for a specific index tab. - * - * @return string - * A system path. - */ - protected function getIndexPath($tab = NULL) { - $path = 'admin/config/search/search-api/index/' . $this->indexId; - if ($tab) { - $path .= "/$tab"; - } - return $path; - } - } diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index 4d71336..a03fbac 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -27,13 +27,6 @@ class IntegrationTest extends WebTestBase { protected $serverId; /** - * The ID of the search index used for this test. - * - * @var string - */ - protected $indexId; - - /** * A storage instance for indexes. * * @var \Drupal\Core\Entity\EntityStorageInterface @@ -805,23 +798,6 @@ class IntegrationTest extends WebTestBase { } /** - * Returns the system path for the test index. - * - * @param string|null $tab - * (optional) If set, the path suffix for a specific index tab. - * - * @return string - * A system path. - */ - protected function getIndexPath($tab = NULL) { - $path = 'admin/config/search/search-api/index/' . $this->indexId; - if ($tab) { - $path .= "/$tab"; - } - return $path; - } - - /** * Retrieves test index. * * @return \Drupal\search_api\IndexInterface diff --git a/src/Tests/Processor/ProcessorIntegrationTest.php b/src/Tests/Processor/ProcessorIntegrationTest.php index ac22441..25b4075 100644 --- a/src/Tests/Processor/ProcessorIntegrationTest.php +++ b/src/Tests/Processor/ProcessorIntegrationTest.php @@ -20,13 +20,6 @@ use Drupal\search_api\Tests\WebTestBase; class ProcessorIntegrationTest extends WebTestBase { /** - * The ID of the search index used by this test. - * - * @var string - */ - protected $indexId; - - /** * {@inheritdoc} */ public function setUp() { diff --git a/src/Tests/ViewsTest.php b/src/Tests/ViewsTest.php index e84e258..d8976d8 100644 --- a/src/Tests/ViewsTest.php +++ b/src/Tests/ViewsTest.php @@ -26,13 +26,6 @@ class ViewsTest extends WebTestBase { public static $modules = array('search_api_test_views'); /** - * A search index ID. - * - * @var string - */ - protected $indexId = 'database_search_index'; - - /** * {@inheritdoc} */ public function setUp() { @@ -40,6 +33,7 @@ class ViewsTest extends WebTestBase { $this->setUpExampleStructure(); + $this->indexId = 'database_search_index'; \Drupal::getContainer()->get('search_api.index_task_manager')->addItemsAll(Index::load($this->indexId)); } diff --git a/src/Tests/WebTestBase.php b/src/Tests/WebTestBase.php index f19efd0..a2d7734 100644 --- a/src/Tests/WebTestBase.php +++ b/src/Tests/WebTestBase.php @@ -32,6 +32,15 @@ abstract class WebTestBase extends SimpletestWebTestBase { * @var \Drupal\Core\Session\AccountInterface */ protected $adminUser; + /** + * The permissions of the admin user. + * + * @var string[] + */ + protected $adminUserPermissions = array( + 'administer search_api', + 'access administration pages' + ); /** * A user without Search API admin permission. @@ -55,13 +64,20 @@ abstract class WebTestBase extends SimpletestWebTestBase { protected $urlGenerator; /** + * The ID of the search index used for this test. + * + * @var string + */ + protected $indexId; + + /** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Create the users used for the tests. - $this->adminUser = $this->drupalCreateUser(array('administer search_api', 'access administration pages')); + $this->adminUser = $this->drupalCreateUser($this->adminUserPermissions); $this->unauthorizedUser = $this->drupalCreateUser(array('access administration pages')); $this->anonymousUser = $this->drupalCreateUser(); @@ -101,6 +117,7 @@ abstract class WebTestBase extends SimpletestWebTestBase { */ public function getTestServer($name = 'WebTest server', $id = 'webtest_server', $backend_id = 'search_api_test_backend', $backend_config = array(), $reset = FALSE) { if ($reset) { + /** @var \Drupal\search_api\ServerInterface $server */ $server = Server::load($id); if ($server) { $server->delete(); @@ -140,6 +157,7 @@ abstract class WebTestBase extends SimpletestWebTestBase { */ public function getTestIndex($name = 'WebTest Index', $id = 'webtest_index', $server_id = 'webtest_server', $datasource_id = 'entity:node', $reset = FALSE) { if ($reset) { + /** @var \Drupal\search_api\IndexInterface $index */ $index = Index::load($id); if ($index) { $index->delete(); @@ -154,9 +172,27 @@ abstract class WebTestBase extends SimpletestWebTestBase { 'datasources' => array($datasource_id), )); $index->save(); + $this->indexId = $index->id(); } return $index; } + /** + * Returns the system path for the test index. + * + * @param string|null $tab + * (optional) If set, the path suffix for a specific index tab. + * + * @return string + * A system path. + */ + protected function getIndexPath($tab = NULL) { + $path = 'admin/config/search/search-api/index/' . $this->indexId; + if ($tab) { + $path .= "/$tab"; + } + return $path; + } + } diff --git a/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml b/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml new file mode 100644 index 0000000..a9c5c2c --- /dev/null +++ b/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml @@ -0,0 +1,10 @@ +plugin.plugin_configuration.search_api_processor.dummy_processor: + type: mapping + label: 'Dummy processor configuration' + mapping: + fields: + type: sequence + label: 'The selected fields' + sequence: + type: string + label: 'Selected field' diff --git a/tests/search_api_test_processor/search_api_test_processor.info.yml b/tests/search_api_test_processor/search_api_test_processor.info.yml new file mode 100644 index 0000000..de85f76 --- /dev/null +++ b/tests/search_api_test_processor/search_api_test_processor.info.yml @@ -0,0 +1,8 @@ +name: 'Search API Custom processor Test' +type: module +description: 'Support module for Search API tests' +package: Search +dependencies: + - search_api:search_api +core: 8.x +hidden: true diff --git a/tests/search_api_test_processor/src/Plugin/search_api/processor/DummyProcessor.php b/tests/search_api_test_processor/src/Plugin/search_api/processor/DummyProcessor.php new file mode 100644 index 0000000..537e6c7 --- /dev/null +++ b/tests/search_api_test_processor/src/Plugin/search_api/processor/DummyProcessor.php @@ -0,0 +1,35 @@ +