MigrateUserSettingsTest.php in Drupal 9
File
core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserSettingsTest.php
View source
<?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;
class MigrateUserSettingsTest extends MigrateDrupal7TestBase {
use SchemaCheckTestTrait;
protected function setUp() : void {
parent::setUp();
$this
->executeMigrations([
'd7_user_settings',
]);
}
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'));
$user_register_map = [
[
0,
UserInterface::REGISTER_ADMINISTRATORS_ONLY,
],
[
1,
UserInterface::REGISTER_VISITORS,
],
[
2,
UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL,
],
];
foreach ($user_register_map as $map) {
Database::getConnection('default', 'migrate')
->update('variable')
->fields([
'value' => serialize($map[0]),
])
->condition('name', 'user_register')
->execute();
$migration = $this
->getMigration('d7_user_settings');
$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']);
}
}
}