function StorageCopyTraitTest::testWithInvalidConfiguration
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php \Drupal\Tests\Core\Config\StorageCopyTraitTest::testWithInvalidConfiguration()
- 8.9.x core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php \Drupal\Tests\Core\Config\StorageCopyTraitTest::testWithInvalidConfiguration()
- 11.x core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php \Drupal\Tests\Core\Config\StorageCopyTraitTest::testWithInvalidConfiguration()
Tests replaceStorageContents() with config with an invalid configuration.
@covers ::replaceStorageContents
File
-
core/
tests/ Drupal/ Tests/ Core/ Config/ StorageCopyTraitTest.php, line 124
Class
- StorageCopyTraitTest
- @coversDefaultClass \Drupal\Core\Config\StorageCopyTrait @group Config
Namespace
Drupal\Tests\Core\ConfigCode
public function testWithInvalidConfiguration() : void {
$source = new TestStorage();
$this->generateRandomData($source);
// Get a name from the source config storage and set the config value to
// false. It mimics a config storage read return value when that config
// storage has an invalid configuration.
$names = $source->listAll();
$test_name = reset($names);
$source->setValue($test_name, FALSE);
$logger_factory = $this->prophesize(LoggerChannelFactoryInterface::class);
$container = new ContainerBuilder();
$container->set('logger.factory', $logger_factory->reveal());
\Drupal::setContainer($container);
// Reading a config storage with an invalid configuration logs a notice.
$channel = $this->prophesize(LoggerChannelInterface::class);
$logger_factory->get('config')
->willReturn($channel->reveal());
$channel->notice('Missing required data for configuration: %config', Argument::withEntry('%config', $test_name))
->shouldBeCalled();
// Copy the config from the source storage to the target storage.
$target = new TestStorage();
self::replaceStorageContents($source, $target);
// Test that all configuration is copied correctly and that the value of the
// config with the invalid configuration has not been copied to the target
// storage.
foreach ($names as $name) {
if ($name === $test_name) {
$this->assertFalse($source->read($name));
$this->assertFalse($target->exists($name));
}
else {
$this->assertEquals($source->read($name), $target->read($name));
}
}
// Test that the invalid configuration's name is in the source config
// storage, but not the target config storage. This ensures that it was not
// copied.
$this->assertContains($test_name, $source->listAll());
$this->assertNotContains($test_name, $target->listAll());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.