updated core from 8.4 to 8.5 : bug with login_destination

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-13 14:01:21 +01:00
parent 0d78da249b
commit e668535a4e
3486 changed files with 89604 additions and 33283 deletions
+1 -1
View File
@@ -18,5 +18,5 @@
/* Account settings */
.user-admin-settings .details-description {
font-size: 0.85em;
padding-bottom: .5em;
padding-bottom: 0.5em;
}
@@ -3,6 +3,7 @@ label: Profile values
class: Drupal\user\Plugin\migrate\ProfileValues
migration_tags:
- Drupal 6
- Content
source:
plugin: d6_profile_field_values
process:
@@ -1,7 +1,9 @@
id: d6_user
label: User accounts
audit: true
migration_tags:
- Drupal 6
- Content
source:
plugin: d6_user
process:
@@ -2,6 +2,7 @@ id: d6_user_contact_settings
label: User contact settings
migration_tags:
- Drupal 6
- Content
source:
plugin: d6_user
constants:
@@ -2,6 +2,7 @@ id: d6_user_mail
label: User mail configuration
migration_tags:
- Drupal 6
- Configuration
source:
plugin: variable
variables:
@@ -2,6 +2,7 @@ id: d6_user_picture_file
label: User pictures
migration_tags:
- Drupal 6
- Content
source:
plugin: d6_user_picture_file
constants:
@@ -2,6 +2,7 @@ id: d6_user_role
label: User roles
migration_tags:
- Drupal 6
- Configuration
source:
plugin: d6_user_role
process:
@@ -2,6 +2,7 @@ id: d6_user_settings
label: User configuration
migration_tags:
- Drupal 6
- Configuration
source:
plugin: variable
variables:
@@ -1,7 +1,9 @@
id: d7_user
label: User accounts
audit: true
migration_tags:
- Drupal 7
- Content
class: Drupal\user\Plugin\migrate\User
source:
plugin: d7_user
@@ -2,6 +2,7 @@ id: d7_user_flood
label: User flood configuration
migration_tags:
- Drupal 7
- Configuration
source:
plugin: variable
variables:
@@ -2,6 +2,7 @@ id: d7_user_mail
label: User mail configuration
migration_tags:
- Drupal 7
- Configuration
source:
plugin: variable
variables:
@@ -2,6 +2,7 @@ id: d7_user_role
label: User roles
migration_tags:
- Drupal 7
- Configuration
source:
plugin: d7_user_role
process:
@@ -3,6 +3,7 @@ label: User picture display configuration
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: user_picture_instance
constants:
@@ -3,6 +3,7 @@ label: User picture form display configuration
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: user_picture_instance
constants:
@@ -3,6 +3,7 @@ label: User picture field configuration
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
# We do an empty source and a proper destination to have an idmap for
# dependencies.
@@ -3,6 +3,7 @@ label: User picture field instance configuration
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: user_picture_instance
constants:
@@ -3,6 +3,7 @@ label: User profile display configuration
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: profile_field
constants:
@@ -3,6 +3,7 @@ label: User profile form display configuration
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: profile_field
constants:
@@ -3,6 +3,7 @@ label: User profile field configuration
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: profile_field
constants:
@@ -3,6 +3,7 @@ label: User profile field instance configuration
migration_tags:
- Drupal 6
- Drupal 7
- Configuration
source:
plugin: profile_field
constants:
@@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configure user settings for this site.
*
* @internal
*/
class AccountSettingsForm extends ConfigFormBase {
@@ -50,6 +50,12 @@ class CurrentUserContext implements ContextProviderInterface {
public function getRuntimeContexts(array $unqualified_context_ids) {
$current_user = $this->userStorage->load($this->account->id());
if ($current_user) {
// @todo Do not validate protected fields to avoid bug in TypedData,
// remove this in https://www.drupal.org/project/drupal/issues/2934192.
$current_user->_skipProtectedUserFieldConstraint = TRUE;
}
$context = new Context(new ContextDefinition('entity:user', $this->t('Current user')), $current_user);
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts(['user']);
+4
View File
@@ -9,6 +9,8 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\user\RoleInterface;
use Drupal\user\StatusItem;
use Drupal\user\TimeZoneItem;
use Drupal\user\UserInterface;
/**
@@ -498,11 +500,13 @@ class User extends ContentEntityBase implements UserInterface {
->addPropertyConstraints('value', [
'AllowedValues' => ['callback' => __CLASS__ . '::getAllowedTimezones'],
]);
$fields['timezone']->getItemDefinition()->setClass(TimeZoneItem::class);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('User status'))
->setDescription(t('Whether the user is active or blocked.'))
->setDefaultValue(FALSE);
$fields['status']->getItemDefinition()->setClass(StatusItem::class);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Provides a confirmation form for cancelling user account.
*
* @internal
*/
class UserCancelForm extends ContentEntityConfirmFormBase {
@@ -12,6 +12,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a user login form.
*
* @internal
*/
class UserLoginForm extends FormBase {
@@ -6,19 +6,21 @@ use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\user\UserStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a confirmation form for cancelling multiple user accounts.
*
* @internal
*/
class UserMultipleCancelConfirm extends ConfirmFormBase {
/**
* The temp store factory.
*
* @var \Drupal\user\PrivateTempStoreFactory
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
@@ -39,7 +41,7 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
/**
* Constructs a new UserMultipleCancelConfirm.
*
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The temp store factory.
* @param \Drupal\user\UserStorageInterface $user_storage
* The user storage.
@@ -57,7 +59,7 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('user.private_tempstore'),
$container->get('tempstore.private'),
$container->get('entity.manager')->getStorage('user'),
$container->get('entity.manager')
);
@@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a user password reset form.
*
* @internal
*/
class UserPasswordForm extends FormBase {
@@ -9,6 +9,8 @@ use Drupal\Core\Url;
/**
* Form controller for the user password forms.
*
* @internal
*/
class UserPasswordResetForm extends FormBase {
@@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the user permissions administration form.
*
* @internal
*/
class UserPermissionsForm extends FormBase {
@@ -127,6 +129,21 @@ class UserPermissionsForm extends FormBase {
$permissions_by_provider[$permission['provider']][$permission_name] = $permission;
}
// Move the access content permission to the Node module if it is installed.
if ($this->moduleHandler->moduleExists('node')) {
// Insert 'access content' before the 'view own unpublished content' key
// in order to maintain the UI even though the permission is provided by
// the system module.
$keys = array_keys($permissions_by_provider['node']);
$offset = (int) array_search('view own unpublished content', $keys);
$permissions_by_provider['node'] = array_merge(
array_slice($permissions_by_provider['node'], 0, $offset),
['access content' => $permissions_by_provider['system']['access content']],
array_slice($permissions_by_provider['node'], $offset)
);
unset($permissions_by_provider['system']['access content']);
}
foreach ($permissions_by_provider as $provider => $permissions) {
// Module name.
$form['permissions'][$provider] = [
@@ -7,6 +7,8 @@ use Drupal\user\RoleInterface;
/**
* Provides the user permissions administration form for a specific role.
*
* @internal
*/
class UserPermissionsRoleSpecificForm extends UserPermissionsForm {
@@ -5,7 +5,7 @@ namespace Drupal\user\Plugin\Action;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -23,7 +23,7 @@ class CancelUser extends ActionBase implements ContainerFactoryPluginInterface {
/**
* The tempstore factory.
*
* @var \Drupal\user\PrivateTempStoreFactory
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
@@ -43,7 +43,7 @@ class CancelUser extends ActionBase implements ContainerFactoryPluginInterface {
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The tempstore factory.
* @param \Drupal\Core\Session\AccountInterface $current_user
* Current user.
@@ -63,7 +63,7 @@ class CancelUser extends ActionBase implements ContainerFactoryPluginInterface {
$configuration,
$plugin_id,
$plugin_definition,
$container->get('user.private_tempstore'),
$container->get('tempstore.private'),
$container->get('current_user')
);
}
@@ -28,6 +28,7 @@ class ProfileValues extends Migration {
'ignore_map' => TRUE,
] + $this->source;
$definition['destination']['plugin'] = 'null';
$definition['idMap']['plugin'] = 'null';
try {
$profile_field_migration = $this->migrationPluginManager->createStubMigration($definition);
$source_plugin = $profile_field_migration->getSourcePlugin();
@@ -21,6 +21,7 @@ class User extends FieldMigration {
'ignore_map' => TRUE,
] + $this->source;
$definition['destination']['plugin'] = 'null';
$definition['idMap']['plugin'] = 'null';
if (\Drupal::moduleHandler()->moduleExists('field')) {
$definition['source']['plugin'] = 'd7_field_instance';
$field_migration = $this->migrationPluginManager->createStubMigration($definition);
@@ -127,4 +127,18 @@ class EntityUser extends EntityContentBase {
}
}
/**
* {@inheritdoc}
*/
public function getHighestId() {
$highest_id = parent::getHighestId();
// Every Drupal site must have a user with UID of 1 and it's normal for
// migrations to overwrite this user.
if ($highest_id === 1) {
return 0;
}
return $highest_id;
}
}
@@ -3,8 +3,8 @@
namespace Drupal\user\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\system\Plugin\views\field\BulkForm;
use Drupal\user\UserInterface;
use Drupal\views\Plugin\views\field\BulkForm;
/**
* Defines a user operations bulk form element.
@@ -74,10 +74,20 @@ class Roles extends ManyToOne {
*/
public function calculateDependencies() {
$dependencies = [];
if (in_array($this->operator, ['empty', 'not empty'])) {
return $dependencies;
}
foreach ($this->value as $role_id) {
// The value might be a string due to the wrong plugin being used for role
// field data, and subsequently the incorrect config schema object and
// value. In the empty case stop early. Otherwise we cast it to an array
// later.
if (is_string($this->value) && $this->value === '') {
return [];
}
foreach ((array) $this->value as $role_id) {
$role = $this->roleStorage->load($role_id);
$dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName();
}
+15 -202
View File
@@ -2,212 +2,25 @@
namespace Drupal\user;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\TempStore\PrivateTempStore as CorePrivateTempStore;
@trigger_error('\Drupal\user\PrivateTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStore instead. See https://www.drupal.org/node/2935639.', E_USER_DEPRECATED);
/**
* In order to preserve BC alias the core exception.
*/
if (!class_exists('\Drupal\user\TempStoreException')) {
class_alias('\Drupal\Core\TempStore\TempStoreException', '\Drupal\user\TempStoreException');
}
/**
* Stores and retrieves temporary data for a given owner.
*
* A PrivateTempStore can be used to make temporary, non-cache data available
* across requests. The data for the PrivateTempStore is stored in one
* key/value collection. PrivateTempStore data expires automatically after a
* given timeframe.
* @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
* Use \Drupal\Core\TempStore\PrivateTempStore instead.
*
* The PrivateTempStore is different from a cache, because the data in it is not
* yet saved permanently and so it cannot be rebuilt. Typically, the
* PrivateTempStore might be used to store work in progress that is later saved
* permanently elsewhere, e.g. autosave data, multistep forms, or in-progress
* changes to complex configuration that are not ready to be saved.
*
* The PrivateTempStore differs from the SharedTempStore in that all keys are
* ensured to be unique for a particular user and users can never share data. If
* you want to be able to share data between users or use it for locking, use
* \Drupal\user\SharedTempStore.
* @see \Drupal\Core\TempStore\PrivateTempStore
* @see https://www.drupal.org/node/2935639
*/
class PrivateTempStore {
/**
* The key/value storage object used for this data.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
*/
protected $storage;
/**
* The lock object used for this data.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
protected $lockBackend;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The time to live for items in seconds.
*
* By default, data is stored for one week (604800 seconds) before expiring.
*
* @var int
*/
protected $expire;
/**
* Constructs a new object for accessing data from a key/value store.
*
* @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $storage
* The key/value storage object used for this data. Each storage object
* represents a particular collection of data and will contain any number
* of key/value pairs.
* @param \Drupal\Core\Lock\LockBackendInterface $lock_backend
* The lock object used for this data.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user account.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param int $expire
* The time to live for items, in seconds.
*/
public function __construct(KeyValueStoreExpirableInterface $storage, LockBackendInterface $lock_backend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire = 604800) {
$this->storage = $storage;
$this->lockBackend = $lock_backend;
$this->currentUser = $current_user;
$this->requestStack = $request_stack;
$this->expire = $expire;
}
/**
* Retrieves a value from this PrivateTempStore for a given key.
*
* @param string $key
* The key of the data to retrieve.
*
* @return mixed
* The data associated with the key, or NULL if the key does not exist.
*/
public function get($key) {
$key = $this->createkey($key);
if (($object = $this->storage->get($key)) && ($object->owner == $this->getOwner())) {
return $object->data;
}
}
/**
* Stores a particular key/value pair in this PrivateTempStore.
*
* @param string $key
* The key of the data to store.
* @param mixed $value
* The data to store.
*
* @throws \Drupal\user\TempStoreException
* Thrown when a lock for the backend storage could not be acquired.
*/
public function set($key, $value) {
$key = $this->createkey($key);
if (!$this->lockBackend->acquire($key)) {
$this->lockBackend->wait($key);
if (!$this->lockBackend->acquire($key)) {
throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage.");
}
}
$value = (object) [
'owner' => $this->getOwner(),
'data' => $value,
'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'),
];
$this->storage->setWithExpire($key, $value, $this->expire);
$this->lockBackend->release($key);
}
/**
* Returns the metadata associated with a particular key/value pair.
*
* @param string $key
* The key of the data to store.
*
* @return mixed
* An object with the owner and updated time if the key has a value, or
* NULL otherwise.
*/
public function getMetadata($key) {
$key = $this->createkey($key);
// Fetch the key/value pair and its metadata.
$object = $this->storage->get($key);
if ($object) {
// Don't keep the data itself in memory.
unset($object->data);
return $object;
}
}
/**
* Deletes data from the store for a given key and releases the lock on it.
*
* @param string $key
* The key of the data to delete.
*
* @return bool
* TRUE if the object was deleted or does not exist, FALSE if it exists but
* is not owned by $this->owner.
*
* @throws \Drupal\user\TempStoreException
* Thrown when a lock for the backend storage could not be acquired.
*/
public function delete($key) {
$key = $this->createkey($key);
if (!$object = $this->storage->get($key)) {
return TRUE;
}
elseif ($object->owner != $this->getOwner()) {
return FALSE;
}
if (!$this->lockBackend->acquire($key)) {
$this->lockBackend->wait($key);
if (!$this->lockBackend->acquire($key)) {
throw new TempStoreException("Couldn't acquire lock to delete item '$key' from '{$this->storage->getCollectionName()}' temporary storage.");
}
}
$this->storage->delete($key);
$this->lockBackend->release($key);
return TRUE;
}
/**
* Ensures that the key is unique for a user.
*
* @param string $key
* The key.
*
* @return string
* The unique key for the user.
*/
protected function createkey($key) {
return $this->getOwner() . ':' . $key;
}
/**
* Gets the current owner based on the current user or the session ID.
*
* @return string
* The owner.
*/
protected function getOwner() {
return $this->currentUser->id() ?: $this->requestStack->getCurrentRequest()->getSession()->getId();
}
class PrivateTempStore extends CorePrivateTempStore {
}
@@ -2,72 +2,20 @@
namespace Drupal\user;
use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\TempStore\PrivateTempStoreFactory as CorePrivateTempStoreFactory;
@trigger_error('\Drupal\user\PrivateTempStoreFactory is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStoreFactory instead. See https://www.drupal.org/node/2935639.', E_USER_DEPRECATED);
/**
* Creates a PrivateTempStore object for a given collection.
*
* @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
* Use \Drupal\Core\TempStore\PrivateTempStoreFactory instead.
*
* @see \Drupal\Core\TempStore\PrivateTempStoreFactory
* @see https://www.drupal.org/node/2935639
*/
class PrivateTempStoreFactory {
/**
* The storage factory creating the backend to store the data.
*
* @var \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface
*/
protected $storageFactory;
/**
* The lock object used for this data.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
protected $lockBackend;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The time to live for items in seconds.
*
* @var int
*/
protected $expire;
/**
* Constructs a Drupal\user\PrivateTempStoreFactory object.
*
* @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $storage_factory
* The key/value store factory.
* @param \Drupal\Core\Lock\LockBackendInterface $lock_backend
* The lock object used for this data.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current account.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param int $expire
* The time to live for items, in seconds.
*/
public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire = 604800) {
$this->storageFactory = $storage_factory;
$this->lockBackend = $lock_backend;
$this->currentUser = $current_user;
$this->requestStack = $request_stack;
$this->expire = $expire;
}
class PrivateTempStoreFactory extends CorePrivateTempStoreFactory {
/**
* Creates a PrivateTempStore.
+2
View File
@@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Form handler for the profile forms.
*
* @internal
*/
class ProfileForm extends AccountForm {
+2
View File
@@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Form handler for the user register forms.
*
* @internal
*/
class RegisterForm extends AccountForm {
+2
View File
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for the role entity edit forms.
*
* @internal
*/
class RoleForm extends EntityForm {
+15 -268
View File
@@ -2,278 +2,25 @@
namespace Drupal\user;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\TempStore\SharedTempStore as CoreSharedTempStore;
@trigger_error('\Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.', E_USER_DEPRECATED);
/**
* In order to preserve BC alias the core exception.
*/
if (!class_exists('\Drupal\user\TempStoreException')) {
class_alias('\Drupal\Core\TempStore\TempStoreException', '\Drupal\user\TempStoreException');
}
/**
* Stores and retrieves temporary data for a given owner.
*
* A SharedTempStore can be used to make temporary, non-cache data available
* across requests. The data for the SharedTempStore is stored in one key/value
* collection. SharedTempStore data expires automatically after a given
* timeframe.
* @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
* Use \Drupal\Core\TempStore\SharedTempStore instead.
*
* The SharedTempStore is different from a cache, because the data in it is not
* yet saved permanently and so it cannot be rebuilt. Typically, the
* SharedTempStore might be used to store work in progress that is later saved
* permanently elsewhere, e.g. autosave data, multistep forms, or in-progress
* changes to complex configuration that are not ready to be saved.
*
* Each SharedTempStore belongs to a particular owner (e.g. a user, session, or
* process). Multiple owners may use the same key/value collection, and the
* owner is stored along with the key/value pair.
*
* Every key is unique within the collection, so the SharedTempStore can check
* whether a particular key is already set by a different owner. This is
* useful for informing one owner that the data is already in use by another;
* for example, to let one user know that another user is in the process of
* editing certain data, or even to restrict other users from editing it at
* the same time. It is the responsibility of the implementation to decide
* when and whether one owner can use or update another owner's data.
*
* If you want to be able to ensure that the data belongs to the current user,
* use \Drupal\user\PrivateTempStore.
* @see \Drupal\Core\TempStore\SharedTempStore
* @see https://www.drupal.org/node/2935639
*/
class SharedTempStore {
/**
* The key/value storage object used for this data.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
*/
protected $storage;
/**
* The lock object used for this data.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
protected $lockBackend;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The owner key to store along with the data (e.g. a user or session ID).
*
* @var mixed
*/
protected $owner;
/**
* The time to live for items in seconds.
*
* By default, data is stored for one week (604800 seconds) before expiring.
*
* @var int
*/
protected $expire;
/**
* Constructs a new object for accessing data from a key/value store.
*
* @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $storage
* The key/value storage object used for this data. Each storage object
* represents a particular collection of data and will contain any number
* of key/value pairs.
* @param \Drupal\Core\Lock\LockBackendInterface $lock_backend
* The lock object used for this data.
* @param mixed $owner
* The owner key to store along with the data (e.g. a user or session ID).
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param int $expire
* The time to live for items, in seconds.
*/
public function __construct(KeyValueStoreExpirableInterface $storage, LockBackendInterface $lock_backend, $owner, RequestStack $request_stack, $expire = 604800) {
$this->storage = $storage;
$this->lockBackend = $lock_backend;
$this->owner = $owner;
$this->requestStack = $request_stack;
$this->expire = $expire;
}
/**
* Retrieves a value from this SharedTempStore for a given key.
*
* @param string $key
* The key of the data to retrieve.
*
* @return mixed
* The data associated with the key, or NULL if the key does not exist.
*/
public function get($key) {
if ($object = $this->storage->get($key)) {
return $object->data;
}
}
/**
* Retrieves a value from this SharedTempStore for a given key.
*
* Only returns the value if the value is owned by $this->owner.
*
* @param string $key
* The key of the data to retrieve.
*
* @return mixed
* The data associated with the key, or NULL if the key does not exist.
*/
public function getIfOwner($key) {
if (($object = $this->storage->get($key)) && ($object->owner == $this->owner)) {
return $object->data;
}
}
/**
* Stores a particular key/value pair only if the key doesn't already exist.
*
* @param string $key
* The key of the data to check and store.
* @param mixed $value
* The data to store.
*
* @return bool
* TRUE if the data was set, or FALSE if it already existed.
*/
public function setIfNotExists($key, $value) {
$value = (object) [
'owner' => $this->owner,
'data' => $value,
'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'),
];
return $this->storage->setWithExpireIfNotExists($key, $value, $this->expire);
}
/**
* Stores a particular key/value pair in this SharedTempStore.
*
* Only stores the given key/value pair if it does not exist yet or is owned
* by $this->owner.
*
* @param string $key
* The key of the data to store.
* @param mixed $value
* The data to store.
*
* @return bool
* TRUE if the data was set, or FALSE if it already exists and is not owned
* by $this->user.
*
* @throws \Drupal\user\TempStoreException
* Thrown when a lock for the backend storage could not be acquired.
*/
public function setIfOwner($key, $value) {
if ($this->setIfNotExists($key, $value)) {
return TRUE;
}
if (($object = $this->storage->get($key)) && ($object->owner == $this->owner)) {
$this->set($key, $value);
return TRUE;
}
return FALSE;
}
/**
* Stores a particular key/value pair in this SharedTempStore.
*
* @param string $key
* The key of the data to store.
* @param mixed $value
* The data to store.
*
* @throws \Drupal\user\TempStoreException
* Thrown when a lock for the backend storage could not be acquired.
*/
public function set($key, $value) {
if (!$this->lockBackend->acquire($key)) {
$this->lockBackend->wait($key);
if (!$this->lockBackend->acquire($key)) {
throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage.");
}
}
$value = (object) [
'owner' => $this->owner,
'data' => $value,
'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'),
];
$this->storage->setWithExpire($key, $value, $this->expire);
$this->lockBackend->release($key);
}
/**
* Returns the metadata associated with a particular key/value pair.
*
* @param string $key
* The key of the data to store.
*
* @return mixed
* An object with the owner and updated time if the key has a value, or
* NULL otherwise.
*/
public function getMetadata($key) {
// Fetch the key/value pair and its metadata.
$object = $this->storage->get($key);
if ($object) {
// Don't keep the data itself in memory.
unset($object->data);
return $object;
}
}
/**
* Deletes data from the store for a given key and releases the lock on it.
*
* @param string $key
* The key of the data to delete.
*
* @throws \Drupal\user\TempStoreException
* Thrown when a lock for the backend storage could not be acquired.
*/
public function delete($key) {
if (!$this->lockBackend->acquire($key)) {
$this->lockBackend->wait($key);
if (!$this->lockBackend->acquire($key)) {
throw new TempStoreException("Couldn't acquire lock to delete item '$key' from {$this->storage->getCollectionName()} temporary storage.");
}
}
$this->storage->delete($key);
$this->lockBackend->release($key);
}
/**
* Deletes data from the store for a given key and releases the lock on it.
*
* Only delete the given key if it is owned by $this->owner.
*
* @param string $key
* The key of the data to delete.
*
* @return bool
* TRUE if the object was deleted or does not exist, FALSE if it exists but
* is not owned by $this->owner.
*
* @throws \Drupal\user\TempStoreException
* Thrown when a lock for the backend storage could not be acquired.
*/
public function deleteIfOwner($key) {
if (!$object = $this->storage->get($key)) {
return TRUE;
}
elseif ($object->owner == $this->owner) {
$this->delete($key);
return TRUE;
}
return FALSE;
}
class SharedTempStore extends CoreSharedTempStore {
}
@@ -2,61 +2,20 @@
namespace Drupal\user;
use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\TempStore\SharedTempStoreFactory as CoreSharedTempStoreFactory;
@trigger_error('\Drupal\user\SharedTempStoreFactory is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStoreFactory instead. See https://www.drupal.org/node/2935639.', E_USER_DEPRECATED);
/**
* Creates a shared temporary storage for a collection.
*
* @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.0.
* Use \Drupal\Core\TempStore\SharedTempStoreFactory instead.
*
* @see \Drupal\Core\TempStore\SharedTempStoreFactory
* @see https://www.drupal.org/node/2935639
*/
class SharedTempStoreFactory {
/**
* The storage factory creating the backend to store the data.
*
* @var \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface
*/
protected $storageFactory;
/**
* The lock object used for this data.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
protected $lockBackend;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The time to live for items in seconds.
*
* @var int
*/
protected $expire;
/**
* Constructs a Drupal\user\SharedTempStoreFactory object.
*
* @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $storage_factory
* The key/value store factory.
* @param \Drupal\Core\Lock\LockBackendInterface $lock_backend
* The lock object used for this data.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param int $expire
* The time to live for items, in seconds.
*/
public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, $expire = 604800) {
$this->storageFactory = $storage_factory;
$this->lockBackend = $lock_backend;
$this->requestStack = $request_stack;
$this->expire = $expire;
}
class SharedTempStoreFactory extends CoreSharedTempStoreFactory {
/**
* Creates a SharedTempStore for the current user or anonymous session.
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace Drupal\user;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\BooleanItem;
/**
* Defines the 'status' entity field type.
*
* @todo Consider making this a full field type plugin in
* https://www.drupal.org/project/drupal/issues/2936864.
*/
class StatusItem extends BooleanItem {
/**
* {@inheritdoc}
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
// Always generate a sample with an enabled status.
$values['value'] = 1;
return $values;
}
}
@@ -1,11 +0,0 @@
<?php
namespace Drupal\user;
/**
* Thrown by SharedTempStore and PrivateTempStore if they cannot acquire a lock.
*
* @see \Drupal\user\SharedTempStore
* @see \Drupal\user\PrivateTempStore
*/
class TempStoreException extends \Exception {}
@@ -2,6 +2,7 @@
namespace Drupal\user\Tests;
use Drupal\Core\Url;
use Drupal\rest\Tests\RESTTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
@@ -166,7 +167,7 @@ class RestRegisterUserTest extends RESTTestBase {
*/
protected function registerRequest($name, $include_password = TRUE) {
$serialized = $this->createSerializedUser($name, $include_password);
$this->httpRequest('/user/register', 'POST', $serialized, 'application/hal+json');
$this->httpRequest(Url::fromRoute('rest.user_registration.POST', ['_format' => 'hal_json']), 'POST', $serialized, 'application/hal+json');
}
}
@@ -118,7 +118,7 @@ class UserPasswordResetTest extends PageCacheTagsTestBase {
// invalidate the reset token.
$image = current($this->drupalGetTestFiles('image'));
$edit = [
'files[user_picture_0]' => drupal_realpath($image->uri),
'files[user_picture_0]' => \Drupal::service('file_system')->realpath($image->uri),
];
$this->drupalPostAjaxForm(NULL, $edit, 'user_picture_0_upload_button');
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace Drupal\user;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
use Drupal\user\Entity\User;
/**
* Defines a custom field item class for the 'timezone' user entity field.
*/
class TimeZoneItem extends StringItem {
/**
* {@inheritdoc}
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$timezones = User::getAllowedTimezones();
// We need to vary the selected timezones since we're generating a sample.
$key = rand(0, count($timezones) - 1);
return $timezones[$key];
}
}
@@ -0,0 +1,86 @@
<?php
namespace Drupal\user;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
/**
* ToolbarLinkBuilder fills out the placeholders generated in user_toolbar().
*/
class ToolbarLinkBuilder {
use StringTranslationTrait;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $account;
/**
* ToolbarHandler constructor.
*
* @param \Drupal\Core\Session\AccountProxyInterface $account
* The current user.
*/
public function __construct(AccountProxyInterface $account) {
$this->account = $account;
}
/**
* Lazy builder callback for rendering toolbar links.
*
* @return array
* A renderable array as expected by the renderer service.
*/
public function renderToolbarLinks() {
$links = [
'account' => [
'title' => $this->t('View profile'),
'url' => Url::fromRoute('user.page'),
'attributes' => [
'title' => $this->t('User account'),
],
],
'account_edit' => [
'title' => $this->t('Edit profile'),
'url' => Url::fromRoute('entity.user.edit_form', ['user' => $this->account->id()]),
'attributes' => [
'title' => $this->t('Edit user account'),
],
],
'logout' => [
'title' => $this->t('Log out'),
'url' => Url::fromRoute('user.logout'),
],
];
$build = [
'#theme' => 'links__toolbar_user',
'#links' => $links,
'#attributes' => [
'class' => ['toolbar-menu'],
],
'#cache' => [
'contexts' => ['user'],
],
];
return $build;
}
/**
* Lazy builder callback for rendering the username.
*
* @return array
* A renderable array as expected by the renderer service.
*/
public function renderDisplayName() {
return [
'#markup' => $this->account->getDisplayName(),
];
}
}
@@ -58,7 +58,7 @@ class UserAccessControlHandler extends EntityAccessControlHandler {
return AccessResult::allowed()->cachePerUser();
}
else {
return AccessResultNeutral::neutral("The 'access user profiles' permission is required and the user must be active.");
return AccessResultNeutral::neutral("The 'access user profiles' permission is required and the user must be active.")->cachePerPermissions()->addCacheableDependency($entity);
}
break;
+6 -10
View File
@@ -48,30 +48,26 @@ class UserData implements UserDataInterface {
}
return NULL;
}
$return = [];
// If $module and $uid were passed, return data keyed by name.
elseif (isset($uid)) {
$return = [];
if (isset($uid)) {
foreach ($result as $record) {
$return[$record->name] = ($record->serialized ? unserialize($record->value) : $record->value);
}
return $return;
}
// If $module and $name were passed, return data keyed by uid.
elseif (isset($name)) {
$return = [];
if (isset($name)) {
foreach ($result as $record) {
$return[$record->uid] = ($record->serialized ? unserialize($record->value) : $record->value);
}
return $return;
}
// If only $module was passed, return data keyed by uid and name.
else {
$return = [];
foreach ($result as $record) {
$return[$record->uid][$record->name] = ($record->serialized ? unserialize($record->value) : $record->value);
}
return $return;
foreach ($result as $record) {
$return[$record->uid][$record->name] = ($record->serialized ? unserialize($record->value) : $record->value);
}
return $return;
}
/**
+11
View File
@@ -2,6 +2,7 @@
namespace Drupal\user;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
/**
@@ -23,4 +24,14 @@ class UserNameItem extends StringItem {
return $value === NULL || $value === '';
}
/**
* {@inheritdoc}
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$values = parent::generateSampleValue($field_definition);
// User names larger than 60 characters won't pass validation.
$values['value'] = substr($values['value'], 0, UserInterface::USERNAME_MAX_LENGTH);
return $values;
}
}
+23 -6
View File
@@ -1,8 +1,25 @@
<?php
// @codingStandardsIgnoreFile
// This class is intentionally empty so that it overwrites when sites are
// updated from a zip/tarball without deleting the /core folder first.
// @todo: remove in 8.3.x
//
namespace Drupal\user;
class UserServiceProvider {}
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
class UserServiceProvider implements ServiceModifierInterface {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
if ($container->hasParameter('user.tempstore.expire')) {
@trigger_error('The container parameter "user.tempstore.expire" is deprecated. Use "tempstore.expire" instead. See https://www.drupal.org/node/2935639.', E_USER_DEPRECATED);
$container->setParameter('tempstore.expire', $container->getParameter('user.tempstore.expire'));
}
else {
// Ensure the user.tempstore.expire parameter is set to the same value
// for modules that still rely on it.
$container->setParameter('user.tempstore.expire', $container->getParameter('tempstore.expire'));
}
}
}
+12 -26
View File
@@ -220,34 +220,20 @@ class UserViewsData extends EntityViewsData {
],
];
$data['user__roles']['table']['group'] = $this->t('User');
// Alter the user roles target_id column.
$data['user__roles']['roles_target_id']['field']['id'] = 'user_roles';
$data['user__roles']['roles_target_id']['field']['no group by'] = TRUE;
$data['user__roles']['table']['join'] = [
'users_field_data' => [
'left_field' => 'uid',
'field' => 'entity_id',
],
];
$data['user__roles']['roles_target_id']['filter']['id'] = 'user_roles';
$data['user__roles']['roles_target_id']['filter']['allow empty'] = TRUE;
$data['user__roles']['roles_target_id'] = [
'title' => $this->t('Roles'),
'help' => $this->t('Roles that a user belongs to.'),
'field' => [
'id' => 'user_roles',
'no group by' => TRUE,
],
'filter' => [
'id' => 'user_roles',
'allow empty' => TRUE,
],
'argument' => [
'id' => 'user__roles_rid',
'name table' => 'role',
'name field' => 'name',
'empty field name' => $this->t('No role'),
'zero is null' => TRUE,
'numeric' => TRUE,
],
$data['user__roles']['roles_target_id']['argument'] = [
'id' => 'user__roles_rid',
'name table' => 'role',
'name field' => 'name',
'empty field name' => $this->t('No role'),
'zero is null' => TRUE,
'numeric' => TRUE,
];
$data['user__roles']['permission'] = [
@@ -5,8 +5,8 @@ package: Testing
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
@@ -5,8 +5,8 @@ package: Testing
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
@@ -5,8 +5,8 @@ package: Testing
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
@@ -5,8 +5,8 @@ package: Testing
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
@@ -8,8 +8,8 @@ dependencies:
- user
- views
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
@@ -1,15 +1,15 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests user-account links.
*
* @group user
*/
class UserAccountLinksTest extends WebTestBase {
class UserAccountLinksTest extends BrowserTestBase {
/**
* Modules to enable.
@@ -89,7 +89,7 @@ class UserAccountLinksTest extends WebTestBase {
// the consistent label text.
$this->drupalGet('admin/structure/menu/manage/account');
$label = $this->xpath('//label[contains(.,:text)]/@for', [':text' => 'Enable My account menu link']);
$this->assertFieldChecked((string) $label[0], "The 'My account' link is enabled by default.");
$this->assertFieldChecked($label[0]->getText(), "The 'My account' link is enabled by default.");
// Disable the 'My account' link.
$edit['links[menu_plugin_id:user.page][enabled]'] = FALSE;
@@ -1,8 +1,8 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\User;
/**
@@ -11,7 +11,7 @@ use Drupal\user\Entity\User;
* @group user
* @see user_admin_account()
*/
class UserAdminListingTest extends WebTestBase {
class UserAdminListingTest extends BrowserTestBase {
/**
* Tests the listing.
@@ -63,19 +63,22 @@ class UserAdminListingTest extends WebTestBase {
$result = $this->xpath('//table[contains(@class, "responsive-enabled")]/tbody/tr');
$result_accounts = [];
foreach ($result as $account) {
$name = (string) $account->td[0]->span;
$account_columns = $account->findAll('css', 'td');
$name = $account_columns[0]->getText();
$roles = [];
if (isset($account->td[2]->div->ul)) {
foreach ($account->td[2]->div->ul->li as $element) {
$roles[] = (string) $element;
$account_roles = $account_columns[2]->findAll('css', 'td div ul li');
if (!empty($account_roles)) {
foreach ($account_roles as $element) {
$roles[] = $element->getText();
}
}
$result_accounts[$name] = [
'name' => $name,
'status' => (string) $account->td[1],
'status' => $account_columns[1]->getText(),
'roles' => $roles,
'member_for' => (string) $account->td[3],
'last_access' => (string) $account->td[4],
'member_for' => $account_columns[3]->getText(),
'last_access' => $account_columns[4]->getText(),
];
}
@@ -1,8 +1,9 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\RoleInterface;
/**
@@ -10,7 +11,11 @@ use Drupal\user\RoleInterface;
*
* @group user
*/
class UserAdminTest extends WebTestBase {
class UserAdminTest extends BrowserTestBase {
use AssertMailTrait {
getMails as drupalGetMails;
}
/**
* Modules to enable.
@@ -66,12 +71,12 @@ class UserAdminTest extends WebTestBase {
$this->drupalGet('admin/people', ['query' => ['user' => $user_a->getUsername()]]);
$result = $this->xpath('//table/tbody/tr');
$this->assertEqual(1, count($result), 'Filter by username returned the right amount.');
$this->assertEqual($user_a->getUsername(), (string) $result[0]->td[1]->span, 'Filter by username returned the right user.');
$this->assertEqual($user_a->getUsername(), $result[0]->find('xpath', '/td[2]/span')->getText(), 'Filter by username returned the right user.');
$this->drupalGet('admin/people', ['query' => ['user' => $user_a->getEmail()]]);
$result = $this->xpath('//table/tbody/tr');
$this->assertEqual(1, count($result), 'Filter by username returned the right amount.');
$this->assertEqual($user_a->getUsername(), (string) $result[0]->td[1]->span, 'Filter by username returned the right user.');
$this->assertEqual($user_a->getUsername(), $result[0]->find('xpath', '/td[2]/span')->getText(), 'Filter by username returned the right user.');
// Filter the users by permission 'administer taxonomy'.
$this->drupalGet('admin/people', ['query' => ['permission' => 'administer taxonomy']]);
@@ -1,15 +1,15 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests user edit page.
*
* @group user
*/
class UserEditTest extends WebTestBase {
class UserEditTest extends BrowserTestBase {
/**
* Test user edit page.
@@ -51,7 +51,7 @@ class UserEditTest extends WebTestBase {
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
$this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", ['%name' => t('Email')]));
$edit['current_pass'] = $user1->pass_raw;
$edit['current_pass'] = $user1->passRaw;
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
$this->assertRaw(t("The changes have been saved."));
@@ -63,7 +63,7 @@ class UserEditTest extends WebTestBase {
$this->assertRaw(t("Your current password is missing or incorrect; it's required to change the %name.", ['%name' => t('Password')]));
// Try again with the current password.
$edit['current_pass'] = $user1->pass_raw;
$edit['current_pass'] = $user1->passRaw;
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
$this->assertRaw(t("The changes have been saved."));
@@ -72,7 +72,7 @@ class UserEditTest extends WebTestBase {
// Make sure the user can log in with their new password.
$this->drupalLogout();
$user1->pass_raw = $new_pass;
$user1->passRaw = $new_pass;
$this->drupalLogin($user1);
$this->drupalLogout();
@@ -11,13 +11,6 @@ use Drupal\Tests\BrowserTestBase;
*/
class UserEditedOwnAccountTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['user_form_test'];
public function testUserEditedOwnAccount() {
// Change account setting 'Who can register accounts?' to Administrators
// only.
@@ -1,9 +1,9 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests whether proper language is stored for new users and access to language
@@ -11,7 +11,7 @@ use Drupal\simpletest\WebTestBase;
*
* @group user
*/
class UserLanguageCreationTest extends WebTestBase {
class UserLanguageCreationTest extends BrowserTestBase {
/**
* Modules to enable.
@@ -86,11 +86,11 @@ class UserLanguageCreationTest extends WebTestBase {
$this->drupalGet($user_edit);
$this->assertOptionSelected("edit-preferred-langcode", $langcode, 'Language selector is accessible and correct language is selected.');
// Set pass_raw so we can log in the new user.
$user->pass_raw = $this->randomMachineName(10);
// Set passRaw so we can log in the new user.
$user->passRaw = $this->randomMachineName(10);
$edit = [
'pass[pass1]' => $user->pass_raw,
'pass[pass2]' => $user->pass_raw,
'pass[pass1]' => $user->passRaw,
'pass[pass2]' => $user->passRaw,
];
$this->drupalPostForm($user_edit, $edit, t('Save'));
@@ -1,8 +1,8 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\User;
/**
@@ -10,7 +10,7 @@ use Drupal\user\Entity\User;
*
* @group user
*/
class UserLoginTest extends WebTestBase {
class UserLoginTest extends BrowserTestBase {
/**
* Tests login with destination.
@@ -23,7 +23,7 @@ class UserLoginTest extends WebTestBase {
$user = $this->drupalCreateUser([]);
$this->drupalGet('user/login', ['query' => ['destination' => 'foo']]);
$edit = ['name' => $user->getUserName(), 'pass' => $user->pass_raw];
$edit = ['name' => $user->getUserName(), 'pass' => $user->passRaw];
$this->drupalPostForm(NULL, $edit, t('Log in'));
$this->assertUrl('foo', [], 'Redirected to the correct URL');
}
@@ -40,7 +40,7 @@ class UserLoginTest extends WebTestBase {
$user1 = $this->drupalCreateUser([]);
$incorrect_user1 = clone $user1;
$incorrect_user1->pass_raw .= 'incorrect';
$incorrect_user1->passRaw .= 'incorrect';
// Try 2 failed logins.
for ($i = 0; $i < 2; $i++) {
@@ -77,7 +77,7 @@ class UserLoginTest extends WebTestBase {
$user1 = $this->drupalCreateUser([]);
$incorrect_user1 = clone $user1;
$incorrect_user1->pass_raw .= 'incorrect';
$incorrect_user1->passRaw .= 'incorrect';
$user2 = $this->drupalCreateUser([]);
@@ -117,7 +117,7 @@ class UserLoginTest extends WebTestBase {
// Create a new user and authenticate.
$account = $this->drupalCreateUser([]);
$password = $account->pass_raw;
$password = $account->passRaw;
$this->drupalLogin($account);
$this->drupalLogout();
// Load the stored user. The password hash should reflect $default_count_log2.
@@ -132,7 +132,7 @@ class UserLoginTest extends WebTestBase {
\Drupal::service('module_installer')->install(['user_custom_phpass_params_test']);
$this->resetAll();
$account->pass_raw = $password;
$account->passRaw = $password;
$this->drupalLogin($account);
// Load the stored user, which should have a different password hash now.
$user_storage->resetCache([$account->id()]);
@@ -145,7 +145,7 @@ class UserLoginTest extends WebTestBase {
* Make an unsuccessful login attempt.
*
* @param \Drupal\user\Entity\User $account
* A user object with name and pass_raw attributes for the login attempt.
* A user object with name and passRaw attributes for the login attempt.
* @param mixed $flood_trigger
* (optional) Whether or not to expect that the flood control mechanism
* will be triggered. Defaults to NULL.
@@ -157,7 +157,7 @@ class UserLoginTest extends WebTestBase {
public function assertFailedLogin($account, $flood_trigger = NULL) {
$edit = [
'name' => $account->getUsername(),
'pass' => $account->pass_raw,
'pass' => $account->passRaw,
];
$this->drupalPostForm('user/login', $edit, t('Log in'));
$this->assertNoFieldByXPath("//input[@name='pass' and @value!='']", NULL, 'Password value attribute is blank.');
@@ -1,8 +1,8 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\RoleInterface;
use Drupal\user\Entity\Role;
@@ -12,7 +12,7 @@ use Drupal\user\Entity\Role;
*
* @group user
*/
class UserPermissionsTest extends WebTestBase {
class UserPermissionsTest extends BrowserTestBase {
/**
* User with admin privileges.
@@ -85,7 +85,8 @@ class UserPermissionsTest extends WebTestBase {
// Ensure that the admin role doesn't have any checkboxes.
$this->drupalGet('admin/people/permissions');
foreach (array_keys($this->container->get('user.permissions')->getPermissions()) as $permission) {
$this->assertNoFieldByName('administrator[' . $permission . ']');
$this->assertSession()->checkboxChecked('administrator[' . $permission . ']');
$this->assertSession()->fieldDisabled('administrator[' . $permission . ']');
}
}
@@ -164,4 +165,24 @@ class UserPermissionsTest extends WebTestBase {
$this->assertNotEqual($previous_permissions_hash, $current_permissions_hash, 'Permissions hash has changed.');
}
/**
* Verify 'access content' is listed in the correct location.
*/
public function testAccessContentPermission() {
$this->drupalLogin($this->adminUser);
// When Node is not installed the 'access content' permission is listed next
// to 'access site reports'.
$this->drupalGet('admin/people/permissions');
$next_row = $this->xpath('//tr[@data-drupal-selector=\'edit-permissions-access-content\']/following-sibling::tr[1]');
$this->assertEqual('edit-permissions-access-site-reports', $next_row[0]->getAttribute('data-drupal-selector'));
// When Node is installed the 'access content' permission is listed next to
// to 'view own unpublished content'.
\Drupal::service('module_installer')->install(['node']);
$this->drupalGet('admin/people/permissions');
$next_row = $this->xpath('//tr[@data-drupal-selector=\'edit-permissions-access-content\']/following-sibling::tr[1]');
$this->assertEqual('edit-permissions-view-own-unpublished-content', $next_row[0]->getAttribute('data-drupal-selector'));
}
}
@@ -1,17 +1,22 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\image\Entity\ImageStyle;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\file\Entity\File;
use Drupal\Tests\TestFileCreationTrait;
/**
* Tests user picture functionality.
*
* @group user
*/
class UserPictureTest extends WebTestBase {
class UserPictureTest extends BrowserTestBase {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
}
/**
* The profile to install as a basis for testing.
@@ -136,7 +141,7 @@ class UserPictureTest extends WebTestBase {
* Edits the user picture for the test user.
*/
public function saveUserPicture($image) {
$edit = ['files[user_picture_0]' => drupal_realpath($image->uri)];
$edit = ['files[user_picture_0]' => \Drupal::service('file_system')->realpath($image->uri)];
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save'));
// Load actual user data from database.
@@ -1,8 +1,8 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
@@ -11,7 +11,7 @@ use Drupal\user\RoleInterface;
*
* @group user
*/
class UserRoleAdminTest extends WebTestBase {
class UserRoleAdminTest extends BrowserTestBase {
/**
* User with admin privileges.
@@ -46,7 +46,7 @@ class UserRoleAdminTest extends WebTestBase {
$this->drupalGet('admin/people/permissions');
$tabs = $this->xpath('//ul[@class=:classes and //a[contains(., :text)]]', [
':classes' => 'tabs primary',
':text' => t('Roles'),
':text' => 'Roles',
]);
$this->assertEqual(count($tabs), 1, 'Found roles tab');
@@ -1,16 +1,16 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Set a user time zone and verify that dates are displayed in local time.
*
* @group user
*/
class UserTimeZoneTest extends WebTestBase {
class UserTimeZoneTest extends BrowserTestBase {
/**
* Modules to enable.
@@ -1,8 +1,8 @@
<?php
namespace Drupal\user\Tests;
namespace Drupal\Tests\user\Functional;
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
/**
* Tests the User Translation UI.
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\user\Plugin\views\access\Permission;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
@@ -1,8 +1,9 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\Core\Cache\Cache;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
use Drupal\user\Plugin\views\access\Role;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Views;
@@ -15,6 +16,8 @@ use Drupal\views\Views;
*/
class AccessRoleTest extends AccessTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* Views used by this test.
*
@@ -36,7 +39,7 @@ class AccessRoleTest extends AccessTestBase {
$this->container->get('router.builder')->rebuildIfNeeded();
$expected = [
'config' => ['user.role.' . $this->normalRole],
'module' => ['user'],
'module' => ['user', 'views_test_data'],
];
$this->assertIdentical($expected, $view->calculateDependencies()->getDependencies());
@@ -76,7 +79,7 @@ class AccessRoleTest extends AccessTestBase {
sort($roles);
$expected = [
'config' => $roles,
'module' => ['user'],
'module' => ['user', 'views_test_data'],
];
$this->assertIdentical($expected, $view->calculateDependencies()->getDependencies());
$this->drupalLogin($this->webUser);
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
/**
* A common test base class for the user access plugin tests.
@@ -45,8 +45,8 @@ abstract class AccessTestBase extends UserTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->drupalPlaceBlock('system_breadcrumb_block');
$this->enableViewsTestModule();
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\views\Views;
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\Core\Form\FormState;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
@@ -27,8 +27,8 @@ class ArgumentValidateTest extends UserTestBase {
*/
protected $account;
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->account = $this->drupalCreateUser();
}
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\user\Entity\User;
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
@@ -1,8 +1,8 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
@@ -27,8 +27,8 @@ class FilterPermissionUiTest extends ViewTestBase {
*/
public static $modules = ['user', 'user_test_views', 'views_ui'];
protected function setUp() {
parent::setUp(TRUE);
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
$this->enableViewsTestModule();
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\views\Views;
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\Component\Utility\Html;
use Drupal\user\Entity\User;
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\Core\Render\RenderContext;
use Drupal\views\Views;
@@ -1,9 +1,9 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
@@ -51,8 +51,8 @@ class HandlerFilterUserNameTest extends ViewTestBase {
'uid' => 'uid',
];
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\views\Views;
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
/**
* Tests the handler of the user: roles argument.
@@ -1,8 +1,8 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
@@ -26,8 +26,8 @@ class UserChangedTest extends ViewTestBase {
*/
public static $testViews = ['test_user_changed'];
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
@@ -1,6 +1,6 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\views\Views;
@@ -1,8 +1,8 @@
<?php
namespace Drupal\user\Tests\Views;
namespace Drupal\Tests\user\Functional\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\user\Entity\User;
@@ -32,8 +32,8 @@ abstract class UserTestBase extends ViewTestBase {
*/
protected $nodes = [];
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['user_test_views']);
@@ -12,7 +12,8 @@ use Drupal\Core\Database\Database;
* Tests the temporary object storage system.
*
* @group user
* @see \Drupal\Core\TempStore\TempStore.
* @group legacy
* @see \Drupal\user\SharedTempStore
*/
class TempStoreDatabaseTest extends KernelTestBase {
@@ -67,6 +68,9 @@ class TempStoreDatabaseTest extends KernelTestBase {
/**
* Tests the UserTempStore API.
*
* @expectedDeprecation \Drupal\user\SharedTempStoreFactory is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStoreFactory instead. See https://www.drupal.org/node/2935639.
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testUserTempStore() {
// Create a key/value collection.
@@ -21,6 +21,14 @@ class UserEntityTest extends KernelTestBase {
*/
public static $modules = ['system', 'user', 'field'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
}
/**
* Tests some of the methods.
*
@@ -65,4 +73,22 @@ class UserEntityTest extends KernelTestBase {
$this->assertEqual([RoleInterface::AUTHENTICATED_ID, 'test_role_two'], $user->getRoles());
}
/**
* Tests that all user fields validate properly.
*
* @see \Drupal\Core\Field\FieldItemListInterface::generateSampleItems
* @see \Drupal\Core\Field\FieldItemInterface::generateSampleValue()
* @see \Drupal\Core\Entity\FieldableEntityInterface::validate()
*/
public function testUserValidation() {
$user = User::create([]);
foreach ($user as $field_name => $field) {
if (!in_array($field_name, ['uid'])) {
$user->$field_name->generateSampleItems();
}
}
$violations = $user->validate();
$this->assertFalse((bool) $violations->count());
}
}
@@ -0,0 +1,38 @@
<?php
namespace Drupal\Tests\user\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests \Drupal\user\UserServiceProvider.
*
* @group user
* @group legacy
*/
class UserServiceProviderFallbackTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['user'];
/**
* Tests that user.tempstore.expire equals tempstore.expire if not customized.
*/
public function testUserServiceProvider() {
$this->assertEquals(1000, $this->container->getParameter('user.tempstore.expire'));
}
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
$container->setParameter('tempstore.expire', 1000);
parent::register($container);
}
}
@@ -0,0 +1,40 @@
<?php
namespace Drupal\Tests\user\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests \Drupal\user\UserServiceProvider.
*
* @group user
* @group legacy
*/
class UserServiceProviderTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['user'];
/**
* Tests that tempstore.expire is set to user.tempstore.expire.
*
* @expectedDeprecation The container parameter "user.tempstore.expire" is deprecated. Use "tempstore.expire" instead. See https://www.drupal.org/node/2935639.
*/
public function testUserServiceProvider() {
$this->assertEquals(1000, $this->container->getParameter('tempstore.expire'));
}
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
$container->setParameter('user.tempstore.expire', 1000);
parent::register($container);
}
}
@@ -11,6 +11,9 @@ use Symfony\Component\HttpFoundation\RequestStack;
/**
* @coversDefaultClass \Drupal\user\PrivateTempStore
* @group user
* @group legacy
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class PrivateTempStoreTest extends UnitTestCase {
@@ -98,6 +101,7 @@ class PrivateTempStoreTest extends UnitTestCase {
* Tests the get() method.
*
* @covers ::get
* @expectedDeprecation \Drupal\user\PrivateTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testGet() {
$this->keyValue->expects($this->at(0))
@@ -122,6 +126,7 @@ class PrivateTempStoreTest extends UnitTestCase {
* Tests the set() method with no lock available.
*
* @covers ::set
* @expectedDeprecation \Drupal\user\PrivateTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testSetWithNoLockAvailable() {
$this->lock->expects($this->at(0))
@@ -147,6 +152,7 @@ class PrivateTempStoreTest extends UnitTestCase {
* Tests a successful set() call.
*
* @covers ::set
* @expectedDeprecation \Drupal\user\PrivateTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testSet() {
$this->lock->expects($this->once())
@@ -170,6 +176,7 @@ class PrivateTempStoreTest extends UnitTestCase {
* Tests the getMetadata() method.
*
* @covers ::getMetadata
* @expectedDeprecation \Drupal\user\PrivateTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testGetMetadata() {
$this->keyValue->expects($this->at(0))
@@ -194,6 +201,7 @@ class PrivateTempStoreTest extends UnitTestCase {
* Tests the locking in the delete() method.
*
* @covers ::delete
* @expectedDeprecation \Drupal\user\PrivateTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testDeleteLocking() {
$this->keyValue->expects($this->once())
@@ -221,6 +229,7 @@ class PrivateTempStoreTest extends UnitTestCase {
* Tests the delete() method with no lock available.
*
* @covers ::delete
* @expectedDeprecation \Drupal\user\PrivateTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testDeleteWithNoLockAvailable() {
$this->keyValue->expects($this->once())
@@ -250,6 +259,7 @@ class PrivateTempStoreTest extends UnitTestCase {
* Tests the delete() method.
*
* @covers ::delete
* @expectedDeprecation \Drupal\user\PrivateTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\PrivateTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testDelete() {
$this->lock->expects($this->once())
@@ -11,6 +11,9 @@ use Symfony\Component\HttpFoundation\RequestStack;
/**
* @coversDefaultClass \Drupal\user\SharedTempStore
* @group user
* @group legacy
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class SharedTempStoreTest extends UnitTestCase {
@@ -90,6 +93,7 @@ class SharedTempStoreTest extends UnitTestCase {
/**
* @covers ::get
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testGet() {
$this->keyValue->expects($this->at(0))
@@ -109,6 +113,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the getIfOwner() method.
*
* @covers ::getIfOwner
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testGetIfOwner() {
$this->keyValue->expects($this->at(0))
@@ -133,6 +138,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the set() method with no lock available.
*
* @covers ::set
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testSetWithNoLockAvailable() {
$this->lock->expects($this->at(0))
@@ -158,6 +164,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests a successful set() call.
*
* @covers ::set
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testSet() {
$this->lock->expects($this->once())
@@ -181,6 +188,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the setIfNotExists() methods.
*
* @covers ::setIfNotExists
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testSetIfNotExists() {
$this->keyValue->expects($this->once())
@@ -195,6 +203,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the setIfOwner() method when no key exists.
*
* @covers ::setIfOwner
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testSetIfOwnerWhenNotExists() {
$this->keyValue->expects($this->once())
@@ -208,6 +217,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the setIfOwner() method when a key already exists but no object.
*
* @covers ::setIfOwner
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testSetIfOwnerNoObject() {
$this->keyValue->expects($this->once())
@@ -226,6 +236,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the setIfOwner() method with matching and non matching owners.
*
* @covers ::setIfOwner
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testSetIfOwner() {
$this->lock->expects($this->once())
@@ -250,6 +261,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the getMetadata() method.
*
* @covers ::getMetadata
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testGetMetadata() {
$this->keyValue->expects($this->at(0))
@@ -274,6 +286,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the delete() method.
*
* @covers ::delete
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testDelete() {
$this->lock->expects($this->once())
@@ -297,6 +310,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the delete() method with no lock available.
*
* @covers ::delete
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testDeleteWithNoLockAvailable() {
$this->lock->expects($this->at(0))
@@ -322,6 +336,7 @@ class SharedTempStoreTest extends UnitTestCase {
* Tests the deleteIfOwner() method.
*
* @covers ::deleteIfOwner
* @expectedDeprecation \Drupal\user\SharedTempStore is scheduled for removal in Drupal 9.0.0. Use \Drupal\Core\TempStore\SharedTempStore instead. See https://www.drupal.org/node/2935639.
*/
public function testDeleteIfOwner() {
$this->lock->expects($this->once())
@@ -3,6 +3,8 @@
namespace Drupal\Tests\user\Unit\Views\Argument;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\user\Entity\Role;
use Drupal\user\Plugin\views\argument\RolesRid;
@@ -44,23 +46,27 @@ class RolesRidTest extends UnitTestCase {
->with('label')
->will($this->returnValue('label'));
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$entity_manager->expects($this->any())
$entity_manager = new EntityManager();
$entity_type_manager = $this->getMock(EntityTypeManagerInterface::class);
$entity_type_manager->expects($this->any())
->method('getDefinition')
->with($this->equalTo('user_role'))
->will($this->returnValue($entity_type));
$entity_manager
$entity_type_manager
->expects($this->once())
->method('getStorage')
->with($this->equalTo('user_role'))
->will($this->returnValue($role_storage));
// @todo \Drupal\Core\Entity\Entity::entityType() uses a global call to
// entity_get_info(), which in turn wraps \Drupal::entityManager(). Set
// the entity manager until this is fixed.
// Set up a minimal container to satisfy Drupal\Core\Entity\Entity's
// dependency on it.
$container = new ContainerBuilder();
$container->set('entity.manager', $entity_manager);
$container->set('entity_type.manager', $entity_type_manager);
// Inject the container into entity.manager so it can defer to
// entity_type.manager.
$entity_manager->setContainer($container);
\Drupal::setContainer($container);
$roles_rid_argument = new RolesRid([], 'user__roles_rid', [], $entity_manager);
@@ -4,8 +4,8 @@ description: 'Theme for testing the available fields in user twig template'
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
+3 -3
View File
@@ -9,8 +9,8 @@ configure: user.admin_index
dependencies:
- system
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
+28 -52
View File
@@ -9,7 +9,6 @@ use Drupal\Component\Utility\Crypt;
use Drupal\Component\Render\PlainTextOutput;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Asset\AttachedAssetsInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Render\Element;
@@ -1328,41 +1327,6 @@ function user_cookie_delete($cookie_name) {
function user_toolbar() {
$user = \Drupal::currentUser();
// Add logout & user account links or login link.
$links_cache_contexts = [];
if ($user->isAuthenticated()) {
$links = [
'account' => [
'title' => t('View profile'),
'url' => Url::fromRoute('user.page'),
'attributes' => [
'title' => t('User account'),
],
],
'account_edit' => [
'title' => t('Edit profile'),
'url' => Url::fromRoute('entity.user.edit_form', ['user' => $user->id()]),
'attributes' => [
'title' => t('Edit user account'),
],
],
'logout' => [
'title' => t('Log out'),
'url' => Url::fromRoute('user.logout'),
],
];
// The "Edit user account" link is per-user.
$links_cache_contexts[] = 'user';
}
else {
$links = [
'login' => [
'title' => t('Log in'),
'url' => Url::fromRoute('user.page'),
],
];
}
$items['user'] = [
'#type' => 'toolbar_item',
'tab' => [
@@ -1374,26 +1338,12 @@ function user_toolbar() {
'class' => ['toolbar-icon', 'toolbar-icon-user'],
],
'#cache' => [
'contexts' => [
// Cacheable per user, because the current user's name is shown.
'user',
],
// Vary cache for anonymous and authenticated users.
'contexts' => ['user.roles:anonymous'],
],
],
'tray' => [
'#heading' => t('User account actions'),
'user_links' => [
'#cache' => [
// Cacheable per "authenticated or not", because the links to
// display depend on that.
'contexts' => Cache::mergeContexts(['user.roles:authenticated'], $links_cache_contexts),
],
'#theme' => 'links__toolbar_user',
'#links' => $links,
'#attributes' => [
'class' => ['toolbar-menu'],
],
],
],
'#weight' => 100,
'#attached' => [
@@ -1403,6 +1353,32 @@ function user_toolbar() {
],
];
if ($user->isAnonymous()) {
$links = [
'login' => [
'title' => t('Log in'),
'url' => Url::fromRoute('user.page'),
],
];
$items['user']['tray']['user_links'] = [
'#theme' => 'links__toolbar_user',
'#links' => $links,
'#attributes' => [
'class' => ['toolbar-menu'],
],
];
}
else {
$items['user']['tab']['#title'] = [
'#lazy_builder' => ['user.toolbar_link_builder:renderDisplayName', []],
'#create_placeholder' => TRUE,
];
$items['user']['tray']['user_links'] = [
'#lazy_builder' => ['user.toolbar_link_builder:renderToolbarLinks', []],
'#create_placeholder' => TRUE,
];
}
return $items;
}
+7 -5
View File
@@ -50,12 +50,14 @@ services:
arguments: ['@entity.manager', '@password']
user.private_tempstore:
class: Drupal\user\PrivateTempStoreFactory
arguments: ['@keyvalue.expirable', '@lock', '@current_user', '@request_stack', '%user.tempstore.expire%']
arguments: ['@keyvalue.expirable', '@lock', '@current_user', '@request_stack', '%tempstore.expire%']
deprecated: The "%service_id%" service is deprecated. You should use the 'tempstore.private' service instead. See https://www.drupal.org/node/2935639.
tags:
- { name: backend_overridable }
user.shared_tempstore:
class: Drupal\user\SharedTempStoreFactory
arguments: ['@keyvalue.expirable', '@lock', '@request_stack', '%user.tempstore.expire%']
arguments: ['@keyvalue.expirable', '@lock', '@request_stack', '%tempstore.expire%']
deprecated: The "%service_id%" service is deprecated. You should use the 'tempstore.shared' service instead. See https://www.drupal.org/node/2935639.
tags:
- { name: backend_overridable }
user.permissions:
@@ -66,6 +68,6 @@ services:
arguments: ['@current_user', '@entity.manager']
tags:
- { name: 'context_provider' }
parameters:
user.tempstore.expire: 604800
user.toolbar_link_builder:
class: Drupal\user\ToolbarLinkBuilder
arguments: ['@current_user']