You are here

public function ConfigHandlerTest::testGeneratePatchFileWithConfigExport in Update helper 2.x

Same name and namespace in other branches
  1. 8 tests/src/Kernel/ConfigHandlerTest.php \Drupal\Tests\update_helper\Kernel\ConfigHandlerTest::testGeneratePatchFileWithConfigExport()

@covers \Drupal\update_helper\ConfigHandler::generatePatchFile

File

tests/src/Kernel/ConfigHandlerTest.php, line 151

Class

ConfigHandlerTest
Automated tests for ConfigName class.

Namespace

Drupal\Tests\update_helper\Kernel

Code

public function testGeneratePatchFileWithConfigExport() {

  /** @var \Drupal\update_helper\ConfigHandler $configHandler */
  $configHandler = \Drupal::service('update_helper.config_handler');

  /** @var \Drupal\Core\Config\FileStorage $extensionStorage */
  $extensionStorage = \Drupal::service('config_update.extension_storage');
  $configFilePath = $extensionStorage
    ->getFilePath('field.storage.node.body');

  /** @var \Drupal\config_update\ConfigRevertInterface $configReverter */
  $configReverter = \Drupal::service('config_update.config_update');
  $configReverter
    ->import('field_storage_config', 'node.body');

  /** @var \Drupal\Core\Config\ConfigFactory $configFactory */
  $configFactory = \Drupal::service('config.factory');
  $config = $configFactory
    ->getEditable('field.storage.node.body');
  $configData = $config
    ->get();
  $configData['type'] = 'text';
  $configData['settings'] = [
    'max_length' => 321,
  ];
  $config
    ->setData($configData)
    ->save(TRUE);

  // Check file configuration before export.
  $fileData = Yaml::decode(file_get_contents($configFilePath));
  $this
    ->assertEqual('text_with_summary', $fileData['type']);
  $this
    ->assertEqual([], $fileData['settings']);

  // Generate patch and export config after configuration change.
  $data = $configHandler
    ->generatePatchFile([
    'node',
  ], FALSE);
  $expected = <<<EOF
field.storage.node.body:
  expected_config:
    settings: {  }
    type: text_with_summary
  update_actions:
    change:
      settings:
        max_length: 321
      type: text

EOF;
  $this
    ->assertEqual($expected, $data);

  // Check newly exported configuration.
  $fileData = Yaml::decode(file_get_contents($configFilePath));
  $this
    ->assertEqual('text', $fileData['type']);
  $this
    ->assertEqual([
    'max_length' => 321,
  ], $fileData['settings']);
}