You are here

public function TamperConfigSchemaTest::testCreateInstance in Tamper 8

Tests instantiating each plugin.

File

tests/src/Kernel/TamperConfigSchemaTest.php, line 51

Class

TamperConfigSchemaTest
Tests config schema of each tamper plugin.

Namespace

Drupal\Tests\tamper\Kernel

Code

public function testCreateInstance() {
  $tamper_manager = \Drupal::service('plugin.manager.tamper');
  $plugin_collection = new TamperPluginCollection($tamper_manager, new SourceDefinition([]), []);
  foreach ($tamper_manager
    ->getDefinitions() as $plugin_id => $plugin_definition) {

    // Create instance. DefaultLazyPluginCollection uses 'id' as plugin key.
    $plugin_collection
      ->addInstanceId($plugin_id, [
      'id' => $plugin_id,
    ]);

    // Assert that the instance implements TamperInterface.
    $tamper = $plugin_collection
      ->get($plugin_id);
    $this
      ->assertInstanceOf(TamperInterface::class, $tamper);

    // Add tamper instances to the entity so that the config schema checker
    // runs.
    $this->entity
      ->setThirdPartySetting('tamper_test', 'tampers', $plugin_collection
      ->getConfiguration());
    $this->entity
      ->save();
  }
}