Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
22
core/modules/user/tests/fixtures/update/drupal-8.user-email-token-2587275.php
vendored
Normal file
22
core/modules/user/tests/fixtures/update/drupal-8.user-email-token-2587275.php
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
|
||||
* upgrade path of https://www.drupal.org/node/2587275.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// Replace the user.mail configuration because the dump contains the right token
|
||||
// already.
|
||||
$connection->delete('config')->condition('name', 'user.mail')->execute();
|
||||
$connection->insert('config')
|
||||
->fields(array('collection', 'name', 'data'))
|
||||
->values(array(
|
||||
'collection' => '',
|
||||
'name' => 'user.mail',
|
||||
'data' => "a:10:{s:14:\"cancel_confirm\";a:2:{s:4:\"body\";s:369:\"[user:name],\n\nA request to cancel your account has been made at [site:name].\n\nYou may now cancel your account on [site:url-brief] by clicking this link or copying and pasting it into your browser:\n\n[user:cancel-url]\n\nNOTE: The cancellation of your account is not reversible.\n\nThis link expires in one day and nothing will happen if it is not used.\n\n-- [site:name] team\";s:7:\"subject\";s:59:\"Account cancellation request for [user:name] at [site:name]\";}s:14:\"password_reset\";a:2:{s:4:\"body\";s:397:\"[user:name],\n\nA request to reset the password for your account has been made at [site:name].\n\nYou may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password. It expires after one day and nothing will happen if it's not used.\n\n-- [site:name] team\";s:7:\"subject\";s:60:\"Replacement login information for [user:name] at [site:name]\";}s:22:\"register_admin_created\";a:2:{s:4:\"body\";s:463:\"[user:name],\n\nA site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team\";s:7:\"subject\";s:58:\"An administrator created an account for you at [site:name]\";}s:29:\"register_no_approval_required\";a:2:{s:4:\"body\";s:437:\"[user:name],\n\nThank you for registering at [site:name]. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team\";s:7:\"subject\";s:46:\"Account details for [user:name] at [site:name]\";}s:25:\"register_pending_approval\";a:2:{s:4:\"body\";s:281:\"[user:name],\n\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to log in, set your password, and other details.\n\n\n-- [site:name] team\";s:7:\"subject\";s:71:\"Account details for [user:name] at [site:name] (pending admin approval)\";}s:31:\"register_pending_approval_admin\";a:2:{s:4:\"body\";s:56:\"[user:name] has applied for an account.\n\n[user:edit-url]\";s:7:\"subject\";s:71:\"Account details for [user:name] at [site:name] (pending admin approval)\";}s:16:\"status_activated\";a:2:{s:4:\"body\";s:446:\"[user:name],\n\nYour account at [site:name] has been activated.\n\nYou may now log in by clicking this link or copying and pasting it into your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team\";s:7:\"subject\";s:57:\"Account details for [user:name] at [site:name] (approved)\";}s:14:\"status_blocked\";a:2:{s:4:\"body\";s:89:\"[user:name],\n\nYour account on [site:account-name] has been blocked.\n\n-- [site:name] team\";s:7:\"subject\";s:56:\"Account details for [user:name] at [site:name] (blocked)\";}s:15:\"status_canceled\";a:2:{s:4:\"body\";s:82:\"[user:name],\n\nYour account on [site:name] has been canceled.\n\n-- [site:name] team\";s:7:\"subject\";s:57:\"Account details for [user:name] at [site:name] (canceled)\";}s:8:\"langcode\";s:2:\"en\";}"
|
||||
))->execute();
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests preservation of root account password.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserAdminPassTest extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* The passwords as retrieved from the account entities before migration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $originalPasswords = [];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $modules = ['user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Make sure the admin user and a regular user are created.
|
||||
$this->container->get('module_handler')->loadInclude('user', 'install');
|
||||
$this->installEntitySchema('user');
|
||||
user_install();
|
||||
/** @var \Drupal\user\Entity\User $admin_account */
|
||||
$admin_account = User::load(1);
|
||||
$admin_account->setPassword('original');
|
||||
$admin_account->save();
|
||||
$this->originalPasswords[1] = $admin_account->getPassword();
|
||||
|
||||
/** @var \Drupal\user\Entity\User $user_account */
|
||||
$user_account = User::create([
|
||||
'uid' => 2,
|
||||
'name' => 'original_username',
|
||||
'mail' => 'original_email@example.com',
|
||||
'pass' => 'original_password',
|
||||
]);
|
||||
$user_account->save();
|
||||
$this->originalPasswords[2] = $user_account->getPassword();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests preserving the admin user's password.
|
||||
*/
|
||||
public function testAdminPasswordPreserved() {
|
||||
$user_data_rows = [
|
||||
[
|
||||
'id' => '1',
|
||||
'username' => 'site_admin',
|
||||
'password' => 'new_password',
|
||||
'email' => 'site_admin@example.com',
|
||||
],
|
||||
[
|
||||
'id' => '2',
|
||||
'username' => 'random_user',
|
||||
'password' => 'random_password',
|
||||
'email' => 'random_user@example.com',
|
||||
],
|
||||
];
|
||||
$ids = ['id' => ['type' => 'integer']];
|
||||
$definition = [
|
||||
'id' => 'users',
|
||||
'migration_tags' => ['Admin password test'],
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => $user_data_rows,
|
||||
'ids' => $ids,
|
||||
],
|
||||
'process' => [
|
||||
'uid' => 'id',
|
||||
'name' => 'username',
|
||||
'mail' => 'email',
|
||||
'pass' => 'password',
|
||||
],
|
||||
'destination' => ['plugin' => 'entity:user'],
|
||||
];
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$this->executeMigration($migration);
|
||||
|
||||
// Verify that admin username and email were changed, but password was not.
|
||||
/** @var \Drupal\user\Entity\User $admin_account */
|
||||
$admin_account = User::load(1);
|
||||
$this->assertIdentical($admin_account->getUsername(), 'site_admin');
|
||||
$this->assertIdentical($admin_account->getEmail(), 'site_admin@example.com');
|
||||
$this->assertIdentical($admin_account->getPassword(), $this->originalPasswords[1]);
|
||||
|
||||
// Verify that everything changed for the regular user.
|
||||
/** @var \Drupal\user\Entity\User $user_account */
|
||||
$user_account = User::load(2);
|
||||
$this->assertIdentical($user_account->getUsername(), 'random_user');
|
||||
$this->assertIdentical($user_account->getEmail(), 'random_user@example.com');
|
||||
$this->assertNotIdentical($user_account->getPassword(), $this->originalPasswords[2]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* User picture entity display.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserPictureEntityDisplayTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['file', 'image'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('file');
|
||||
$this->executeMigrations([
|
||||
'user_picture_field',
|
||||
'user_picture_field_instance',
|
||||
'user_picture_entity_display',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 7 user picture to Drupal 8 entity display migration.
|
||||
*/
|
||||
public function testUserPictureEntityDisplay() {
|
||||
$component = EntityViewDisplay::load('user.user.default')->getComponent('user_picture');
|
||||
$this->assertIdentical('image', $component['type']);
|
||||
$this->assertIdentical('', $component['settings']['image_style']);
|
||||
$this->assertIdentical('content', $component['settings']['image_link']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of the user_picture field's entity form display settings.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserPictureEntityFormDisplayTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['image', 'file'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigrations([
|
||||
'user_picture_field',
|
||||
'user_picture_field_instance',
|
||||
'user_picture_entity_form_display',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the field's entity form display settings.
|
||||
*/
|
||||
public function testEntityFormDisplaySettings() {
|
||||
$component = EntityFormDisplay::load('user.user.default')->getComponent('user_picture');
|
||||
$this->assertIdentical('image_image', $component['type']);
|
||||
$this->assertIdentical('throbber', $component['settings']['progress_indicator']);
|
||||
$this->assertIdentical('thumbnail', $component['settings']['preview_image_style']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\Core\Field\FieldConfigInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* User picture field instance migration.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserPictureFieldInstanceTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['image', 'file'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigrations([
|
||||
'user_picture_field',
|
||||
'user_picture_field_instance',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the user picture field migration.
|
||||
*/
|
||||
public function testUserPictureField() {
|
||||
/** @var \Drupal\field\FieldConfigInterface $field */
|
||||
$field = FieldConfig::load('user.user.user_picture');
|
||||
$this->assertTrue($field instanceof FieldConfigInterface);
|
||||
$this->assertIdentical('user', $field->getTargetEntityTypeId());
|
||||
$this->assertIdentical('user', $field->getTargetBundle());
|
||||
$this->assertIdentical('user_picture', $field->getName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* User picture field migration.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserPictureFieldTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['image', 'file'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('user_picture_field');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the user picture field migration.
|
||||
*/
|
||||
public function testUserPictureField() {
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
|
||||
$field_storage = FieldStorageConfig::load('user.user_picture');
|
||||
$this->assertTrue($field_storage instanceof FieldStorageConfigInterface);
|
||||
$this->assertIdentical('user.user_picture', $field_storage->id());
|
||||
$this->assertIdentical('image', $field_storage->getType());
|
||||
$this->assertIdentical('user', $field_storage->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the user profile entity display migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserProfileEntityDisplayTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigrations([
|
||||
'user_profile_field',
|
||||
'user_profile_field_instance',
|
||||
'user_profile_entity_display',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of user profile fields.
|
||||
*/
|
||||
public function testUserProfileFields() {
|
||||
$display = EntityViewDisplay::load('user.user.default');
|
||||
|
||||
// Test a text field.
|
||||
$component = $display->getComponent('profile_color');
|
||||
$this->assertIdentical('text_default', $component['type']);
|
||||
|
||||
// Test a list field.
|
||||
$component = $display->getComponent('profile_bands');
|
||||
$this->assertIdentical('text_default', $component['type']);
|
||||
|
||||
// Test a date field.
|
||||
$component = $display->getComponent('profile_birthdate');
|
||||
$this->assertIdentical('datetime_default', $component['type']);
|
||||
|
||||
// Test PROFILE_PRIVATE field is hidden.
|
||||
$this->assertNull($display->getComponent('profile_sell_address'));
|
||||
|
||||
// Test PROFILE_HIDDEN field is hidden.
|
||||
$this->assertNull($display->getComponent('profile_sold_to'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the user profile entity form display migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserProfileEntityFormDisplayTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigrations([
|
||||
'user_profile_field',
|
||||
'user_profile_field_instance',
|
||||
'user_profile_entity_form_display',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of user profile fields.
|
||||
*/
|
||||
public function testUserProfileEntityFormDisplay() {
|
||||
$display = EntityFormDisplay::load('user.user.default');
|
||||
|
||||
// Test a text field.
|
||||
$component = $display->getComponent('profile_color');
|
||||
$this->assertIdentical('text_textfield', $component['type']);
|
||||
|
||||
// Test a list field.
|
||||
$component = $display->getComponent('profile_bands');
|
||||
$this->assertIdentical('text_textfield', $component['type']);
|
||||
|
||||
// Test a date field.
|
||||
$component = $display->getComponent('profile_birthdate');
|
||||
$this->assertIdentical('datetime_default', $component['type']);
|
||||
|
||||
// Test PROFILE_PRIVATE field is hidden.
|
||||
$this->assertNull($display->getComponent('profile_sell_address'));
|
||||
|
||||
// Test PROFILE_HIDDEN field is hidden.
|
||||
$this->assertNull($display->getComponent('profile_sold_to'));
|
||||
|
||||
// Test that a checkbox field has the proper display label setting.
|
||||
$component = $display->getComponent('profile_love_migrations');
|
||||
$this->assertIdentical('boolean_checkbox', $component['type']);
|
||||
$this->assertIdentical(true, $component['settings']['display_label']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the user profile field instance migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserProfileFieldInstanceTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['field'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigrations([
|
||||
'user_profile_field',
|
||||
'user_profile_field_instance',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of user profile fields.
|
||||
*/
|
||||
public function testUserProfileFields() {
|
||||
// Migrated a text field.
|
||||
$field = FieldConfig::load('user.user.profile_color');
|
||||
$this->assertIdentical('Favorite color', $field->label());
|
||||
$this->assertIdentical('List your favorite color', $field->getDescription());
|
||||
|
||||
// Migrated a textarea.
|
||||
$field = FieldConfig::load('user.user.profile_biography');
|
||||
$this->assertIdentical('Biography', $field->label());
|
||||
$this->assertIdentical('Tell people a little bit about yourself', $field->getDescription());
|
||||
|
||||
// Migrated checkbox field.
|
||||
$field = FieldConfig::load('user.user.profile_sell_address');
|
||||
$this->assertIdentical('Sell your email address?', $field->label());
|
||||
$this->assertIdentical("If you check this box, we'll sell your address to spammers to help line the pockets of our shareholders. Thanks!", $field->getDescription());
|
||||
|
||||
// Migrated selection field.
|
||||
$field = FieldConfig::load('user.user.profile_sold_to');
|
||||
$this->assertIdentical('Sales Category', $field->label());
|
||||
$this->assertIdentical("Select the sales categories to which this user's address was sold.", $field->getDescription());
|
||||
|
||||
// Migrated list field.
|
||||
$field = FieldConfig::load('user.user.profile_bands');
|
||||
$this->assertIdentical('Favorite bands', $field->label());
|
||||
$this->assertIdentical("Enter your favorite bands. When you've saved your profile, you'll be able to find other people with the same favorites.", $field->getDescription());
|
||||
|
||||
// Migrated URL field.
|
||||
$field = FieldConfig::load('user.user.profile_blog');
|
||||
$this->assertIdentical('Blog', $field->label());
|
||||
$this->assertIdentical("Paste the full URL, including http://, of your personal blog.", $field->getDescription());
|
||||
|
||||
// Migrated date field.
|
||||
$field = FieldConfig::load('user.user.profile_birthdate');
|
||||
$this->assertIdentical('Birthdate', $field->label());
|
||||
$this->assertIdentical("Enter your birth date and we'll send you a coupon.", $field->getDescription());
|
||||
|
||||
// Another migrated checkbox field, with a different source visibility setting.
|
||||
$field = FieldConfig::load('user.user.profile_love_migrations');
|
||||
$this->assertIdentical('I love migrations', $field->label());
|
||||
$this->assertIdentical("If you check this box, you love migrations.", $field->getDescription());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the user profile field migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserProfileFieldTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('user_profile_field');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of user profile fields.
|
||||
*/
|
||||
public function testUserProfileFields() {
|
||||
// Migrated a text field.
|
||||
$field_storage = FieldStorageConfig::load('user.profile_color');
|
||||
$this->assertIdentical('text', $field_storage->getType(), 'Field type is text.');
|
||||
$this->assertIdentical(1, $field_storage->getCardinality(), 'Text field has correct cardinality');
|
||||
|
||||
// Migrated a textarea.
|
||||
$field_storage = FieldStorageConfig::load('user.profile_biography');
|
||||
$this->assertIdentical('text_long', $field_storage->getType(), 'Field type is text_long.');
|
||||
|
||||
// Migrated checkbox field.
|
||||
$field_storage = FieldStorageConfig::load('user.profile_sell_address');
|
||||
$this->assertIdentical('boolean', $field_storage->getType(), 'Field type is boolean.');
|
||||
|
||||
// Migrated selection field.
|
||||
$field_storage = FieldStorageConfig::load('user.profile_sold_to');
|
||||
$this->assertIdentical('list_string', $field_storage->getType(), 'Field type is list_string.');
|
||||
$settings = $field_storage->getSettings();
|
||||
$this->assertEqual($settings['allowed_values'], array(
|
||||
'Pill spammers' => 'Pill spammers',
|
||||
'Fitness spammers' => 'Fitness spammers',
|
||||
'Back\slash' => 'Back\slash',
|
||||
'Forward/slash' => 'Forward/slash',
|
||||
'Dot.in.the.middle' => 'Dot.in.the.middle',
|
||||
'Faithful servant' => 'Faithful servant',
|
||||
'Anonymous donor' => 'Anonymous donor',
|
||||
));
|
||||
$this->assertIdentical('list_string', $field_storage->getType(), 'Field type is list_string.');
|
||||
|
||||
// Migrated list field.
|
||||
$field_storage = FieldStorageConfig::load('user.profile_bands');
|
||||
$this->assertIdentical('text', $field_storage->getType(), 'Field type is text.');
|
||||
$this->assertIdentical(-1, $field_storage->getCardinality(), 'List field has correct cardinality');
|
||||
|
||||
// Migrated URL field.
|
||||
$field_storage = FieldStorageConfig::load('user.profile_blog');
|
||||
$this->assertIdentical('link', $field_storage->getType(), 'Field type is link.');
|
||||
|
||||
// Migrated date field.
|
||||
$field_storage = FieldStorageConfig::load('user.profile_birthdate');
|
||||
$this->assertIdentical('datetime', $field_storage->getType(), 'Field type is datetime.');
|
||||
$this->assertIdentical('date', $field_storage->getSettings()['datetime_type']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
use Drupal\migrate_drupal\Tests\StubTestTrait;
|
||||
|
||||
/**
|
||||
* Test stub creation for user entities.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserStubTest extends MigrateDrupalTestBase {
|
||||
|
||||
use StubTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installSchema('system', ['sequences']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creation of user stubs.
|
||||
*/
|
||||
public function testStub() {
|
||||
$this->performStubTest('user');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
use Drupal\user\AccountSettingsForm;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Upgrade variables to user.*.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserConfigsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->container->get('router.builder')->rebuild();
|
||||
$this->executeMigrations(['d6_user_mail', 'd6_user_settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of user variables to user.mail.yml.
|
||||
*/
|
||||
public function testUserMail() {
|
||||
$config = $this->config('user.mail');
|
||||
|
||||
$this->assertIdentical('Account details for [user:name] at [site:name] (approved)', $config->get('status_activated.subject'));
|
||||
$this->assertIdentical("[user:name],\n\nYour account at [site:name] has been activated.\n\nYou may now log in by clicking on this link or copying and pasting it in your browser:\n\n[user:one-time-login-url]\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.\n\nOnce you have set your own password, you will be able to log in to [site:login-url] in the future using:\n\nusername: [user:name]\n", $config->get('status_activated.body'));
|
||||
$this->assertIdentical('Replacement login information for [user:name] at [site:name]', $config->get('password_reset.subject'));
|
||||
$this->assertIdentical("[user:name],\n\nA request to reset the password for your account has been made at [site:name].\n\nYou may now log in to [site:url-brief] by clicking on this link or copying and pasting it in your browser:\n\n[user:one-time-login-url]\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password." , $config->get('password_reset.body'));
|
||||
$this->assertIdentical('Account details for [user:name] at [site:name] (deleted)', $config->get('cancel_confirm.subject'));
|
||||
$this->assertIdentical("[user:name],\n\nYour account on [site:name] has been deleted.", $config->get('cancel_confirm.body'));
|
||||
$this->assertIdentical('An administrator created an account for you at [site:name]', $config->get('register_admin_created.subject'));
|
||||
$this->assertIdentical("[user:name],\n\nA site administrator at [site:name] has created an account for you. You may now log in to [site:login-url] using the following username and password:\n\nusername: [user:name]\npassword: \n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n[user:one-time-login-url]\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.\n\n\n-- [site:name] team", $config->get('register_admin_created.body'));
|
||||
$this->assertIdentical('Account details for [user:name] at [site:name]', $config->get('register_no_approval_required.subject'));
|
||||
$this->assertIdentical("[user:name],\n\nThank you for registering at [site:name]. You may now log in to [site:login-url] using the following username and password:\n\nusername: [user:name]\npassword: \n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n[user:one-time-login-url]\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to [user:edit-url] so you can change your password.\n\n\n-- [site:name] team", $config->get('register_no_approval_required.body'));
|
||||
$this->assertIdentical('Account details for [user:name] at [site:name] (pending admin approval)', $config->get('register_pending_approval.subject'));
|
||||
$this->assertIdentical("[user:name],\n\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to log in, set your password, and other details.\n\n\n-- [site:name] team", $config->get('register_pending_approval.body'));
|
||||
$this->assertIdentical('Account details for [user:name] at [site:name] (blocked)', $config->get('status_blocked.subject'));
|
||||
$this->assertIdentical("[user:name],\n\nYour account on [site:name] has been blocked.", $config->get('status_blocked.body'));
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), 'user.mail', $config->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of user variables to user.settings.yml.
|
||||
*/
|
||||
public function testUserSettings() {
|
||||
$config = $this->config('user.settings');
|
||||
$this->assertIdentical(TRUE, $config->get('notify.status_blocked'));
|
||||
$this->assertIdentical(FALSE, $config->get('notify.status_activated'));
|
||||
$this->assertIdentical(FALSE, $config->get('verify_mail'));
|
||||
$this->assertIdentical('admin_only', $config->get('register'));
|
||||
$this->assertIdentical('Guest', $config->get('anonymous'));
|
||||
|
||||
// Tests migration of user_register using the AccountSettingsForm.
|
||||
|
||||
// Map D6 value to D8 value
|
||||
$user_register_map = [
|
||||
[0, USER_REGISTER_ADMINISTRATORS_ONLY],
|
||||
[1, USER_REGISTER_VISITORS],
|
||||
[2, USER_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('d6_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->assertIdentical($map[1], $form['registration_cancellation']['user_register']['#value']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Users contact settings migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserContactSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['contact'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->migrateUsers(FALSE);
|
||||
$this->installSchema('user', ['users_data']);
|
||||
$this->executeMigration('d6_user_contact_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal6 user contact settings migration.
|
||||
*/
|
||||
public function testUserContactSettings() {
|
||||
$user_data = \Drupal::service('user.data');
|
||||
$module = $key = 'contact';
|
||||
$uid = 2;
|
||||
$setting = $user_data->get($module, $uid, $key);
|
||||
$this->assertIdentical('1', $setting);
|
||||
|
||||
$uid = 8;
|
||||
$setting = $user_data->get($module, $uid, $key);
|
||||
$this->assertIdentical('0', $setting);
|
||||
|
||||
$uid = 15;
|
||||
$setting = $user_data->get($module, $uid, $key);
|
||||
$this->assertIdentical(NULL, $setting);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* User pictures migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserPictureFileTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('file');
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = $this->getMigration('d6_user_picture_file');
|
||||
$source = $migration->getSourceConfiguration();
|
||||
$source['site_path'] = 'core/modules/simpletest';
|
||||
$migration->set('source', $source);
|
||||
$this->executeMigration($migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 6 user pictures to Drupal 8 migration.
|
||||
*/
|
||||
public function testUserPictures() {
|
||||
$file_ids = array();
|
||||
foreach ($this->migration->getIdMap() as $destination_ids) {
|
||||
$file_ids[] = reset($destination_ids);
|
||||
}
|
||||
$files = File::loadMultiple($file_ids);
|
||||
/** @var \Drupal\file\FileInterface $file */
|
||||
$file = array_shift($files);
|
||||
$this->assertIdentical('image-test.jpg', $file->getFilename());
|
||||
$this->assertIdentical('public://image-test.jpg', $file->getFileUri());
|
||||
$this->assertIdentical('2', $file->getOwnerId());
|
||||
$this->assertIdentical('1901', $file->getSize());
|
||||
$this->assertIdentical('image/jpeg', $file->getMimeType());
|
||||
|
||||
$file = array_shift($files);
|
||||
$this->assertIdentical('image-test.png', $file->getFilename());
|
||||
$this->assertIdentical('public://image-test.png', $file->getFileUri());
|
||||
$this->assertIdentical('8', $file->getOwnerId());
|
||||
$this->assertFalse($files);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* User profile values migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserProfileValuesTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->executeMigrations([
|
||||
'user_profile_field',
|
||||
'user_profile_field_instance',
|
||||
'user_profile_entity_display',
|
||||
'user_profile_entity_form_display',
|
||||
]);
|
||||
$this->migrateUsers(FALSE);
|
||||
$this->executeMigration('d6_profile_values');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Drupal 6 profile values to Drupal 8 migration.
|
||||
*/
|
||||
public function testUserProfileValues() {
|
||||
$user = User::load(2);
|
||||
$this->assertFalse(is_null($user));
|
||||
$this->assertIdentical('red', $user->profile_color->value);
|
||||
$expected = <<<EOT
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nulla sapien, congue nec risus ut, adipiscing aliquet felis. Maecenas quis justo vel nulla varius euismod. Quisque metus metus, cursus sit amet sem non, bibendum vehicula elit. Cras dui nisl, eleifend at iaculis vitae, lacinia ut felis. Nullam aliquam ligula volutpat nulla consectetur accumsan. Maecenas tincidunt molestie diam, a accumsan enim fringilla sit amet. Morbi a tincidunt tellus. Donec imperdiet scelerisque porta. Sed quis sem bibendum eros congue sodales. Vivamus vel fermentum est, at rutrum orci. Nunc consectetur purus ut dolor pulvinar, ut volutpat felis congue. Cras tincidunt odio sed neque sollicitudin, vehicula tempor metus scelerisque.
|
||||
EOT;
|
||||
$this->assertIdentical($expected, $user->profile_biography->value);
|
||||
$this->assertIdentical('1', $user->profile_sell_address->value);
|
||||
$this->assertIdentical('Back\slash', $user->profile_sold_to->value);
|
||||
$this->assertIdentical('AC/DC', $user->profile_bands[0]->value);
|
||||
$this->assertIdentical('Eagles', $user->profile_bands[1]->value);
|
||||
$this->assertIdentical('Elton John', $user->profile_bands[2]->value);
|
||||
$this->assertIdentical('Lemonheads', $user->profile_bands[3]->value);
|
||||
$this->assertIdentical('Rolling Stones', $user->profile_bands[4]->value);
|
||||
$this->assertIdentical('Queen', $user->profile_bands[5]->value);
|
||||
$this->assertIdentical('The White Stripes', $user->profile_bands[6]->value);
|
||||
$this->assertIdentical('1974-06-02', $user->profile_birthdate->value);
|
||||
$this->assertIdentical('http://example.com/blog', $user->profile_blog->uri);
|
||||
$this->assertNull($user->profile_blog->title);
|
||||
$this->assertIdentical([], $user->profile_blog->options);
|
||||
$this->assertIdentical('http://example.com/blog', $user->profile_blog->uri);
|
||||
$this->assertNull($user->profile_love_migrations->value);
|
||||
|
||||
$user = User::load(8);
|
||||
$this->assertIdentical('Forward/slash', $user->profile_sold_to->value);
|
||||
|
||||
$user = User::load(15);
|
||||
$this->assertIdentical('Dot.in.the.middle', $user->profile_sold_to->value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade user roles to user.role.*.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserRoleTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigrations(['d6_filter_format', 'd6_user_role']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests user role migration.
|
||||
*/
|
||||
public function testUserRole() {
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$id_map = $this->getMigration('d6_user_role')->getIdMap();
|
||||
$rid = 'anonymous';
|
||||
$anonymous = Role::load($rid);
|
||||
$this->assertIdentical($rid, $anonymous->id());
|
||||
$this->assertIdentical(array('migrate test anonymous permission', 'use text format filtered_html'), $anonymous->getPermissions());
|
||||
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(1)));
|
||||
$rid = 'authenticated';
|
||||
$authenticated = Role::load($rid);
|
||||
$this->assertIdentical($rid, $authenticated->id());
|
||||
$this->assertIdentical(array('migrate test authenticated permission', 'use text format filtered_html'), $authenticated->getPermissions());
|
||||
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(2)));
|
||||
$rid = 'migrate_test_role_1';
|
||||
$migrate_test_role_1 = Role::load($rid);
|
||||
$this->assertIdentical($rid, $migrate_test_role_1->id());
|
||||
$this->assertIdentical(array('migrate test role 1 test permission', 'use text format full_html', 'use text format php_code'), $migrate_test_role_1->getPermissions());
|
||||
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(3)));
|
||||
$rid = 'migrate_test_role_2';
|
||||
$migrate_test_role_2 = Role::load($rid);
|
||||
$this->assertIdentical(array(
|
||||
'migrate test role 2 test permission',
|
||||
'use PHP for settings',
|
||||
'administer contact forms',
|
||||
'skip comment approval',
|
||||
'edit own blog content',
|
||||
'edit any blog content',
|
||||
'delete own blog content',
|
||||
'delete any blog content',
|
||||
'create forum content',
|
||||
'delete any forum content',
|
||||
'delete own forum content',
|
||||
'edit any forum content',
|
||||
'edit own forum content',
|
||||
'administer nodes',
|
||||
'access content overview',
|
||||
'use text format php_code',
|
||||
), $migrate_test_role_2->getPermissions());
|
||||
$this->assertIdentical($rid, $migrate_test_role_2->id());
|
||||
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(4)));
|
||||
$rid = 'migrate_test_role_3_that_is_long';
|
||||
$migrate_test_role_3 = Role::load($rid);
|
||||
$this->assertIdentical($rid, $migrate_test_role_3->id());
|
||||
$this->assertIdentical(array($rid), $id_map->lookupDestinationId(array(5)));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Users migration.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateUserTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('file');
|
||||
$this->installSchema('file', ['file_usage']);
|
||||
$this->installEntitySchema('node');
|
||||
$this->installSchema('user', ['users_data']);
|
||||
// Make sure uid 1 is created.
|
||||
user_install();
|
||||
|
||||
$file = File::create(array(
|
||||
'fid' => 2,
|
||||
'uid' => 2,
|
||||
'filename' => 'image-test.jpg',
|
||||
'uri' => "public://image-test.jpg",
|
||||
'filemime' => 'image/jpeg',
|
||||
'created' => 1,
|
||||
'changed' => 1,
|
||||
'status' => FILE_STATUS_PERMANENT,
|
||||
));
|
||||
$file->enforceIsNew();
|
||||
file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png'));
|
||||
$file->save();
|
||||
|
||||
$file = File::create(array(
|
||||
'fid' => 8,
|
||||
'uid' => 8,
|
||||
'filename' => 'image-test.png',
|
||||
'uri' => "public://image-test.png",
|
||||
'filemime' => 'image/png',
|
||||
'created' => 1,
|
||||
'changed' => 1,
|
||||
'status' => FILE_STATUS_PERMANENT,
|
||||
));
|
||||
$file->enforceIsNew();
|
||||
file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-2.jpg'));
|
||||
$file->save();
|
||||
|
||||
$this->migrateUsers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal6 user to Drupal 8 migration.
|
||||
*/
|
||||
public function testUser() {
|
||||
$users = Database::getConnection('default', 'migrate')
|
||||
->select('users', 'u')
|
||||
->fields('u')
|
||||
->condition('uid', 0, '>')
|
||||
->execute()
|
||||
->fetchAll();
|
||||
|
||||
foreach ($users as $source) {
|
||||
// Get roles directly from the source.
|
||||
$rids = Database::getConnection('default', 'migrate')
|
||||
->select('users_roles', 'ur')
|
||||
->fields('ur', array('rid'))
|
||||
->condition('ur.uid', $source->uid)
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$roles = array(RoleInterface::AUTHENTICATED_ID);
|
||||
$id_map = $this->getMigration('d6_user_role')->getIdMap();
|
||||
foreach ($rids as $rid) {
|
||||
$role = $id_map->lookupDestinationId(array($rid));
|
||||
$roles[] = reset($role);
|
||||
}
|
||||
|
||||
/** @var \Drupal\user\UserInterface $user */
|
||||
$user = User::load($source->uid);
|
||||
$this->assertIdentical($source->uid, $user->id());
|
||||
$this->assertIdentical($source->name, $user->label());
|
||||
$this->assertIdentical($source->mail, $user->getEmail());
|
||||
$this->assertIdentical($source->created, $user->getCreatedTime());
|
||||
$this->assertIdentical($source->access, $user->getLastAccessedTime());
|
||||
$this->assertIdentical($source->login, $user->getLastLoginTime());
|
||||
$is_blocked = $source->status == 0;
|
||||
$this->assertIdentical($is_blocked, $user->isBlocked());
|
||||
// $user->getPreferredLangcode() might fallback to default language if the
|
||||
// user preferred language is not configured on the site. We just want to
|
||||
// test if the value was imported correctly.
|
||||
$this->assertIdentical($source->language, $user->preferred_langcode->value);
|
||||
$expected_timezone_name = $source->timezone_name ?: $this->config('system.date')->get('timezone.default');
|
||||
$this->assertIdentical($expected_timezone_name, $user->getTimeZone());
|
||||
$this->assertIdentical($source->init, $user->getInitialEmail());
|
||||
$this->assertIdentical($roles, $user->getRoles());
|
||||
|
||||
// We have one empty picture in the data so don't try load that.
|
||||
if (!empty($source->picture)) {
|
||||
// Test the user picture.
|
||||
$file = File::load($user->user_picture->target_id);
|
||||
$this->assertIdentical(basename($source->picture), $file->getFilename());
|
||||
}
|
||||
else {
|
||||
// Ensure the user does not have a picture.
|
||||
$this->assertFalse($user->user_picture->target_id, sprintf('User %s does not have a picture', $user->id()));
|
||||
}
|
||||
|
||||
// Use the API to check if the password has been salted and re-hashed to
|
||||
// conform to Drupal >= 7 for non-admin users.
|
||||
if ($user->id() != 1) {
|
||||
$this->assertTrue(\Drupal::service('password')
|
||||
->check($source->pass_plain, $user->getPassword()));
|
||||
}
|
||||
}
|
||||
// Rollback the migration and make sure everything is deleted but uid 1.
|
||||
(new MigrateExecutable($this->migration, $this))->rollback();
|
||||
$users = Database::getConnection('default', 'migrate')
|
||||
->select('users', 'u')
|
||||
->fields('u', ['uid'])
|
||||
->condition('uid', 0, '>')
|
||||
->execute()
|
||||
->fetchCol();
|
||||
foreach ($users as $uid) {
|
||||
$account = User::load($uid);
|
||||
if ($uid == 1) {
|
||||
$this->assertNotNull($account, 'User 1 was preserved after rollback');
|
||||
}
|
||||
else {
|
||||
$this->assertNull($account);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Migrates user flood control configuration.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserFloodTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(['user']);
|
||||
$this->executeMigration('d7_user_flood');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$expected = [
|
||||
'uid_only' => TRUE,
|
||||
'ip_limit' => 30,
|
||||
'ip_window' => 7200,
|
||||
'user_limit' => 22,
|
||||
'user_window' => 86400,
|
||||
'_core' => [
|
||||
'default_config_hash' => 'UYfMzeP1S8jKm9PSvxf7nQNe8DsNS-3bc2WSNNXBQWs',
|
||||
],
|
||||
];
|
||||
$this->assertIdentical($expected, $this->config('user.flood')->get());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Migrates user mail configuration.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserMailTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(['user']);
|
||||
$this->executeMigration('d7_user_mail');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the migration.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$config = $this->config('user.mail');
|
||||
$this->assertIdentical('Your account is approved!', $config->get('status_activated.subject'));
|
||||
$this->assertIdentical('Your account was activated, and there was much rejoicing.', $config->get('status_activated.body'));
|
||||
$this->assertIdentical('Fix your password', $config->get('password_reset.subject'));
|
||||
$this->assertIdentical("Nope! You're locked out forever.", $config->get('password_reset.body'));
|
||||
$this->assertIdentical('So long, bub', $config->get('cancel_confirm.subject'));
|
||||
$this->assertIdentical('The gates of Drupal are closed to you. Now you will work in the salt mines.', $config->get('cancel_confirm.body'));
|
||||
$this->assertIdentical('Gawd made you an account', $config->get('register_admin_created.subject'));
|
||||
$this->assertIdentical('...and she could take it away.', $config->get('register_admin_created.body'));
|
||||
$this->assertIdentical('Welcome!', $config->get('register_no_approval_required.subject'));
|
||||
$this->assertIdentical('You can now log in if you can figure out how to use Drupal!', $config->get('register_no_approval_required.body'));
|
||||
$this->assertIdentical('Soon...', $config->get('register_pending_approval.subject'));
|
||||
$this->assertIdentical('...you will join our Circle. Let the Drupal flow through you.', $config->get('register_pending_approval.body'));
|
||||
$this->assertIdentical('BEGONE!', $config->get('status_blocked.subject'));
|
||||
$this->assertIdentical('You no longer please the robot overlords. Go to your room and chill out.', $config->get('status_blocked.body'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Upgrade user roles to user.role.*.yml.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserRoleTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d7_user_role');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts aspects of a user role config entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The role ID.
|
||||
* @param string $label
|
||||
* The role's expected label.
|
||||
* @param int|NULL $original_rid
|
||||
* The original (integer) ID of the role, to check permissions.
|
||||
*/
|
||||
protected function assertEntity($id, $label, $original_rid) {
|
||||
/** @var \Drupal\user\RoleInterface $entity */
|
||||
$entity = Role::load($id);
|
||||
$this->assertTrue($entity instanceof RoleInterface);
|
||||
$this->assertIdentical($label, $entity->label());
|
||||
|
||||
if (isset($original_rid)) {
|
||||
$permissions = Database::getConnection('default', 'migrate')
|
||||
->select('role_permission', 'rp')
|
||||
->fields('rp', ['permission'])
|
||||
->condition('rid', $original_rid)
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$this->assertIdentical($permissions, $entity->getPermissions());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests user role migration.
|
||||
*/
|
||||
public function testUserRole() {
|
||||
$this->assertEntity('anonymous', 'anonymous user', 1);
|
||||
$this->assertEntity('authenticated', 'authenticated user', 2);
|
||||
$this->assertEntity('administrator', 'administrator', 3);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Users migration.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class MigrateUserTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['file', 'image'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Prepare to migrate user pictures as well.
|
||||
$this->installEntitySchema('file');
|
||||
$this->executeMigrations([
|
||||
'user_picture_field',
|
||||
'user_picture_field_instance',
|
||||
'd7_user_role',
|
||||
'd7_user',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a user account.
|
||||
*
|
||||
* @param string $id
|
||||
* The user ID.
|
||||
* @param string $label
|
||||
* The username.
|
||||
* @param string $mail
|
||||
* The user's email address.
|
||||
* @param int $access
|
||||
* The last access time.
|
||||
* @param int $login
|
||||
* The last login time.
|
||||
* @param bool $blocked
|
||||
* Whether or not the account is blocked.
|
||||
* @param string $langcode
|
||||
* The user account's language code.
|
||||
* @param string $init
|
||||
* The user's initial email address.
|
||||
* @param string[] $roles
|
||||
* Role IDs the user account is expected to have.
|
||||
* @param bool $has_picture
|
||||
* Whether the user is expected to have a picture attached.
|
||||
*/
|
||||
protected function assertEntity($id, $label, $mail, $access, $login, $blocked, $langcode, $init, array $roles = [RoleInterface::AUTHENTICATED_ID], $has_picture = FALSE) {
|
||||
/** @var \Drupal\user\UserInterface $user */
|
||||
$user = User::load($id);
|
||||
$this->assertTrue($user instanceof UserInterface);
|
||||
$this->assertIdentical($label, $user->label());
|
||||
$this->assertIdentical($mail, $user->getEmail());
|
||||
$this->assertIdentical($access, $user->getLastAccessedTime());
|
||||
$this->assertIdentical($login, $user->getLastLoginTime());
|
||||
$this->assertIdentical($blocked, $user->isBlocked());
|
||||
// $user->getPreferredLangcode() might fallback to default language if the
|
||||
// user preferred language is not configured on the site. We just want to
|
||||
// test if the value was imported correctly.
|
||||
$this->assertIdentical($langcode, $user->langcode->value);
|
||||
$this->assertIdentical($langcode, $user->preferred_langcode->value);
|
||||
$this->assertIdentical($langcode, $user->preferred_admin_langcode->value);
|
||||
$this->assertIdentical($init, $user->getInitialEmail());
|
||||
$this->assertIdentical($roles, $user->getRoles());
|
||||
$this->assertIdentical($has_picture, !$user->user_picture->isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 7 user to Drupal 8 migration.
|
||||
*/
|
||||
public function testUser() {
|
||||
$this->assertEntity(2, 'Odo', 'odo@local.host', '0', '0', FALSE, '', 'odo@local.host');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests the user migration plugin class.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserMigrationClassTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* Tests d6_profile_values builder.
|
||||
*
|
||||
* Ensures profile fields are merged into the d6_profile_values migration's
|
||||
* process pipeline.
|
||||
*/
|
||||
public function testClass() {
|
||||
$migration = $this->getMigration('d7_user');
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
|
||||
$this->assertIdentical('d7_user', $migration->id());
|
||||
$process = $migration->getProcess();
|
||||
$this->assertIdentical('field_file', $process['field_file'][0]['source']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the permission field handler.
|
||||
*
|
||||
* @group user
|
||||
* @see \Drupal\user\Plugin\views\field\Permissions
|
||||
*/
|
||||
class HandlerFieldPermissionTest extends UserKernelTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_field_permission');
|
||||
|
||||
/**
|
||||
* Tests the permission field handler output.
|
||||
*/
|
||||
public function testFieldPermission() {
|
||||
$this->setupPermissionTestData();
|
||||
|
||||
$view = Views::getView('test_field_permission');
|
||||
$this->executeView($view);
|
||||
$view->initStyle();
|
||||
$view->render();
|
||||
$style_plugin = $view->style_plugin;
|
||||
|
||||
$expected_permissions = array();
|
||||
$expected_permissions[$this->users[0]->id()] = array();
|
||||
$expected_permissions[$this->users[1]->id()] = array();
|
||||
$expected_permissions[$this->users[2]->id()][] = t('Administer permissions');
|
||||
// View user profiles comes first, because we sort by the permission
|
||||
// machine name.
|
||||
$expected_permissions[$this->users[3]->id()][] = t('Administer permissions');
|
||||
$expected_permissions[$this->users[3]->id()][] = t('Administer users');
|
||||
$expected_permissions[$this->users[3]->id()][] = t('View user information');
|
||||
|
||||
foreach ($view->result as $index => $row) {
|
||||
$uid = $view->field['uid']->getValue($row);
|
||||
$rendered_permission = $style_plugin->getField($index, 'permission');
|
||||
|
||||
$expected_output = implode(', ', $expected_permissions[$uid]);
|
||||
$this->assertEqual($rendered_permission, $expected_output, 'The right permissions are rendered.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Views;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the permissions filter handler.
|
||||
*
|
||||
* @group user
|
||||
* @see \Drupal\user\Plugin\views\filter\Permissions
|
||||
*/
|
||||
class HandlerFilterPermissionTest extends UserKernelTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_filter_permission');
|
||||
|
||||
protected $columnMap;
|
||||
|
||||
/**
|
||||
* Tests the permission filter handler.
|
||||
*
|
||||
* @todo Fix the different commented out tests by fixing the many to one
|
||||
* handler handling with the NOT operator.
|
||||
*/
|
||||
public function testFilterPermission() {
|
||||
$this->setupPermissionTestData();
|
||||
|
||||
$column_map = array('uid' => 'uid');
|
||||
$view = Views::getView('test_filter_permission');
|
||||
|
||||
// Filter by a non existing permission.
|
||||
$view->initHandlers();
|
||||
$view->filter['permission']->value = array('non_existent_permission');
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 4, 'A non existent permission is not filtered so everything is the result.');
|
||||
$expected[] = array('uid' => 1);
|
||||
$expected[] = array('uid' => 2);
|
||||
$expected[] = array('uid' => 3);
|
||||
$expected[] = array('uid' => 4);
|
||||
$this->assertIdenticalResultset($view, $expected, $column_map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by a permission.
|
||||
$view->initHandlers();
|
||||
$view->filter['permission']->value = array('administer permissions');
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 2);
|
||||
$expected = array();
|
||||
$expected[] = array('uid' => 3);
|
||||
$expected[] = array('uid' => 4);
|
||||
$this->assertIdenticalResultset($view, $expected, $column_map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by not a permission.
|
||||
$view->initHandlers();
|
||||
$view->filter['permission']->operator = 'not';
|
||||
$view->filter['permission']->value = array('administer users');
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 3);
|
||||
$expected = array();
|
||||
$expected[] = array('uid' => 1);
|
||||
$expected[] = array('uid' => 2);
|
||||
$expected[] = array('uid' => 3);
|
||||
$this->assertIdenticalResultset($view, $expected, $column_map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by not multiple permissions, that are present in multiple roles.
|
||||
$view->initHandlers();
|
||||
$view->filter['permission']->operator = 'not';
|
||||
$view->filter['permission']->value = array('administer users', 'administer permissions');
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 2);
|
||||
$expected = array();
|
||||
$expected[] = array('uid' => 1);
|
||||
$expected[] = array('uid' => 2);
|
||||
$this->assertIdenticalResultset($view, $expected, $column_map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by another permission of a role with multiple permissions.
|
||||
$view->initHandlers();
|
||||
$view->filter['permission']->value = array('administer users');
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 1);
|
||||
$expected = array();
|
||||
$expected[] = array('uid' => 4);
|
||||
$this->assertIdenticalResultset($view, $expected, $column_map);
|
||||
$view->destroy();
|
||||
|
||||
$view->initDisplay();
|
||||
$view->initHandlers();
|
||||
|
||||
// Test the value options.
|
||||
$value_options = $view->filter['permission']->getValueOptions();
|
||||
|
||||
$permission_by_module = [];
|
||||
$permissions = \Drupal::service('user.permissions')->getPermissions();
|
||||
foreach ($permissions as $name => $permission) {
|
||||
$permission_by_module[$permission['provider']][$name] = $permission;
|
||||
}
|
||||
foreach (array('system' => 'System', 'user' => 'User') as $module => $title) {
|
||||
$expected = array_map(function ($permission) {
|
||||
return Html::escape(strip_tags($permission['title']));
|
||||
}, $permission_by_module[$module]);
|
||||
|
||||
$this->assertEqual($expected, $value_options[$title], 'Ensure the all permissions are available');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Views;
|
||||
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the roles filter handler.
|
||||
*
|
||||
* @group user
|
||||
*
|
||||
* @see \Drupal\user\Plugin\views\filter\Roles
|
||||
*/
|
||||
class HandlerFilterRolesTest extends UserKernelTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_user_name');
|
||||
|
||||
/**
|
||||
* Tests that role filter dependencies are calculated correctly.
|
||||
*/
|
||||
public function testDependencies() {
|
||||
$role = Role::create(['id' => 'test_user_role']);
|
||||
$role->save();
|
||||
$view = View::load('test_user_name');
|
||||
$expected = [
|
||||
'module' => ['user'],
|
||||
];
|
||||
$this->assertEqual($expected, $view->getDependencies());
|
||||
|
||||
$display = &$view->getDisplay('default');
|
||||
$display['display_options']['filters']['roles_target_id'] = [
|
||||
'id' => 'roles_target_id',
|
||||
'table' => 'user__roles',
|
||||
'field' => 'roles_target_id',
|
||||
'value' => [
|
||||
'test_user_role' => 'test_user_role',
|
||||
],
|
||||
'plugin_id' => 'user_roles',
|
||||
];
|
||||
$view->save();
|
||||
$expected['config'][] = 'user.role.test_user_role';
|
||||
$this->assertEqual($expected, $view->getDependencies());
|
||||
|
||||
$view = Views::getView('test_user_name');
|
||||
$view->initDisplay();
|
||||
$view->initHandlers();
|
||||
$this->assertEqual(array_keys($view->filter['roles_target_id']->getValueOptions()), ['test_user_role']);
|
||||
|
||||
$view = View::load('test_user_name');
|
||||
$display = &$view->getDisplay('default');
|
||||
$display['display_options']['filters']['roles_target_id'] = [
|
||||
'id' => 'roles_target_id',
|
||||
'table' => 'user__roles',
|
||||
'field' => 'roles_target_id',
|
||||
'value' => [],
|
||||
'plugin_id' => 'user_roles',
|
||||
];
|
||||
$view->save();
|
||||
unset($expected['config']);
|
||||
$this->assertEqual($expected, $view->getDependencies());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Views;
|
||||
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
* Provides a common test base for user views tests.
|
||||
*/
|
||||
abstract class UserKernelTestBase extends ViewsKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user_test_views', 'user', 'system', 'field');
|
||||
|
||||
/**
|
||||
* Users to use during this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $users = array();
|
||||
|
||||
/**
|
||||
* The entity storage for roles.
|
||||
*
|
||||
* @var \Drupal\user\RoleStorage
|
||||
*/
|
||||
protected $roleStorage;
|
||||
|
||||
/**
|
||||
* The entity storage for users.
|
||||
*
|
||||
* @var \Drupal\user\UserStorage
|
||||
*/
|
||||
protected $userStorage;
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp();
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('user_test_views'));
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
$entity_manager = $this->container->get('entity.manager');
|
||||
$this->roleStorage = $entity_manager->getStorage('user_role');
|
||||
$this->userStorage = $entity_manager->getStorage('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set some test data for permission related tests.
|
||||
*/
|
||||
protected function setupPermissionTestData() {
|
||||
// Setup a role without any permission.
|
||||
$this->roleStorage->create(array('id' => 'authenticated'))
|
||||
->save();
|
||||
$this->roleStorage->create(array('id' => 'no_permission'))
|
||||
->save();
|
||||
// Setup a role with just one permission.
|
||||
$this->roleStorage->create(array('id' => 'one_permission'))
|
||||
->save();
|
||||
user_role_grant_permissions('one_permission', array('administer permissions'));
|
||||
// Setup a role with multiple permissions.
|
||||
$this->roleStorage->create(array('id' => 'multiple_permissions'))
|
||||
->save();
|
||||
user_role_grant_permissions('multiple_permissions', array('administer permissions', 'administer users', 'access user profiles'));
|
||||
|
||||
// Setup a user without an extra role.
|
||||
$this->users[] = $account = $this->userStorage->create(['name' => $this->randomString()]);
|
||||
$account->save();
|
||||
// Setup a user with just the first role (so no permission beside the
|
||||
// ones from the authenticated role).
|
||||
$this->users[] = $account = $this->userStorage->create(array('name' => 'first_role'));
|
||||
$account->addRole('no_permission');
|
||||
$account->save();
|
||||
// Setup a user with just the second role (so one additional permission).
|
||||
$this->users[] = $account = $this->userStorage->create(array('name' => 'second_role'));
|
||||
$account->addRole('one_permission');
|
||||
$account->save();
|
||||
// Setup a user with both the second and the third role.
|
||||
$this->users[] = $account = $this->userStorage->create(array('name' => 'second_third_role'));
|
||||
$account->addRole('one_permission');
|
||||
$account->addRole('multiple_permissions');
|
||||
$account->save();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\user\Kernel\Views;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase;
|
||||
|
||||
/**
|
||||
* Tests base field access in Views for the user entity.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserViewsFieldAccessTest extends FieldFieldAccessTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['user', 'entity_test', 'language'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
}
|
||||
|
||||
public function testUserFields() {
|
||||
ConfigurableLanguage::create([
|
||||
'id' => 'es',
|
||||
'name' => 'Spanish',
|
||||
])->save();
|
||||
ConfigurableLanguage::create([
|
||||
'id' => 'fr',
|
||||
'name' => 'French',
|
||||
])->save();
|
||||
|
||||
$user = User::create([
|
||||
'name' => 'test user',
|
||||
'mail' => 'druplicon@drop.org',
|
||||
'status' => 1,
|
||||
'preferred_langcode' => 'es',
|
||||
'preferred_admin_langcode' => 'fr',
|
||||
'timezone' => 'ut1',
|
||||
'created' => 123456,
|
||||
]);
|
||||
|
||||
$user->save();
|
||||
|
||||
// @todo Expand the test coverage in https://www.drupal.org/node/2464635
|
||||
|
||||
$this->assertFieldAccess('user', 'uid', $user->id());
|
||||
$this->assertFieldAccess('user', 'uuid', $user->uuid());
|
||||
$this->assertFieldAccess('user', 'langcode', $user->language()->getName());
|
||||
$this->assertFieldAccess('user', 'preferred_langcode', 'Spanish');
|
||||
$this->assertFieldAccess('user', 'preferred_admin_langcode', 'French');
|
||||
$this->assertFieldAccess('user', 'name', 'test user');
|
||||
// $this->assertFieldAccess('user', 'mail', 'druplicon@drop.org');
|
||||
$this->assertFieldAccess('user', 'timezone', 'ut1');
|
||||
$this->assertFieldAccess('user', 'status', 'On');
|
||||
// $this->assertFieldAccess('user', 'created', \Drupal::service('date.formatter')->format(123456));
|
||||
// $this->assertFieldAccess('user', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Menu\UserLocalTasksTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Menu;
|
||||
|
||||
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Migrate\ProfileFieldTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Migrate;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Migrate\UserPictureInstanceTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Migrate;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Migrate\d6\ProfileFieldValuesTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Migrate\d6\RoleTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Migrate\d6\UserPictureFileTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Migrate\d6\UserPictureTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Migrate\d6\UserTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\PermissionAccessCheckTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
|
|
@ -113,6 +113,9 @@ class PermissionHandlerTest extends UnitTestCase {
|
|||
"'access module b':
|
||||
title: 'Access B'
|
||||
description: 'bla bla'
|
||||
'access module a via module b':
|
||||
title: 'Access A via B'
|
||||
provider: 'module_a'
|
||||
");
|
||||
mkdir($url . '/module_c');
|
||||
file_put_contents($url . '/module_c/module_c.permissions.yml',
|
||||
|
@ -239,6 +242,7 @@ access_module_a1: single_description1"
|
|||
file_put_contents($url . '/module_b/module_b.permissions.yml',
|
||||
"permission_callbacks:
|
||||
- 'Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription'
|
||||
- 'Drupal\\user\\Tests\\TestPermissionCallbacks::titleProvider'
|
||||
");
|
||||
mkdir($url . '/module_c');
|
||||
file_put_contents($url . '/module_c/module_c.permissions.yml',
|
||||
|
@ -271,6 +275,10 @@ access_module_a1: single_description1"
|
|||
->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription')
|
||||
->willReturn(array(new TestPermissionCallbacks(), 'titleDescription'));
|
||||
$this->controllerResolver->expects($this->at(2))
|
||||
->method('getControllerFromDefinition')
|
||||
->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleProvider')
|
||||
->willReturn(array(new TestPermissionCallbacks(), 'titleProvider'));
|
||||
$this->controllerResolver->expects($this->at(3))
|
||||
->method('getControllerFromDefinition')
|
||||
->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescriptionRestrictAccess')
|
||||
->willReturn(array(new TestPermissionCallbacks(), 'titleDescriptionRestrictAccess'));
|
||||
|
@ -351,7 +359,7 @@ permission_callbacks:
|
|||
* The actual permissions
|
||||
*/
|
||||
protected function assertPermissions(array $actual_permissions) {
|
||||
$this->assertCount(3, $actual_permissions);
|
||||
$this->assertCount(4, $actual_permissions);
|
||||
$this->assertEquals($actual_permissions['access_module_a']['title'], 'single_description');
|
||||
$this->assertEquals($actual_permissions['access_module_a']['provider'], 'module_a');
|
||||
$this->assertEquals($actual_permissions['access module b']['title'], 'Access B');
|
||||
|
@ -359,6 +367,7 @@ permission_callbacks:
|
|||
$this->assertEquals($actual_permissions['access_module_c']['title'], 'Access C');
|
||||
$this->assertEquals($actual_permissions['access_module_c']['provider'], 'module_c');
|
||||
$this->assertEquals($actual_permissions['access_module_c']['restrict access'], TRUE);
|
||||
$this->assertEquals($actual_permissions['access module a via module b']['provider'], 'module_a');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -409,6 +418,14 @@ class TestPermissionCallbacks {
|
|||
);
|
||||
}
|
||||
|
||||
public function titleProvider() {
|
||||
return array(
|
||||
'access module a via module b' => array(
|
||||
'title' => 'Access A via B',
|
||||
'provider' => 'module_a',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\Action\AddRoleUserTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\Action;
|
||||
|
||||
use Drupal\user\Plugin\Action\AddRoleUser;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\Action\RemoveRoleUserTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\Action;
|
||||
|
||||
use Drupal\user\Plugin\Action\RemoveRoleUser;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\Action\RoleUserTestBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\Action;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\Core\Entity\UserTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\Core\Entity;
|
||||
|
||||
use Drupal\Tests\Core\Session\UserSessionTest;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidatorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\Validation\Constraint;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\migrate\process\ConvertTokensTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\migrate\process;
|
||||
|
||||
use Drupal\user\Plugin\migrate\process\ConvertTokens;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\migrate\source\d7\RoleTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\migrate\source\d7\UserTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Plugin\views\field\UserBulkFormTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\PrivateTempStoreTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\SharedTempStoreTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\UserAccessControlHandlerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\UserAuthTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\user\Unit\Views\Argument\RolesRidTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\user\Unit\Views\Argument;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
|
Reference in a new issue