function CheckpointStorageTest::testConfigSaveAndRead

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Config/Storage/Checkpoint/CheckpointStorageTest.php \Drupal\KernelTests\Core\Config\Storage\Checkpoint\CheckpointStorageTest::testConfigSaveAndRead()

File

core/tests/Drupal/KernelTests/Core/Config/Storage/Checkpoint/CheckpointStorageTest.php, line 32

Class

CheckpointStorageTest
Tests CheckpointStorage operations.

Namespace

Drupal\KernelTests\Core\Config\Storage\Checkpoint

Code

public function testConfigSaveAndRead() : void {
    $checkpoint_storage = $this->container
        ->get('config.storage.checkpoint');
    $this->config('system.site')
        ->set('name', 'Test1')
        ->save();
    $check1 = $checkpoint_storage->checkpoint('A');
    $this->config('system.site')
        ->set('name', 'Test2')
        ->save();
    $check2 = $checkpoint_storage->checkpoint('B');
    $this->config('system.site')
        ->set('name', 'Test3')
        ->save();
    $this->assertSame('Test3', $this->config('system.site')
        ->get('name'));
    $this->assertSame('Test1', $checkpoint_storage->read('system.site')['name']);
    // The config listings should be exactly the same.
    $this->assertSame($checkpoint_storage->listAll(), $this->container
        ->get('config.storage')
        ->listAll());
    $checkpoint_storage->setCheckpointToReadFrom($check2);
    $this->assertSame('Test2', $checkpoint_storage->read('system.site')['name']);
    $this->assertSame($checkpoint_storage->listAll(), $this->container
        ->get('config.storage')
        ->listAll());
    $checkpoint_storage->setCheckpointToReadFrom($check1);
    $this->assertSame('Test1', $checkpoint_storage->read('system.site')['name']);
    $this->assertSame($checkpoint_storage->listAll(), $this->container
        ->get('config.storage')
        ->listAll());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.