function ConfigEntityStorageTest::testSaveInsert

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityStorageTest::testSaveInsert()
  2. 8.9.x core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityStorageTest::testSaveInsert()
  3. 11.x 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: The entity to test.

Return value

\Drupal\Core\Entity\EntityInterface

File

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

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;
}

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