diff --git a/src/Entity/Index.php b/src/Entity/Index.php index bf01515..e9d6886 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -199,7 +199,7 @@ class Index extends ConfigEntityBase implements IndexInterface { * * @see loadProcessors() */ - protected $processorInstances; + protected $processorInstances = NULL; /** * Whether reindexing has been triggered for this index in this page request. @@ -491,8 +491,8 @@ class Index extends ConfigEntityBase implements IndexInterface { 'settings' => $processor->getConfiguration(), ); - // Reset processors static cache. - $this->processorInstances = array(); + // Reset processors canonical storage. + $this->processorInstances = NULL; return $this; } @@ -503,8 +503,8 @@ class Index extends ConfigEntityBase implements IndexInterface { public function removeProcessor($processor_id) { unset($this->processor_settings[$processor_id]); - // Reset processors static cache. - $this->processorInstances = array(); + // Reset processors canonical storage. + $this->processorInstances = NULL; return $this; } @@ -516,7 +516,7 @@ class Index extends ConfigEntityBase implements IndexInterface { * The loaded processors, keyed by processor ID. */ protected function loadProcessors() { - if (empty($this->processorInstances)) { + if (is_null($this->processorInstances)) { /** @var $processor_plugin_manager \Drupal\search_api\Processor\ProcessorPluginManager */ $processor_plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); $processor_settings = $this->processor_settings; diff --git a/src/Tests/Processor/ProcessorIntegrationTest.php b/src/Tests/Processor/ProcessorIntegrationTest.php index 1be986d..9519a62 100644 --- a/src/Tests/Processor/ProcessorIntegrationTest.php +++ b/src/Tests/Processor/ProcessorIntegrationTest.php @@ -50,65 +50,86 @@ class ProcessorIntegrationTest extends WebTestBase { public function testProcessorIntegration() { // By default, the add_url and language processors are already enabled. $enabled = array('add_url', 'language'); - $this->assertEqual(sort($enabled), array_keys($this->loadIndex()->getProcessors())); + $this->assertEqual($enabled, array_keys($this->loadIndex()->getProcessors())); $this->checkContentAccessIntegration(); $enabled[] = 'content_access'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkHighlightIntegration(); $enabled[] = 'highlight'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkHtmlFilterIntegration(); $enabled[] = 'html_filter'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkIgnoreCaseIntegration(); $enabled[] = 'ignorecase'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkIgnoreCharactersIntegration(); $enabled[] = 'ignore_character'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkNodeStatusIntegration(); $enabled[] = 'node_status'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkRenderedItemIntegration(); $enabled[] = 'rendered_item'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkStopWordsIntegration(); $enabled[] = 'stopwords'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkTokenizerIntegration(); $enabled[] = 'tokenizer'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkTransliterationIntegration(); $enabled[] = 'transliteration'; + sort($enabled); $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); // The 'language' and 'add_url' processors are are not available to be removed $actual_processors = array_keys($this->loadIndex()->getProcessors()); - $this->assertEqual(sort($enabled), sort($actual_processors)); + sort($actual_processors); + $this->assertEqual($enabled, $actual_processors); $this->checkLanguageIntegration(); - $this->assertEqual(sort($enabled), sort($actual_processors)); + $this->assertEqual($enabled, $actual_processors); $this->checkUrlFieldIntegration(); - $this->assertEqual(sort($enabled), sort($actual_processors)); + $this->assertEqual($enabled, $actual_processors); } /** diff --git a/tests/src/Kernel/DependencyRemovalTest.php b/tests/src/Kernel/DependencyRemovalTest.php index 745f379..641d0e9 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 $dependency_removal_return_value + * @param bool $remove_dependency * Whether to remove the dependency from the backend when the object * depended on is deleted. * * @dataProvider dependencyTestDataProvider */ - public function testBackendDependency($dependency_removal_return_value) { + public function testBackendDependency($remove_dependency) { $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, $dependency_removal_return_value); + \Drupal::state()->set($key, $remove_dependency); // Delete the backend's dependency. $this->dependency->delete(); @@ -147,7 +147,7 @@ class DependencyRemovalTest extends KernelTestBase { $storage->resetCache(); $server = $storage->load($server->id()); - if ($dependency_removal_return_value) { + if ($remove_dependency) { $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 $dependency_removal_return_value + * @param bool $remove_dependency * Whether to remove the dependency from the datasource when the object * depended on is deleted. * * @dataProvider dependencyTestDataProvider */ - public function testDatasourceDependency($dependency_removal_return_value) { + public function testDatasourceDependency($remove_dependency) { // 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, $dependency_removal_return_value); + \Drupal::state()->set($key, $remove_dependency); // Delete the datasource's dependency. $this->dependency->delete(); @@ -224,13 +224,12 @@ 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 ($dependency_removal_return_value) { - $this->assertContains('search_api_test_dependencies', array_keys($datasources), 'Datasource not removed'); + if ($remove_dependency) { + $this->assertArrayHasKey('search_api_test_dependencies', $datasources, 'Datasource not removed'); $this->assertEmpty($datasources['search_api_test_dependencies']['settings'], 'Datasource settings adapted'); } else { - $this->assertNotContains('search_api_test_dependencies', array_keys($datasources), 'Datasource removed'); - $this->assertArrayNotHasKey('search_api_test_dependencies', $datasources, 'Datasource config removed'); + $this->assertArrayNotHasKey('search_api_test_dependencies', $datasources, 'Datasource removed'); } } @@ -273,13 +272,13 @@ class DependencyRemovalTest extends KernelTestBase { /** * Tests a processor with a dependency that gets removed. * - * @param bool $dependency_removal_return_value + * @param bool $remove_dependency * Whether to remove the dependency from the processor when the object * depended on is deleted. * * @dataProvider dependencyTestDataProvider */ - public function testProcessorDependency($dependency_removal_return_value) { + public function testProcessorDependency($remove_dependency) { // 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 +304,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, $dependency_removal_return_value); + \Drupal::state()->set($key, $remove_dependency); // Delete the processor's dependency. $this->dependency->delete(); @@ -322,7 +321,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('processor_settings'); - if ($dependency_removal_return_value) { + if ($remove_dependency) { $this->assertArrayHasKey('search_api_test_dependencies', $processors, 'Processor not removed'); $this->assertEmpty($processors['search_api_test_dependencies']['settings'], 'Processor settings adapted'); } @@ -334,13 +333,13 @@ class DependencyRemovalTest extends KernelTestBase { /** * Tests a tracker with a dependency that gets removed. * - * @param bool $dependency_removal_return_value + * @param bool $remove_dependency * Whether to remove the dependency from the tracker when the object * depended on is deleted. * * @dataProvider dependencyTestDataProvider */ - public function testTrackerDependency($dependency_removal_return_value) { + public function testTrackerDependency($remove_dependency) { // 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 +365,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, $dependency_removal_return_value); + \Drupal::state()->set($key, $remove_dependency); // If the index resets the tracker, it needs to know the ID of the default // tracker. - if (!$dependency_removal_return_value) { + if (!$remove_dependency) { \Drupal::configFactory()->getEditable('search_api.settings') ->set('default_tracker', 'default') ->save(); @@ -393,7 +392,7 @@ class DependencyRemovalTest extends KernelTestBase { $plugins = array_keys($config); $tracker = $config[$plugins[0]]['plugin_id']; $tracker_config = $config[$plugins[0]]['settings']; - if ($dependency_removal_return_value) { + if ($remove_dependency) { $this->assertEquals('search_api_test_dependencies', $tracker, 'Tracker not reset'); $this->assertEmpty($tracker_config, 'Tracker settings adapted'); } @@ -461,16 +460,15 @@ 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 $remove_dependency 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 dependency, so I should better remove the plugin" - * and the plugin gets removed. + * If $remove_dependency is FALSE, Plugin::onDependencyRemoval() will do + * nothing and just return FALSE, the index says "oh, that plugin still has + * that removed dependency, 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.