function ConfigImportCommandTest::testImportErrorLog

Tests an import that results in an error.

File

core/tests/Drupal/FunctionalTests/Core/Config/ConfigImportCommandTest.php, line 312

Class

ConfigImportCommandTest
Tests the 'config:import' command.

Namespace

Drupal\FunctionalTests\Core\Config

Code

public function testImportErrorLog() : void {
  $name_primary = 'config_test.dynamic.primary';
  $name_secondary = 'config_test.dynamic.secondary';
  $sync = $this->container
    ->get('config.storage.sync');
  $uuid = $this->container
    ->get('uuid');
  $values_primary = [
    'uuid' => $uuid->generate(),
    'langcode' => 'en',
    'status' => TRUE,
    'dependencies' => [],
    'id' => 'primary',
    'label' => 'Primary',
    'weight' => 0,
    'style' => NULL,
    'size' => NULL,
    'size_value' => NULL,
    'protected_property' => NULL,
  ];
  $sync->write($name_primary, $values_primary);
  $values_secondary = [
    'uuid' => $uuid->generate(),
    'langcode' => 'en',
    'status' => TRUE,
    // Add a dependency on primary, to ensure that is synced first.
'dependencies' => [
      'config' => [
        $name_primary,
      ],
    ],
    'id' => 'secondary',
    'label' => 'Secondary Sync',
    'weight' => 0,
    'style' => NULL,
    'size' => NULL,
    'size_value' => NULL,
    'protected_property' => NULL,
  ];
  $sync->write($name_secondary, $values_secondary);
  // Run the import command.
  $tester = $this->commandTester();
  $code = $tester->execute([
    '--yes' => TRUE,
  ]);
  self::assertSame(Command::FAILURE, $code);
  $display = preg_replace('/\\s+/', ' ', $tester->getDisplay());
  // Verify that both appear as ready to import.
  self::assertStringContainsString($name_primary . ' Create', $display);
  self::assertStringContainsString($name_secondary . ' Create', $display);
  self::assertStringContainsString('[ERROR] Deleted and replaced configuration entity "' . $name_secondary . '"', $display);
  self::assertStringContainsString('[ERROR] The configuration was imported with errors.', $display);
  self::assertStringNotContainsString('The configuration was imported successfully.', $display);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.