function ExportStorageManagerTest::testGetStorage
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Config/ExportStorageManagerTest.php \Drupal\KernelTests\Core\Config\ExportStorageManagerTest::testGetStorage()
- 8.9.x core/tests/Drupal/KernelTests/Core/Config/ExportStorageManagerTest.php \Drupal\KernelTests\Core\Config\ExportStorageManagerTest::testGetStorage()
- 11.x core/tests/Drupal/KernelTests/Core/Config/ExportStorageManagerTest.php \Drupal\KernelTests\Core\Config\ExportStorageManagerTest::testGetStorage()
Tests getting the export storage.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ ExportStorageManagerTest.php, line 40
Class
- ExportStorageManagerTest
- Tests the export storage manager.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testGetStorage() : void {
// Get the raw system.site config and set it in the sync storage.
$rawConfig = $this->config('system.site')
->getRawData();
$this->container
->get('config.storage.sync')
->write('system.site', $rawConfig);
// The export storage manager under test.
$manager = new ExportStorageManager($this->container
->get('config.storage'), $this->container
->get('database'), $this->container
->get('event_dispatcher'), new NullLockBackend());
$storage = $manager->getStorage();
$exported = $storage->read('system.site');
// The test subscriber adds "Arrr" to the slogan of the sync config.
$this->assertEquals($rawConfig['name'], $exported['name']);
$this->assertEquals($rawConfig['slogan'] . ' Arrr', $exported['slogan']);
// Save the config to active storage so that the transformer can alter it.
$this->config('system.site')
->set('name', 'New name')
->set('slogan', 'New slogan')
->save();
// Get the storage again.
$storage = $manager->getStorage();
$exported = $storage->read('system.site');
// The test subscriber adds "Arrr" to the slogan of the sync config.
$this->assertEquals('New name', $exported['name']);
$this->assertEquals($rawConfig['slogan'] . ' Arrr', $exported['slogan']);
// Change what the transformer does without changing anything else to assert
// that the event is dispatched every time the storage is needed.
$this->container
->get('state')
->set('config_transform_test_mail', 'config@drupal.example');
$storage = $manager->getStorage();
$exported = $storage->read('system.site');
// The mail is still set to the value from the beginning.
$this->assertEquals('config@drupal.example', $exported['mail']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.