function CheckpointStorageTest::testCheckpointCreation

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Config/Checkpoint/CheckpointStorageTest.php \Drupal\Tests\Core\Config\Checkpoint\CheckpointStorageTest::testCheckpointCreation()

@covers ::checkpoint @covers \Drupal\Core\Config\Checkpoint\Checkpoint

File

core/tests/Drupal/Tests/Core/Config/Checkpoint/CheckpointStorageTest.php, line 64

Class

CheckpointStorageTest
@coversDefaultClass \Drupal\Core\Config\Checkpoint\CheckpointStorage @group Config

Namespace

Drupal\Tests\Core\Config\Checkpoint

Code

public function testCheckpointCreation() : void {
    $checkpoint = $this->storage
        ->checkpoint('Test');
    $this->assertInstanceOf(Checkpoint::class, $checkpoint);
    $this->assertSame('Test', $checkpoint->label);
    $checkpoint2 = $this->storage
        ->checkpoint('This will not make a checkpoint because nothing has changed');
    $this->assertSame($checkpoint2, $checkpoint);
    $config = $this->prophesize(Config::class);
    $config->getName()
        ->willReturn('test.config');
    $config->getOriginal('', FALSE)
        ->willReturn([]);
    $config->getRawData()
        ->willReturn([
        'foo' => 'bar',
    ]);
    $config->getStorage()
        ->willReturn($this->storage);
    $event = new ConfigCrudEvent($config->reveal());
    $this->storage
        ->onConfigSaveAndDelete($event);
    $checkpoint3 = $this->storage
        ->checkpoint('Created test.config');
    $this->assertNotSame($checkpoint3, $checkpoint);
    $this->assertSame('Created test.config', $checkpoint3->label);
    $checkpoint4 = $this->storage
        ->checkpoint('This will not create a checkpoint either');
    $this->assertSame($checkpoint4, $checkpoint3);
    // Simulate a save with no change.
    $config = $this->prophesize(Config::class);
    $config->getName()
        ->willReturn('test.config');
    $config->getOriginal('', FALSE)
        ->willReturn([
        'foo' => 'bar',
    ]);
    $config->getRawData()
        ->willReturn([
        'foo' => 'bar',
    ]);
    $config->getStorage()
        ->willReturn($this->storage);
    $event = new ConfigCrudEvent($config->reveal());
    $this->storage
        ->onConfigSaveAndDelete($event);
    $checkpoint5 = $this->storage
        ->checkpoint('Save with no change');
    $this->assertSame($checkpoint5, $checkpoint3);
    // Create collection and ensure that checkpoints are kept in sync.
    $collection = $this->storage
        ->createCollection('test');
    $config = $this->prophesize(Config::class);
    $config->getName()
        ->willReturn('test.config');
    $config->getOriginal('', FALSE)
        ->willReturn([
        'foo' => 'bar',
    ]);
    $config->getRawData()
        ->willReturn([
        'foo' => 'collection_bar',
    ]);
    $config->getStorage()
        ->willReturn($collection);
    $event = new ConfigCrudEvent($config->reveal());
    $collection->onConfigSaveAndDelete($event);
    $checkpoint6 = $this->storage
        ->checkpoint('Save in collection');
    $this->assertNotSame($checkpoint6, $checkpoint3);
    $this->assertSame($collection->checkpoint('Calling checkpoint on collection'), $checkpoint6);
}

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