function ConfigEntityBaseUnitTest::testPreSaveDuringSync
@covers ::preSave
      
    
File
- 
              core/
tests/ Drupal/ Tests/ Core/ Config/ Entity/ ConfigEntityBaseUnitTest.php, line 189  
Class
- ConfigEntityBaseUnitTest
 - @coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityBase[[api-linebreak]] @group Config
 
Namespace
Drupal\Tests\Core\Config\EntityCode
public function testPreSaveDuringSync() : void {
  $this->moduleHandler
    ->moduleExists('node')
    ->willReturn(TRUE);
  $query = $this->createMock('\\Drupal\\Core\\Entity\\Query\\QueryInterface');
  $storage = $this->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
  $query->expects($this->any())
    ->method('execute')
    ->willReturn([]);
  $query->expects($this->any())
    ->method('condition')
    ->willReturn($query);
  $storage->expects($this->any())
    ->method('getQuery')
    ->willReturn($query);
  $storage->expects($this->any())
    ->method('loadUnchanged')
    ->willReturn($this->entity);
  // Saving an entity will not reset the dependencies array during config
  // synchronization.
  $this->entity
    ->set('dependencies', [
    'module' => [
      'node',
    ],
  ]);
  $this->entity
    ->preSave($storage);
  $this->assertEmpty($this->entity
    ->getDependencies());
  $this->entity
    ->setSyncing(TRUE);
  $this->entity
    ->set('dependencies', [
    'module' => [
      'node',
    ],
  ]);
  $this->entity
    ->preSave($storage);
  $dependencies = $this->entity
    ->getDependencies();
  $this->assertContains('node', $dependencies['module']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.