You are here

public function ConfigHandlerTest::testGeneratePatchFileFromActiveConfig 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::testGeneratePatchFileFromActiveConfig()

@covers \Drupal\update_helper\ConfigHandler::generatePatchFile

File

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

Class

ConfigHandlerTest
Automated tests for ConfigName class.

Namespace

Drupal\Tests\update_helper\Kernel

Code

public function testGeneratePatchFileFromActiveConfig() {

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

  /** @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['status'] = FALSE;
  $configData['type'] = 'text';
  unset($configData['cardinality']);
  $configData['settings'] = [
    'max_length' => 123,
  ];
  $configData['lost_config'] = 'text';
  $config
    ->setData($configData)
    ->save(TRUE);

  // Generate patch after configuration change.
  $data = $configHandler
    ->generatePatchFile([
    'node',
  ], TRUE);
  $this
    ->assertEquals($this
    ->getUpdateDefinition(), $data);

  // Check that configuration file is not changed.

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