You are here

protected function UpdaterTest::setUp in Update helper 8

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

Overrides KernelTestBase::setUp

File

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

Class

UpdaterTest
@covers \Drupal\update_helper\Updater

Namespace

Drupal\Tests\update_helper\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this->moduleHandler = \Drupal::moduleHandler();
  $this->configDir = $this->moduleHandler
    ->getModule('update_helper')
    ->getPath() . '/config';
  mkdir($this->configDir . '/install', 0755, TRUE);

  // Prepare config file for testing of configuration import.
  $tour_config = [
    'id' => 'tour-update-helper-test',
    'module' => 'update_helper',
    'label' => 'Tour test Update Helper config import',
    'langcode' => 'en',
    'routes' => [
      [
        'route_name' => 'update_helper.1',
      ],
    ],
    'tips' => [
      'tour-update-helper-test-1' => [
        'id' => 'update-helper-test-1',
        'plugin' => 'text',
        'label' => 'Update Helper',
        'body' => 'Update helper test tour.',
        'weight' => 1,
      ],
    ],
  ];

  /** @var \Drupal\Core\Serialization\Yaml $yml_serializer */
  $yml_serializer = \Drupal::service('serialization.yaml');
  file_put_contents($this->configDir . '/install/tour.tour.tour-update-helper-test.yml', $yml_serializer::encode($tour_config));

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

  // Create update configuration for testExecuteUpdate.
  $patch_file_path = $config_handler
    ->getPatchFile('update_helper', 'test_updater', TRUE);
  file_put_contents($patch_file_path, $yml_serializer::encode($this
    ->getUpdateDefinition()));

  // Create update configuration for testOnlyDeleteUpdate.
  $patch_file_path = $config_handler
    ->getPatchFile('update_helper', 'test_updater_only_delete', TRUE);
  file_put_contents($patch_file_path, $yml_serializer::encode([
    'field.storage.node.body' => [
      'expected_config' => [],
      'update_actions' => [
        'delete' => [
          'lost_config' => 'text',
        ],
      ],
    ],
  ]));
}