You are here

public function UpdateModeTest::testUpdateModeFullReset in Configuration Synchronizer 8.2

File

tests/src/Kernel/UpdateModeTest.php, line 241

Class

UpdateModeTest
Tests importing configuration entities using various import modes.

Namespace

Drupal\Tests\config_sync\Kernel

Code

public function testUpdateModeFullReset() {

  // Set update mode to partial reset.
  $this
    ->setUpdateMode(ConfigSyncListerInterface::UPDATE_MODE_FULL_RESET);
  $creates = $this->configImporter
    ->getUnprocessedConfiguration('create');
  $updates = $this->configImporter
    ->getUnprocessedConfiguration('update');
  $this
    ->assertEquals(0, count($this->configImporter
    ->getUnprocessedConfiguration('delete')), 'There are no configuration items to delete.');

  // node.type.config_sync_test_2 was deleted from both the snapshot and
  // the active configuration and so should be created.
  // node.type.config_sync_test_3 was deleted from active and should be
  // restored even though it is snapshotted.
  $expected_creates = [
    $this->configNames[2],
    $this->configNames[3],
  ];
  $this
    ->assertSame($creates, $expected_creates, 'Create operations match those expected.');

  // For node.type.config_sync_test_1, the snapshot differs from the current
  // provided value and from the active value.
  // For node.type.config_sync_test_4, the snapshot differs from the active
  // value.
  $expected_updates = [
    $this->configNames[1],
    $this->configNames[4],
  ];
  $this
    ->assertSame($updates, $expected_updates, 'Update operations match those expected.');
  $this->configImporter
    ->import();
  $this->container
    ->get('event_dispatcher')
    ->dispatch(ConfigDistroEvents::IMPORT);

  // Verify that all provided items are at their provided state.
  foreach (array_keys($this->configNames) as $index) {
    $node_type = NodeType::load($this->nodeTypeNames[$index]);
    $this
      ->assertEquals('Provided name', $node_type
      ->label());
    $this
      ->assertEquals('Provided description', $node_type
      ->get('description'));
    $this
      ->assertEquals('Provided help', $node_type
      ->get('help'));
  }
  $this
    ->verifySnapshot();
}