You are here

public function ConfigDevelSubscriberTestBase::testSubscribers in Configuration development 8

Test the import subscriber.

File

tests/src/Kernel/ConfigDevelSubscriberTestBase.php, line 28

Class

ConfigDevelSubscriberTestBase

Namespace

Drupal\Tests\config_devel\Kernel

Code

public function testSubscribers() {

  // Without this the config exporter breaks.
  $this->container
    ->get('config.installer')
    ->installDefaultConfig('module', 'config_devel');
  $filename = 'public://' . static::CONFIGNAME . '.yml';
  $this->container
    ->get('file_system')
    ->mkdir('public://exported');
  $exported_filename = 'public://exported/' . static::CONFIGNAME . '.yml';
  $this->container
    ->get('config.factory')
    ->getEditable('config_devel.settings')
    ->set('auto_import', array(
    array(
      'filename' => $filename,
      'hash' => '',
    ),
  ))
    ->set('auto_export', array(
    $exported_filename,
  ))
    ->save();
  $this->storage = \Drupal::service('config.storage');
  $this
    ->assertFalse($this->storage
    ->exists(static::CONFIGNAME));
  $subscriber = $this->container
    ->get('config_devel.auto_import_subscriber');
  for ($i = 2; $i; $i--) {
    $data['label'] = $this
      ->randomString();
    file_put_contents($filename, Yaml::encode($data));

    // The import fires an export too.
    $subscriber
      ->autoImportConfig();
    $this
      ->doAssert($data, Yaml::decode(file_get_contents($exported_filename)));
  }
}