diff --git a/tests/src/Kernel/DependencyRemovalTest.php b/tests/src/Kernel/DependencyRemovalTest.php index 8daef81..717ea0d 100644 --- a/tests/src/Kernel/DependencyRemovalTest.php +++ b/tests/src/Kernel/DependencyRemovalTest.php @@ -87,13 +87,13 @@ class DependencyRemovalTest extends KernelTestBase { * If the dependency does not get removed, proper cascading to the index is * also verified. * - * @param bool $remove_dependency + * @param bool $dependency_removal_return_value * Whether to remove the dependency from the backend when the object * depended on is deleted. * * @dataProvider dependencyTestDataProvider */ - public function testBackendDependency($remove_dependency) { + public function testBackendDependency($dependency_removal_return_value) { $dependency_key = $this->dependency->getConfigDependencyKey(); $dependency_name = $this->dependency->getConfigDependencyName(); @@ -133,7 +133,7 @@ class DependencyRemovalTest extends KernelTestBase { // dependency should be removed or not. See // \Drupal\search_api_test_backend\Plugin\search_api\backend\TestBackend::onDependencyRemoval(). $key = 'search_api_test_backend.dependencies.remove'; - \Drupal::state()->set($key, $remove_dependency); + \Drupal::state()->set($key, $dependency_removal_return_value); // Delete the backend's dependency. $this->dependency->delete(); @@ -147,7 +147,7 @@ class DependencyRemovalTest extends KernelTestBase { $storage->resetCache(); $server = $storage->load($server->id()); - if ($remove_dependency) { + if ($dependency_removal_return_value) { $this->assertInstanceOf('Drupal\search_api\ServerInterface', $server, 'Server was not removed'); $this->assertArrayNotHasKey('dependencies', $server->get('backend_config'), 'Backend config was adapted'); // @todo Logically, this should not be changed: if the server does not get @@ -169,13 +169,13 @@ class DependencyRemovalTest extends KernelTestBase { /** * Tests a datasource with a dependency that gets removed. * - * @param bool $remove_dependency + * @param bool $dependency_removal_return_value * Whether to remove the dependency from the datasource when the object * depended on is deleted. * * @dataProvider dependencyTestDataProvider */ - public function testDatasourceDependency($remove_dependency) { + public function testDatasourceDependency($dependency_removal_return_value) { // Add the datasource to the index and save it. The datasource configuration // contains the dependencies it will return – in our case, we use the test // server. @@ -207,7 +207,7 @@ class DependencyRemovalTest extends KernelTestBase { // dependency should be removed or not. See // \Drupal\search_api_test_dependencies\Plugin\search_api\datasource\TestDatasource::onDependencyRemoval(). $key = 'search_api_test_dependencies.datasource.remove'; - \Drupal::state()->set($key, $remove_dependency); + \Drupal::state()->set($key, $dependency_removal_return_value); // Delete the datasource's dependency. $this->dependency->delete(); @@ -224,7 +224,7 @@ class DependencyRemovalTest extends KernelTestBase { // Depending on whether the plugin should have removed the dependency or // not, make sure the right action was taken. $datasources = $this->index->get('datasource_settings'); - if ($remove_dependency) { + if ($dependency_removal_return_value) { $this->assertContains('search_api_test_dependencies', array_keys($datasources), 'Datasource not removed'); $this->assertEmpty($datasources['search_api_test_dependencies']['settings'], 'Datasource settings adapted'); } @@ -273,13 +273,13 @@ class DependencyRemovalTest extends KernelTestBase { /** * Tests a processor with a dependency that gets removed. * - * @param bool $remove_dependency + * @param bool $dependency_removal_return_value * Whether to remove the dependency from the processor when the object * depended on is deleted. * * @dataProvider dependencyTestDataProvider */ - public function testProcessorDependency($remove_dependency) { + public function testProcessorDependency($dependency_removal_return_value) { // Add the processor to the index and save it. The processor configuration // contains the dependencies it will return – in our case, we use the test // server. @@ -305,7 +305,7 @@ class DependencyRemovalTest extends KernelTestBase { // dependency should be removed or not. See // \Drupal\search_api_test_dependencies\Plugin\search_api\processor\TestProcessor::onDependencyRemoval(). $key = 'search_api_test_dependencies.processor.remove'; - \Drupal::state()->set($key, $remove_dependency); + \Drupal::state()->set($key, $dependency_removal_return_value); // Delete the processor's dependency. $this->dependency->delete(); @@ -322,7 +322,7 @@ class DependencyRemovalTest extends KernelTestBase { // Depending on whether the plugin should have removed the dependency or // not, make sure the right action was taken. $processors = $this->index->get('processors'); - if ($remove_dependency) { + if ($dependency_removal_return_value) { $this->assertArrayHasKey('search_api_test_dependencies', $processors, 'Processor not removed'); $this->assertEmpty($processors['search_api_test_dependencies']['settings'], 'Processor settings adapted'); } @@ -334,13 +334,13 @@ class DependencyRemovalTest extends KernelTestBase { /** * Tests a tracker with a dependency that gets removed. * - * @param bool $remove_dependency + * @param bool $dependency_removal_return_value * Whether to remove the dependency from the tracker when the object * depended on is deleted. * * @dataProvider dependencyTestDataProvider */ - public function testTrackerDependency($remove_dependency) { + public function testTrackerDependency($dependency_removal_return_value) { // Set the tracker for the index and save it. The tracker configuration // contains the dependencies it will return – in our case, we use the test // server. @@ -366,10 +366,10 @@ class DependencyRemovalTest extends KernelTestBase { // dependency should be removed or not. See // \Drupal\search_api_test_dependencies\Plugin\search_api\tracker\TestTracker::onDependencyRemoval(). $key = 'search_api_test_dependencies.tracker.remove'; - \Drupal::state()->set($key, $remove_dependency); + \Drupal::state()->set($key, $dependency_removal_return_value); // If the index resets the tracker, it needs to know the ID of the default // tracker. - if (!$remove_dependency) { + if (!$dependency_removal_return_value) { \Drupal::configFactory()->getEditable('search_api.settings') ->set('default_tracker', 'default') ->save(); @@ -393,7 +393,7 @@ class DependencyRemovalTest extends KernelTestBase { $plugins = array_keys($config); $tracker = $config[$plugins[0]]['plugin_id']; $tracker_config = $config[$plugins[0]]['settings']; - if ($remove_dependency) { + if ($dependency_removal_return_value) { $this->assertEquals('search_api_test_dependencies', $tracker, 'Tracker not reset'); $this->assertEmpty($tracker_config, 'Tracker settings adapted'); } @@ -461,13 +461,24 @@ class DependencyRemovalTest extends KernelTestBase { /** * Data provider for this class's test methods. * + * If $dependency_removal_return_value is TRUE, in + * Plugin::onDependencyRemoval() it clears its configuration (and thus its + * dependency, in those test plugins) and returns TRUE, which the index will + * take as "all OK, dependency removed" and leave the plugin where it is, + * only with updated configuration. + * + * If $dependency_removal_return_value is FALSE, Plugin::onDependencyRemoval() + * will do nothing and just return FALSE, the index says "oh, that plugin + * still has that removed depenency, so I should better remove the plugin" + * and the plugin gets removed. + * * @return array * An array of argument arrays for this class's test methods. */ public function dependencyTestDataProvider() { return array( - 'Remove dependency' => array(TRUE), - 'Keep dependency' => array(FALSE), + 'Keep dependency' => array(TRUE), + 'Remove dependency' => array(FALSE), ); }