hasUnprocessedConfigurationChanges example



  /** * Imports the changelist to the target storage. * * @return $this * The ConfigImporter instance. * * @throws \Drupal\Core\Config\ConfigException */
  public function import() {
    if ($this->hasUnprocessedConfigurationChanges()) {
      $sync_steps = $this->initialize();

      foreach ($sync_steps as $step) {
        $context = [];
        do {
          $this->doSyncStep($step$context);
        } while ($context['finished'] < 1);
      }
    }
    return $this;
  }

  
$config = $this->config($dynamic_name);
    $this->assertNull($config->get('id'));

    // Verify that appropriate module API hooks have been invoked.     $this->assertTrue(isset($GLOBALS['hook_config_test']['load']));
    $this->assertFalse(isset($GLOBALS['hook_config_test']['presave']));
    $this->assertFalse(isset($GLOBALS['hook_config_test']['insert']));
    $this->assertFalse(isset($GLOBALS['hook_config_test']['update']));
    $this->assertTrue(isset($GLOBALS['hook_config_test']['predelete']));
    $this->assertTrue(isset($GLOBALS['hook_config_test']['delete']));

    $this->assertFalse($config_importer->hasUnprocessedConfigurationChanges());
    $logs = $config_importer->getErrors();
    $this->assertCount(0, $logs);
  }

  /** * Tests creation of configuration during import. */
  public function testNew() {
    $dynamic_name = 'config_test.dynamic.new';
    $storage = $this->container->get('config.storage');
    $sync = $this->container->get('config.storage.sync');

    
    // will be recreated.     $creates = $this->configImporter->getUnprocessedConfiguration('create');
    $deletes = $this->configImporter->getUnprocessedConfiguration('delete');
    $this->assertCount(5, $creates, 'There are 5 configuration items to create.');
    $this->assertCount(5, $deletes, 'There are 5 configuration items to delete.');
    $this->assertCount(0, $this->configImporter->getUnprocessedConfiguration('update'), 'There are no configuration items to update.');
    $this->assertSame($createsarray_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');

    $this->configImporter->import();

    // Verify that there is nothing more to import.     $this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
    $content_type = NodeType::load($type_name);
    $this->assertEquals('Node type one', $content_type->label());
  }

}
Home | Imprint | This part of the site doesn't use cookies.