diff --git a/src/Tests/DependencyRemovalTest.php b/src/Tests/DependencyRemovalTest.php new file mode 100644 index 0000000..83aa2f7 --- /dev/null +++ b/src/Tests/DependencyRemovalTest.php @@ -0,0 +1,102 @@ +drupalCreateUser(array( + 'administer search_api', + 'access administration pages', + 'administer modules', + )); + $this->drupalLogin($admin_user); + } + + /** + * Tests the reaction of an index dependencies are 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. + */ + public function testProcessorRemoval() { + // Create a server and index. + $this->getTestServer(); + $index = $this->getTestIndex(); + $this->indexId = $index->id(); + + // Enable the dummy processor on the index. + $this->drupalGet($this->getIndexPath('processors')); + $this->assertText('Dummy processor'); + $this->drupalPostForm(NULL, array('status[dummy_processor]' => 1), $this->t('Save')); + $this->assertResponse(200); + $this->assertText('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->assertNoText('WebTest Index'); + + $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'); + } + + /** + * 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..2de69c5 --- /dev/null +++ b/tests/search_api_test_processor/config/schema/search_api_test_processor.schema.yml @@ -0,0 +1,10 @@ +search_api.processor.plugin.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 @@ +