You are here

public function ConfigImportUITest::testImportErrorLog in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testImportErrorLog()

Tests an import that results in an error.

File

core/modules/config/tests/src/Functional/ConfigImportUITest.php, line 401

Class

ConfigImportUITest
Tests the user interface for importing configuration.

Namespace

Drupal\Tests\config\Functional

Code

public function testImportErrorLog() {
  $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);

  // Verify that there are configuration differences to import.
  $this
    ->drupalGet('admin/config/development/configuration');
  $this
    ->assertSession()
    ->pageTextNotContains('There are no configuration changes to import.');

  // Attempt to import configuration and verify that an error message appears.
  $this
    ->submitForm([], 'Import all');
  $this
    ->assertSession()
    ->pageTextContains('Deleted and replaced configuration entity "' . $name_secondary . '"');
  $this
    ->assertSession()
    ->pageTextContains('The configuration was imported with errors.');
  $this
    ->assertSession()
    ->pageTextNotContains('The configuration was imported successfully.');
  $this
    ->assertSession()
    ->pageTextContains('There are no configuration changes to import.');
}