function ConfigEntityStorageTest::testSaveRename

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityStorageTest::testSaveRename()
  2. 8.9.x core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityStorageTest::testSaveRename()
  3. 11.x core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityStorageTest::testSaveRename()

@covers ::save @covers ::doSave

@depends testSaveInsert

File

core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php, line 367

Class

ConfigEntityStorageTest
@coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityStorage @group Config

Namespace

Drupal\Tests\Core\Config\Entity

Code

public function testSaveRename(ConfigEntityInterface $entity) : void {
    $immutable_config_object = $this->prophesize(ImmutableConfig::class);
    $immutable_config_object->isNew()
        ->willReturn(FALSE);
    $config_object = $this->prophesize(Config::class);
    $config_object->setData([
        'id' => 'bar',
        'uuid' => 'bar',
        'dependencies' => [],
        'langcode' => 'hu',
        'status' => TRUE,
    ])
        ->shouldBeCalled();
    $config_object->save(FALSE)
        ->shouldBeCalled();
    $config_object->get()
        ->willReturn([]);
    $this->cacheTagsInvalidator
        ->invalidateTags([
        $this->entityTypeId . '_list',
    ])
        ->shouldBeCalled();
    $this->configFactory
        ->get('the_provider.the_config_prefix.foo')
        ->willReturn($immutable_config_object->reveal());
    $this->configFactory
        ->loadMultiple([
        'the_provider.the_config_prefix.foo',
    ])
        ->willReturn([]);
    $this->configFactory
        ->rename('the_provider.the_config_prefix.foo', 'the_provider.the_config_prefix.bar')
        ->shouldBeCalled();
    $this->configFactory
        ->getEditable('the_provider.the_config_prefix.bar')
        ->willReturn($config_object->reveal());
    // Performing a rename does not change the original ID until saving.
    $this->assertSame('foo', $entity->getOriginalId());
    $entity->set('id', 'bar');
    $this->assertSame('foo', $entity->getOriginalId());
    $this->entityQuery
        ->condition('uuid', 'bar')
        ->willReturn($this->entityQuery);
    $this->entityQuery
        ->execute()
        ->willReturn([
        $entity->id(),
    ]);
    $return = $this->entityStorage
        ->save($entity);
    $this->assertSame(SAVED_UPDATED, $return);
    $this->assertSame('bar', $entity->getOriginalId());
}

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