function CheckpointStorageTest::testConfigRename

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::testConfigRename()

File

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

Class

CheckpointStorageTest
Tests CheckpointStorage operations.

Namespace

Drupal\KernelTests\Core\Config\Storage\Checkpoint

Code

public function testConfigRename() : void {
    $checkpoint_storage = $this->container
        ->get('config.storage.checkpoint');
    $check1 = $checkpoint_storage->checkpoint('A');
    $this->container
        ->get('config.factory')
        ->rename('config_test.dynamic.dotted.default', 'config_test.dynamic.renamed');
    $this->config('config_test.dynamic.renamed')
        ->set('id', 'renamed')
        ->save();
    $this->assertFalse($checkpoint_storage->exists('config_test.dynamic.renamed'));
    $this->assertTrue($checkpoint_storage->exists('config_test.dynamic.dotted.default'));
    $this->assertSame('dotted.default', $checkpoint_storage->read('config_test.dynamic.dotted.default')['id']);
    $this->assertSame($checkpoint_storage->read('config_test.dynamic.dotted.default')['uuid'], $this->config('config_test.dynamic.renamed')
        ->get('uuid'));
    $check2 = $checkpoint_storage->checkpoint('B');
    
    /** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $storage */
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('config_test');
    // Entity1 will be deleted by the test.
    $entity1 = $storage->create([
        'id' => 'dotted.default',
        'label' => 'Another one',
    ]);
    $entity1->save();
    $check3 = $checkpoint_storage->checkpoint('C');
    $checkpoint_storage->setCheckpointToReadFrom($check2);
    $this->assertFalse($checkpoint_storage->exists('config_test.dynamic.dotted.default'));
    $checkpoint_storage->setCheckpointToReadFrom($check3);
    $this->assertTrue($checkpoint_storage->exists('config_test.dynamic.dotted.default'));
    $this->assertNotEquals($checkpoint_storage->read('config_test.dynamic.dotted.default')['uuid'], $this->config('config_test.dynamic.renamed')
        ->get('uuid'));
    $this->assertSame('Another one', $checkpoint_storage->read('config_test.dynamic.dotted.default')['label']);
    $checkpoint_storage->setCheckpointToReadFrom($check1);
    $this->assertSame('Default', $checkpoint_storage->read('config_test.dynamic.dotted.default')['label']);
}

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