You are here

public function ExportStorageManagerTest::testGetStorage in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Config/ExportStorageManagerTest.php \Drupal\KernelTests\Core\Config\ExportStorageManagerTest::testGetStorage()
  2. 9 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 36

Class

ExportStorageManagerTest
Tests the export storage manager.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testGetStorage() {

  // 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']);
}