function SearchPageImportTest::checkSinglePluginConfigSync

Tests that a single set of plugin config stays in sync.

Parameters

\Drupal\Core\Entity\EntityWithPluginCollectionInterface $entity: The entity.

string $config_key: Where the plugin config is stored.

string $setting_key: The setting within the plugin config to change.

mixed $expected: The expected default value of the plugin config setting.

File

core/modules/search/tests/src/Kernel/SearchPageImportTest.php, line 70

Class

SearchPageImportTest
Tests search page import.

Namespace

Drupal\Tests\search\Kernel

Code

protected function checkSinglePluginConfigSync(EntityWithPluginCollectionInterface $entity, $config_key, $setting_key, $expected) : void {
  $plugin_collection = $entity->getPluginCollections()[$config_key];
  $settings = $entity->get($config_key);
  // Ensure the default config exists.
  $this->assertSame($expected, $settings[$setting_key]);
  // Change the plugin config by setting it on the entity.
  $settings[$setting_key] = $this->randomString();
  $entity->set($config_key, $settings);
  $entity->save();
  $this->assertSame($settings, $entity->get($config_key));
  $this->assertSame($settings, $plugin_collection->getConfiguration());
  // Change the plugin config by setting it on the plugin.
  $settings[$setting_key] = $this->randomString();
  $plugin_collection->setConfiguration($settings);
  $entity->save();
  $this->assertSame($settings, $entity->get($config_key));
  $this->assertSame($settings, $plugin_collection->getConfiguration());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.