You are here

public function UpdaterTest::testExecuteUpdate in Update helper 2.x

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

@covers \Drupal\update_helper\Updater::executeUpdate

File

tests/src/Kernel/UpdaterTest.php, line 188

Class

UpdaterTest
@covers \Drupal\update_helper\Updater

Namespace

Drupal\Tests\update_helper\Kernel

Code

public function testExecuteUpdate() {

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

  /** @var \Drupal\Core\Config\ConfigFactory $config_factory */
  $config_factory = \Drupal::service('config.factory');
  $config = $config_factory
    ->getEditable('field.storage.node.body');
  $expected_config_data = $config
    ->get();
  $config_data = $config
    ->get();
  $config_data['status'] = FALSE;
  $config_data['type'] = 'text';
  unset($config_data['cardinality']);
  $config_data['settings'] = [
    'max_length' => 123,
  ];
  $config_data['lost_config'] = 'text';
  $config
    ->setData($config_data)
    ->save(TRUE);

  /** @var \Drupal\update_helper\Updater $update_helper */
  $update_helper = \Drupal::service('update_helper.updater');
  $this
    ->assertFalse($this->moduleHandler
    ->moduleExists('help'), 'Module "help" should not be installed.');

  // Create some configuration file for tour, so that it can be imported.
  $this
    ->assertEquals(NULL, $config_factory
    ->get('tour.tour.tour-update-helper-test')
    ->get('id'), 'Tour configuration should not exist.');

  // Ensure that configuration had new values.
  $this
    ->assertEquals('text', $config_factory
    ->get('field.storage.node.body')
    ->get('lost_config'));
  $update_helper
    ->executeUpdate('update_helper_test', 'test_updater');
  $this
    ->assertEquals($expected_config_data, $config_factory
    ->get('field.storage.node.body')
    ->get());
  $this
    ->assertTrue($this->moduleHandler
    ->moduleExists('help'), 'Module "help" should be installed.');
  $this
    ->assertEquals('tour-update-helper-test', $this->container
    ->get('config.factory')
    ->get('tour.tour.tour-update-helper-test')
    ->get('id'), 'Tour configuration should exist.');
}