public function IndividualExportImportTest::testImport in Configuration Split 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/IndividualExportImportTest.php \Drupal\Tests\config_split\Kernel\IndividualExportImportTest::testImport()
Test importing of a split.
File
- tests/src/ Kernel/ IndividualExportImportTest.php, line 168 
Class
- IndividualExportImportTest
- Test the export and import of individual splits.
Namespace
Drupal\Tests\config_split\KernelCode
public function testImport() {
  // Set up the split storage to contain the data it should.
  $storage = $this
    ->getSplitSourceStorage($this->split);
  $this
    ->copyConfig($this
    ->getSplitExpectationStorage(), $storage);
  static::assertEmpty($this
    ->getSyncFileStorage()
    ->listAll());
  static::assertEmpty($this
    ->getSyncFileStorage()
    ->getAllCollectionNames());
  // Do the import.
  $this->container
    ->get('config_split.cli')
    ->ioImport($this->split
    ->getName(), $this->io, $this->t);
  static::assertCount(2, $this->io->calls);
  static::assertEquals([
    'confirm',
  ], array_keys($this->io->calls[0]));
  if (isset($this->io->calls[1]['error'])) {
    // This is not a real assertion but it will display nicer.
    static::assertEquals([
      '',
    ], $this->io->calls[1]['error']);
  }
  static::assertEquals([
    'text' => [
      'There are no changes to import.',
    ],
  ], $this->io->calls[1]);
  // Change some data so that there is something to import.
  $data = $storage
    ->read('config_test.system');
  $data['foo'] = 'test split';
  $storage
    ->write('config_test.system', $data);
  $this->io->calls = [];
  // Do the import.
  $this->container
    ->get('config_split.cli')
    ->ioImport($this->split
    ->getName(), $this->io, $this->t);
  // The data was imported.
  static::assertEquals($data, $this
    ->getActiveStorage()
    ->read('config_test.system'));
  static::assertCount(2, $this->io->calls);
  static::assertEquals([
    'confirm',
  ], array_keys($this->io->calls[0]));
  static::assertEquals([
    'success' => [
      'Configuration successfully imported.',
    ],
  ], $this->io->calls[1]);
}