You are here

public function ConfigEntityStorageTest::testSaveInsert in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityStorageTest::testSaveInsert()

@covers ::save @covers ::doSave

@depends testCreate

Parameters

\Drupal\Core\Entity\EntityInterface $entity:

Return value

\Drupal\Core\Entity\EntityInterface

File

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

Class

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

Namespace

Drupal\Tests\Core\Config\Entity

Code

public function testSaveInsert(EntityInterface $entity) {
  $immutable_config_object = $this
    ->prophesize(ImmutableConfig::class);
  $immutable_config_object
    ->isNew()
    ->willReturn(TRUE);
  $config_object = $this
    ->prophesize(Config::class);
  $config_object
    ->setData([
    'id' => 'foo',
    '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
    ->getEditable('the_provider.the_config_prefix.foo')
    ->willReturn($config_object
    ->reveal());
  $this->moduleHandler
    ->invokeAll('test_entity_type_presave', [
    $entity,
  ])
    ->shouldBeCalled();
  $this->moduleHandler
    ->invokeAll('entity_presave', [
    $entity,
    'test_entity_type',
  ])
    ->shouldBeCalled();
  $this->moduleHandler
    ->invokeAll('test_entity_type_insert', [
    $entity,
  ])
    ->shouldBeCalled();
  $this->moduleHandler
    ->invokeAll('entity_insert', [
    $entity,
    'test_entity_type',
  ])
    ->shouldBeCalled();
  $this->entityQuery
    ->condition('uuid', 'bar')
    ->willReturn($this->entityQuery);
  $this->entityQuery
    ->execute()
    ->willReturn([]);
  $return = $this->entityStorage
    ->save($entity);
  $this
    ->assertSame(SAVED_NEW, $return);
  return $entity;
}