Unverified Commit c016a7dc authored by alexpott's avatar alexpott

Issue #3187320 by Wim Leers, shreyakaushik11, huzooka, quietone: Migrate Drupal 7 user settings

(cherry picked from commit 5e8e2edb)
parent 24f3a949
id: d7_user_settings
label: User configuration
migration_tags:
- Drupal 7
- Configuration
source:
plugin: variable
variables:
- user_mail_status_blocked_notify
- user_mail_status_activated_notify
- user_email_verification
- user_register
- anonymous
source_module: user
process:
'notify/status_blocked': user_mail_status_blocked_notify
'notify/status_activated': user_mail_status_activated_notify
verify_mail: user_email_verification
register:
plugin: static_map
source: user_register
default_value: visitors_admin_approval
map:
2: visitors_admin_approval
1: visitors
0: admin_only
anonymous: anonymous
destination:
plugin: config
config_name: user.settings
<?php
namespace Drupal\Tests\user\Kernel\Migrate\d7;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\user\AccountSettingsForm;
use Drupal\Core\Database\Database;
use Drupal\user\UserInterface;
/**
* Tests migration of user settings.
*
* @group migrate_drupal_7
*/
class MigrateUserSettingsTest extends MigrateDrupal7TestBase {
use SchemaCheckTestTrait;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->executeMigrations(['d7_user_settings']);
}
/**
* Tests the migration.
*/
public function testMigration() {
$config = $this->config('user.settings');
$this->assertTrue($config->get('notify.status_blocked'));
$this->assertTrue($config->get('notify.status_activated'));
$this->assertTrue($config->get('verify_mail'));
$this->assertSame(UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL, $config->get('register'));
$this->assertSame('Anonymous', $config->get('anonymous'));
// Tests migration of user_register using the AccountSettingsForm.
// Map source values to destination values.
$user_register_map = [
[0, UserInterface::REGISTER_ADMINISTRATORS_ONLY],
[1, UserInterface::REGISTER_VISITORS],
[2, UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL],
];
foreach ($user_register_map as $map) {
// Tests migration of user_register = 1.
Database::getConnection('default', 'migrate')
->update('variable')
->fields(['value' => serialize($map[0])])
->condition('name', 'user_register')
->execute();
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = $this->getMigration('d7_user_settings');
// Indicate we're rerunning a migration that's already run.
$migration->getIdMap()->prepareUpdate();
$this->executeMigration($migration);
$form = $this->container->get('form_builder')->getForm(AccountSettingsForm::create($this->container));
$this->assertSame($map[1], $form['registration_cancellation']['user_register']['#value']);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment