function ConfigEntityBaseUnitTest::testSleepWithPluginCollections
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testSleepWithPluginCollections()
- 8.9.x core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testSleepWithPluginCollections()
- 10 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testSleepWithPluginCollections()
@covers ::__sleep
File
-
core/
tests/ Drupal/ Tests/ Core/ Config/ Entity/ ConfigEntityBaseUnitTest.php, line 357
Class
- ConfigEntityBaseUnitTest
- @coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityBase @group Config
Namespace
Drupal\Tests\Core\Config\EntityCode
public function testSleepWithPluginCollections() : void {
$instance_id = 'the_instance_id';
$instance = new TestConfigurablePlugin([], $instance_id, []);
$plugin_manager = $this->prophesize(PluginManagerInterface::class);
$plugin_manager->createInstance($instance_id, Argument::any())
->willReturn($instance);
// Also set up a container with the plugin manager so that we can assert
// that the plugin manager itself is also not serialized.
$container = TestKernel::setContainerWithKernel();
$container->set('plugin.manager.foo', $plugin_manager->reveal());
$entity_values = [
'the_plugin_collection_config' => [
$instance_id => [
'id' => $instance_id,
'foo' => 'original_value',
],
],
];
$entity = new TestConfigEntityWithPluginCollections($entity_values, $this->entityTypeId);
$entity->setPluginManager($plugin_manager->reveal());
// After creating the entity, change the plugin configuration.
$instance->setConfiguration([
'id' => $instance_id,
'foo' => 'new_value',
]);
// After changing the plugin configuration, the entity still has the
// original value.
$expected_plugin_config = [
$instance_id => [
'id' => $instance_id,
'foo' => 'original_value',
],
];
$this->assertSame($expected_plugin_config, $entity->get('the_plugin_collection_config'));
// Ensure the plugin collection and manager is not stored.
$vars = $entity->__sleep();
$this->assertNotContains('pluginCollection', $vars);
$this->assertNotContains('pluginManager', $vars);
$this->assertSame([
'pluginManager' => 'plugin.manager.foo',
], $entity->get('_serviceIds'));
$expected_plugin_config = [
$instance_id => [
'id' => $instance_id,
'foo' => 'new_value',
],
];
// Ensure the updated values are stored in the entity.
$this->assertSame($expected_plugin_config, $entity->get('the_plugin_collection_config'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.