function DefaultLazyPluginCollectionTest::testSetInstanceConfigurationPluginChange

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultLazyPluginCollectionTest::testSetInstanceConfigurationPluginChange()

Tests plugin instances are changed if the configuration plugin key changes.

@covers ::setInstanceConfiguration

File

core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php, line 176

Class

DefaultLazyPluginCollectionTest
@coversDefaultClass \Drupal\Core\Plugin\DefaultLazyPluginCollection @group Plugin

Namespace

Drupal\Tests\Core\Plugin

Code

public function testSetInstanceConfigurationPluginChange() : void {
    $configurable_plugin = $this->prophesize(ConfigurableInterface::class);
    $configurable_config = [
        'id' => 'configurable',
        'foo' => 'bar',
    ];
    $configurable_plugin->getConfiguration()
        ->willReturn($configurable_config);
    $nonconfigurable_plugin = $this->prophesize(PluginInspectionInterface::class);
    $nonconfigurable_config = [
        'id' => 'non-configurable',
        'baz' => 'qux',
    ];
    $nonconfigurable_plugin->configuration = $nonconfigurable_config;
    $configurations = [
        'instance' => $configurable_config,
    ];
    $plugin_manager = $this->prophesize(PluginManagerInterface::class);
    $plugin_manager->createInstance('configurable', $configurable_config)
        ->willReturn($configurable_plugin->reveal());
    $plugin_manager->createInstance('non-configurable', $nonconfigurable_config)
        ->willReturn($nonconfigurable_plugin->reveal());
    $collection = new DefaultLazyPluginCollection($plugin_manager->reveal(), $configurations);
    $this->assertInstanceOf(ConfigurableInterface::class, $collection->get('instance'));
    // Ensure changing the instance to a different plugin via
    // setInstanceConfiguration() results in a different plugin instance.
    $collection->setInstanceConfiguration('instance', $nonconfigurable_config);
    $this->assertNotInstanceOf(ConfigurableInterface::class, $collection->get('instance'));
}

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