ExportStorageManagerTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Config/ExportStorageManagerTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Config;
use Drupal\Core\Config\ExportStorageManager;
use Drupal\Core\Config\StorageTransformerException;
use Drupal\Core\Lock\NullLockBackend;
use Drupal\KernelTests\KernelTestBase;
class ExportStorageManagerTest extends KernelTestBase {
protected static $modules = [
'system',
'config_transformer_test',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'system',
]);
}
public function testGetStorage() {
$rawConfig = $this
->config('system.site')
->getRawData();
$this->container
->get('config.storage.sync')
->write('system.site', $rawConfig);
$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');
$this
->assertEquals($rawConfig['name'], $exported['name']);
$this
->assertEquals($rawConfig['slogan'] . ' Arrr', $exported['slogan']);
$this
->config('system.site')
->set('name', 'New name')
->set('slogan', 'New slogan')
->save();
$storage = $manager
->getStorage();
$exported = $storage
->read('system.site');
$this
->assertEquals('New name', $exported['name']);
$this
->assertEquals($rawConfig['slogan'] . ' Arrr', $exported['slogan']);
$this->container
->get('state')
->set('config_transform_test_mail', 'config@drupal.example');
$storage = $manager
->getStorage();
$exported = $storage
->read('system.site');
$this
->assertEquals('config@drupal.example', $exported['mail']);
}
public function testGetStorageLock() {
$lock = $this
->createMock('Drupal\\Core\\Lock\\LockBackendInterface');
$lock
->expects($this
->exactly(2))
->method('acquire')
->with(ExportStorageManager::LOCK_NAME)
->will($this
->returnValue(FALSE));
$lock
->expects($this
->once())
->method('wait')
->with(ExportStorageManager::LOCK_NAME);
$manager = new ExportStorageManager($this->container
->get('config.storage'), $this->container
->get('database'), $this->container
->get('event_dispatcher'), $lock);
$this
->expectException(StorageTransformerException::class);
$this
->expectExceptionMessage("Cannot acquire config export transformer lock.");
$manager
->getStorage();
}
}