diff --git a/modules/search_api_db/tests/src/Kernel/BackendTest.php b/modules/search_api_db/tests/src/Kernel/BackendTest.php index 9309044..1fad980 100644 --- a/modules/search_api_db/tests/src/Kernel/BackendTest.php +++ b/modules/search_api_db/tests/src/Kernel/BackendTest.php @@ -122,7 +122,7 @@ class BackendTest extends BackendTestBase { */ protected function updateIndex() { /** @var \Drupal\search_api\IndexInterface $index */ - $index = $this->getEditableIndex(); + $index = $this->getIndex(); // Remove a field from the index and check if the change is matched in the // server configuration. @@ -197,7 +197,7 @@ class BackendTest extends BackendTestBase { * (optional) Whether partial matching should be enabled or disabled. */ protected function editServerPartial($enable = TRUE) { - $server = $this->getEditableServer(); + $server = $this->getServer(); $backend_config = $server->getBackendConfig(); $backend_config['partial_matches'] = $enable; $server->setBackendConfig($backend_config); @@ -260,7 +260,7 @@ class BackendTest extends BackendTestBase { * Edits the server to change the "Minimum word length" setting. */ protected function editServerMinChars() { - $server = $this->getEditableServer(); + $server = $this->getServer(); $backend_config = $server->getBackendConfig(); $backend_config['min_chars'] = 4; $backend_config['partial_matches'] = FALSE; @@ -386,13 +386,13 @@ class BackendTest extends BackendTestBase { * Checks that field ID changes are treated correctly (without re-indexing). */ protected function checkFieldIdChanges() { - $this->getEditableIndex() + $this->getIndex() ->renameField('type', 'foobar') ->save(); $results = $this->buildSearch(NULL, array('foobar,item'))->execute(); $this->assertResults(array(1, 2, 3), $results, 'Search after renaming a field.'); - $this->getEditableIndex()->renameField('foobar', 'type')->save(); + $this->getIndex()->renameField('foobar', 'type')->save(); } /** @@ -489,8 +489,8 @@ class BackendTest extends BackendTestBase { // See whether clearing the server works. // Regression test for #2156151. - $server = $this->getEditableServer(); - $index = $this->getEditableIndex(); + $server = $this->getServer(); + $index = $this->getIndex(); $server->deleteAllIndexItems($index); $query = $this->buildSearch(); $results = $query->execute(); diff --git a/src/TemporaryConfOverrideLayer/OverrideSupportingConfigEntityBase.php b/src/TemporaryConfOverrideLayer/OverrideSupportingConfigEntityBase.php index 2140a3d..84de34e 100644 --- a/src/TemporaryConfOverrideLayer/OverrideSupportingConfigEntityBase.php +++ b/src/TemporaryConfOverrideLayer/OverrideSupportingConfigEntityBase.php @@ -35,10 +35,8 @@ abstract class OverrideSupportingConfigEntityBase extends ConfigEntityBase imple if ($this->isNew() || !$this->isImmutable()) { return $this; } - - /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */ - $storage = $this->entityTypeManager()->getStorage($this->entityTypeId); - return $storage->loadOverrideFree($this->id()); + + return self::loadEditable($this->id()); } /** @@ -54,4 +52,19 @@ abstract class OverrideSupportingConfigEntityBase extends ConfigEntityBase imple return parent::save(); } + /** + * {@inheritdoc} + */ + public static function loadEditable($id) { + $entity_manager = \Drupal::entityManager(); + return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->loadOverrideFree($id); + } + + /** + * {@inheritdoc} + */ + public static function loadEditableMultiple(array $ids = NULL) { + $entity_manager = \Drupal::entityManager(); + return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->loadMultipleOverrideFree($ids); + } } diff --git a/src/TemporaryConfOverrideLayer/OverrideSupportingConfigEntityInterface.php b/src/TemporaryConfOverrideLayer/OverrideSupportingConfigEntityInterface.php index 4412a46..778a611 100644 --- a/src/TemporaryConfOverrideLayer/OverrideSupportingConfigEntityInterface.php +++ b/src/TemporaryConfOverrideLayer/OverrideSupportingConfigEntityInterface.php @@ -32,4 +32,25 @@ interface OverrideSupportingConfigEntityInterface extends ConfigEntityInterface */ public function getEditableEntity(); + /** + * Loads an editable config entity. + * + * @param mixed $id + * The id of the entity to load. + * + * @return static + * The entity object or NULL if there is no entity with the given ID. + */ + public static function loadEditable($id); + + /** + * Loads one or more editable config entities. + * + * @param array $ids + * An array of entity IDs, or NULL to load all entities. + * + * @return static[] + * An array of entity objects indexed by their IDs. + */ + public static function loadEditableMultiple(array $ids = NULL); } diff --git a/src/Tests/HooksTest.php b/src/Tests/HooksTest.php index fcbc20a..ccfdca6 100644 --- a/src/Tests/HooksTest.php +++ b/src/Tests/HooksTest.php @@ -65,7 +65,7 @@ class HooksTest extends WebTestBase { // Parts of this test actually use the "database_search_index" from the // search_api_test_db module (via the test view). Set the processor there, // too. - $index = Index::load('database_search_index'); + $index = Index::loadEditable('database_search_index'); $processor = $index->createPlugin('processor', 'search_api_test'); $index->addProcessor($processor)->save(); diff --git a/src/Tests/ProcessorIntegrationTest.php b/src/Tests/ProcessorIntegrationTest.php index cbd5192..bd92567 100644 --- a/src/Tests/ProcessorIntegrationTest.php +++ b/src/Tests/ProcessorIntegrationTest.php @@ -549,10 +549,11 @@ TAGS * The search index used by this test. */ protected function loadIndex() { + /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $index_storage */ $index_storage = \Drupal::entityTypeManager()->getStorage('search_api_index'); $index_storage->resetCache([$this->indexId]); - return $index_storage->load($this->indexId); + return $index_storage->loadOverrideFree($this->indexId); } } diff --git a/src/Tests/WebTestBase.php b/src/Tests/WebTestBase.php index e7b79ed..26c69b2 100644 --- a/src/Tests/WebTestBase.php +++ b/src/Tests/WebTestBase.php @@ -104,7 +104,7 @@ abstract class WebTestBase extends SimpletestWebTestBase { * A search server. */ public function getTestServer() { - $server = Server::load('webtest_server'); + $server = Server::loadEditable('webtest_server'); if (!$server) { $server = Server::create(array( 'id' => 'webtest_server', @@ -127,7 +127,7 @@ abstract class WebTestBase extends SimpletestWebTestBase { */ public function getTestIndex() { $this->indexId = 'webtest_index'; - $index = Index::load($this->indexId); + $index = Index::loadEditable($this->indexId); if (!$index) { $index = Index::create(array( 'id' => $this->indexId, diff --git a/tests/src/Kernel/BackendTestBase.php b/tests/src/Kernel/BackendTestBase.php index ab956ba..d69a584 100644 --- a/tests/src/Kernel/BackendTestBase.php +++ b/tests/src/Kernel/BackendTestBase.php @@ -178,7 +178,7 @@ abstract class BackendTestBase extends KernelTestBase { * Enables the "HTML Filter" processor for the index. */ protected function enableHtmlFilter() { - $index = $this->getEditableIndex(); + $index = $this->getIndex(); /** @var \Drupal\search_api\Processor\ProcessorInterface $processor */ $processor = $index->createPlugin('processor', 'html_filter'); @@ -191,7 +191,7 @@ abstract class BackendTestBase extends KernelTestBase { * Disables the "HTML Filter" processor for the index. */ protected function disableHtmlFilter() { - $index = $this->getEditableIndex(); + $index = $this->getIndex(); $index->removeField('body'); $index->removeProcessor('html_filter'); $index->save(); @@ -844,7 +844,7 @@ abstract class BackendTestBase extends KernelTestBase { * @see https://www.drupal.org/node/1916474 */ protected function regressionTest1916474() { - $index = $this->getEditableIndex(); + $index = $this->getIndex(); $this->addField($index, 'prices', 'decimal'); $success = $index->save(); $this->assertTrue($success, 'The index field settings were successfully changed.'); @@ -900,7 +900,7 @@ abstract class BackendTestBase extends KernelTestBase { * @see https://www.drupal.org/node/2616268 */ protected function regressionTest2471509() { - $index = $this->getEditableIndex(); + $index = $this->getIndex(); $this->addField($index, 'body'); $index->save(); $this->indexItems($this->indexId); @@ -913,7 +913,7 @@ abstract class BackendTestBase extends KernelTestBase { $count = $this->indexItems($this->indexId); $this->assertEquals(1, $count, 'Indexing an item with a word longer than 50 characters worked.'); - $index = $this->getEditableIndex(); + $index = $this->getIndex(); $index->getField('body')->setType('string'); $index->save(); $count = $this->indexItems($this->indexId); @@ -959,10 +959,10 @@ abstract class BackendTestBase extends KernelTestBase { // Test the same body when indexed as a string (255 characters limit should // not be reached). - $index = $this->getEditableIndex(); + $index = $this->getIndex(); $index->getField('body')->setType('string'); $index->save(); - $count = $this->indexItems($this->indexId); + $count = $index->indexItems(); $this->assertEquals($entity_count, $count, 'Switching type from text to string worked.'); $query = $this->buildSearch(NULL, array("body,$mb_body")); @@ -1043,18 +1043,7 @@ abstract class BackendTestBase extends KernelTestBase { * The search server. */ protected function getServer() { - return Server::load($this->serverId); - } - - /** - * Retrieves the search server used by this test in an editable state. - * - * @return \Drupal\search_api\ServerInterface - * The search server. - */ - protected function getEditableServer() { - return $this->getServer() - ->getEditableEntity(); + return Server::loadEditable($this->serverId); } /** @@ -1064,18 +1053,7 @@ abstract class BackendTestBase extends KernelTestBase { * The search index. */ protected function getIndex() { - return Index::load($this->indexId); - } - - /** - * Retrieves the search index used by this test in an editable state. - * - * @return \Drupal\search_api\IndexInterface - * The search index. - */ - protected function getEditableIndex() { - return $this->getIndex() - ->getEditableEntity(); + return Index::loadEditable($this->indexId); } /** diff --git a/tests/src/Kernel/DependencyRemovalTest.php b/tests/src/Kernel/DependencyRemovalTest.php index 7b7f07f..309fd69 100644 --- a/tests/src/Kernel/DependencyRemovalTest.php +++ b/tests/src/Kernel/DependencyRemovalTest.php @@ -593,9 +593,10 @@ class DependencyRemovalTest extends KernelTestBase { * Reloads the index with the latest copy from storage. */ protected function reloadIndex() { + /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */ $storage = \Drupal::entityTypeManager()->getStorage('search_api_index'); $storage->resetCache(); - $this->index = $storage->load($this->index->id()); + $this->index = $storage->loadOverrideFree($this->index->id()); } } diff --git a/tests/src/Kernel/Processor/ContentAccessTest.php b/tests/src/Kernel/Processor/ContentAccessTest.php index e9f2f14..e9d8602 100644 --- a/tests/src/Kernel/Processor/ContentAccessTest.php +++ b/tests/src/Kernel/Processor/ContentAccessTest.php @@ -119,9 +119,10 @@ class ContentAccessTest extends ProcessorTestBase { $this->index->save(); \Drupal::getContainer()->get('search_api.index_task_manager')->addItemsAll($this->index); + /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $index_storage */ $index_storage = \Drupal::entityTypeManager()->getStorage('search_api_index'); $index_storage->resetCache([$this->index->id()]); - $this->index = $index_storage->load($this->index->id()); + $this->index = $index_storage->loadOverrideFree($this->index->id()); } /** diff --git a/tests/src/Kernel/QueryTest.php b/tests/src/Kernel/QueryTest.php index 0e7190c..f98cad3 100644 --- a/tests/src/Kernel/QueryTest.php +++ b/tests/src/Kernel/QueryTest.php @@ -89,7 +89,7 @@ class QueryTest extends KernelTestBase { 'server' => $server->id(), 'options' => array('index_directly' => FALSE), ))->save(); - $this->index = Index::load('test_index'); + $this->index = Index::loadEditable('test_index'); } /**