You are here

public function ConfigEntityStorageTest::testSaveChangedUuid in Zircon Profile 8

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

@covers ::save @covers ::doSave

@expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException @expectedExceptionMessage when this entity already exists with UUID

File

core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php, line 612
Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityStorageTest.

Class

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

Namespace

Drupal\Tests\Core\Config\Entity

Code

public function testSaveChangedUuid() {
  $config_object = $this
    ->getMockBuilder('Drupal\\Core\\Config\\Config')
    ->disableOriginalConstructor()
    ->getMock();
  $config_object
    ->expects($this
    ->atLeastOnce())
    ->method('isNew')
    ->will($this
    ->returnValue(FALSE));
  $config_object
    ->expects($this
    ->never())
    ->method('save');
  $config_object
    ->expects($this
    ->exactly(2))
    ->method('get')
    ->will($this
    ->returnValueMap(array(
    array(
      '',
      array(
        'id' => 'foo',
      ),
    ),
    array(
      'id',
      'foo',
    ),
  )));
  $config_object
    ->expects($this
    ->exactly(1))
    ->method('getCacheContexts')
    ->willReturn([]);
  $config_object
    ->expects($this
    ->exactly(1))
    ->method('getCacheTags')
    ->willReturn([
    'config:foo',
  ]);
  $config_object
    ->expects($this
    ->exactly(1))
    ->method('getCacheMaxAge')
    ->willReturn(Cache::PERMANENT);
  $config_object
    ->expects($this
    ->exactly(1))
    ->method('getName')
    ->willReturn('foo');
  $this->cacheTagsInvalidator
    ->expects($this
    ->never())
    ->method('invalidateTags');
  $this->configFactory
    ->expects($this
    ->at(1))
    ->method('loadMultiple')
    ->with(array(
    'the_config_prefix.foo',
  ))
    ->will($this
    ->returnValue(array()));
  $this->configFactory
    ->expects($this
    ->at(2))
    ->method('loadMultiple')
    ->with(array(
    'the_config_prefix.foo',
  ))
    ->will($this
    ->returnValue(array(
    $config_object,
  )));
  $this->configFactory
    ->expects($this
    ->once())
    ->method('get')
    ->with('the_config_prefix.foo')
    ->will($this
    ->returnValue($config_object));
  $this->configFactory
    ->expects($this
    ->never())
    ->method('rename')
    ->will($this
    ->returnValue($config_object));
  $this->moduleHandler
    ->expects($this
    ->exactly(2))
    ->method('getImplementations')
    ->will($this
    ->returnValue(array()));
  $this->entityQuery
    ->expects($this
    ->once())
    ->method('condition')
    ->will($this
    ->returnSelf());
  $this->entityQuery
    ->expects($this
    ->once())
    ->method('execute')
    ->will($this
    ->returnValue(array(
    'foo',
  )));
  $entity = $this
    ->getMockEntity(array(
    'id' => 'foo',
  ));
  $entity
    ->set('uuid', 'baz');
  $this->entityStorage
    ->save($entity);
}