Commit ccea8392 authored by Jonathan Smith's avatar Jonathan Smith
Browse files

Issue #3238953 by jonathan1055, omkar.podey, huzooka: Add migration of global...

Issue #3238953 by jonathan1055, omkar.podey, huzooka: Add migration of global settings from Drupal 7 to 8 
parent 19b43142
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,10 @@ build:
        # Change testgroups to '--all' if Typed Data reverts to being supported
        # at 8.x. See https://www.drupal.org/project/scheduler/issues/3248470
        suppress-deprecations: true
      run_tests.kernel:
        types: 'PHPUnit-Kernel'
        testgroups: 'scheduler_kernel'
        suppress-deprecations: true
      run_tests.js:
        types: 'PHPUnit-FunctionalJavascript'
        testgroups: 'scheduler_js'
+23 −0
Original line number Diff line number Diff line
id: d7_scheduler_settings
label: Scheduler global configuration
migration_tags:
  - Drupal 7
  - Configuration
source:
  plugin: variable
  variables:
    - scheduler_allow_date_only
    - scheduler_default_time
  source_module: scheduler
process:
  allow_date_only:
    plugin: default_value
    default_value: false
    source: scheduler_allow_date_only
  default_time:
    plugin: default_value
    default_value: '00:00:00'
    source: scheduler_default_time
destination:
  plugin: config
  config_name: scheduler.settings
+50 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * DB fixture for scheduler migration tests on top of core's fixture.
 */

use Drupal\Core\Database\Database;

$connection = Database::getConnection();

$connection->insert('system')
  ->fields([
    'filename',
    'name',
    'type',
    'owner',
    'status',
    'bootstrap',
    'schema_version',
    'weight',
    'info',
  ])
  ->values([
    'filename' => 'sites/all/modules/contrib/scheduler/scheduler.module',
    'name' => 'scheduler',
    'type' => 'module',
    'owner' => '',
    'status' => '1',
    'bootstrap' => '0',
    'schema_version' => '7103',
    'weight' => '0',
    'info' => 'a:14:{s:4:\"name\";s:9:\"Scheduler\";s:11:\"description\";s:85:\"This module allows nodes to be published and unpublished on specified dates and time.\";s:4:\"core\";s:3:\"7.x\";s:9:\"configure\";s:30:\"admin/config/content/scheduler\";s:5:\"files\";a:3:{i:0;s:47:\"scheduler_handler_field_scheduler_countdown.inc\";i:1;s:20:\"tests/scheduler.test\";i:2;s:24:\"tests/scheduler_api.test\";}s:17:\"test_dependencies\";a:2:{i:0;s:4:\"date\";i:1;s:5:\"rules\";}s:7:\"version\";s:7:\"7.x-1.6\";s:7:\"project\";s:9:\"scheduler\";s:9:\"datestamp\";s:10:\"1600171819\";s:5:\"mtime\";i:1600171819;s:12:\"dependencies\";a:0:{}s:7:\"package\";s:5:\"Other\";s:3:\"php\";s:5:\"5.2.4\";s:9:\"bootstrap\";i:0;}',
  ])
  ->execute();

$connection->insert('variable')
  ->fields([
    'name',
    'value',
  ])
  ->values([
    'name' => 'scheduler_allow_date_only',
    'value' => 'i:1;',
  ])
  ->values([
    'name' => 'scheduler_default_time',
    'value' => 's:8:"00:00:38";',
  ])
  ->execute();
+55 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\scheduler\Kernel;

use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;

/**
 * Tests the migration of Drupal 7 scheduler configuration.
 *
 * @group scheduler_kernel
 */
class MigrateSchedulerTest extends MigrateDrupal7TestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'scheduler',
    'views',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $this->loadFixture(implode(DIRECTORY_SEPARATOR, [
      DRUPAL_ROOT,
      drupal_get_path('module', 'scheduler'),
      'tests',
      'fixtures',
      'drupal7.php',
    ]));

    $this->installConfig(['scheduler']);

  }

  /**
   * Tests the migration of Scheduler global settings.
   */
  public function testGlobalSettingsMigration() {
    $config_before = $this->config('scheduler.settings');
    $this->assertFalse($config_before->get('allow_date_only'));
    $this->assertSame('00:00:00', $config_before->get('default_time'));

    $this->executeMigration('d7_scheduler_settings');

    $config_after = $this->config('scheduler.settings');
    $this->assertTrue($config_after->get('allow_date_only'));
    $this->assertSame('00:00:38', $config_after->get('default_time'));

  }

}