updated core
This commit is contained in:
@@ -45,7 +45,7 @@ class CancelUser extends ActionBase implements ContainerFactoryPluginInterface {
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
|
||||
* The tempstore factory.
|
||||
* @param AccountInterface $current_user
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* Current user.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
|
||||
|
||||
@@ -67,11 +67,11 @@ class UserSearch extends SearchPluginBase implements AccessibleInterface {
|
||||
/**
|
||||
* Creates a UserSearch object.
|
||||
*
|
||||
* @param Connection $database
|
||||
* @param \Drupal\Core\Database\Connection $database
|
||||
* The database connection.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param ModuleHandlerInterface $module_handler
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* The current user.
|
||||
|
||||
@@ -39,7 +39,7 @@ class EntityUser extends EntityContentBase {
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration.
|
||||
* @param EntityStorageInterface $storage
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
|
||||
* The storage for this entity type.
|
||||
* @param array $bundles
|
||||
* The list of bundles this entity type has.
|
||||
|
||||
@@ -21,6 +21,8 @@ class Users extends WizardPluginBase {
|
||||
|
||||
/**
|
||||
* Set the created column.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $createdColumn = 'created';
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class PrivateTempStore {
|
||||
/**
|
||||
* Constructs a new object for accessing data from a key/value store.
|
||||
*
|
||||
* @param KeyValueStoreExpirableInterface $storage
|
||||
* @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.
|
||||
|
||||
@@ -77,7 +77,7 @@ class SharedTempStore {
|
||||
/**
|
||||
* Constructs a new object for accessing data from a key/value store.
|
||||
*
|
||||
* @param KeyValueStoreExpirableInterface $storage
|
||||
* @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.
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests user email token upgrade path.
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class UserUpdateEmailToken extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../tests/fixtures/update/drupal-8.user-email-token-2587275.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that email token in status_blocked of user.mail is updated.
|
||||
*/
|
||||
public function testEmailToken() {
|
||||
$mail = \Drupal::config('user.mail')->get('status_blocked');
|
||||
$this->assertTrue(strpos($mail['body'], '[site:account-name]'));
|
||||
$this->runUpdates();
|
||||
$mail = \Drupal::config('user.mail')->get('status_blocked');
|
||||
$this->assertFalse(strpos($mail['body'], '[site:account-name]'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Tests user permissions sort upgrade path.
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class UserUpdateOrderPermissionsTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that permissions are ordered by machine name.
|
||||
*/
|
||||
public function testPermissionsOrder() {
|
||||
$authenticated = Role::load('authenticated');
|
||||
$permissions = $authenticated->getPermissions();
|
||||
sort($permissions);
|
||||
$this->assertNotIdentical($permissions, $authenticated->getPermissions());
|
||||
|
||||
$this->runUpdates();
|
||||
$authenticated = Role::load('authenticated');
|
||||
$this->assertIdentical($permissions, $authenticated->getPermissions());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the User entity's cache tags.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserCacheTagsTest extends EntityWithUriCacheTagsTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('user');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Give anonymous users permission to view user profiles, so that we can
|
||||
// verify the cache tags of cached versions of user profile pages.
|
||||
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
|
||||
$user_role->grantPermission('access user profiles');
|
||||
$user_role->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
// Create a "Llama" user.
|
||||
$user = User::create([
|
||||
'name' => 'Llama',
|
||||
'status' => TRUE,
|
||||
]);
|
||||
$user->save();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAdditionalCacheTagsForEntityListing() {
|
||||
return ['user:0', 'user:1'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,597 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\comment\CommentInterface;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Ensure that account cancellation methods work as expected.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserCancelTest extends WebTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'comment');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to cancel account without permission.
|
||||
*/
|
||||
function testUserCancelWithoutPermission() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->assertNoRaw(t('Cancel account'), 'No cancel account button displayed.');
|
||||
|
||||
// Attempt bogus account cancellation request confirmation.
|
||||
$timestamp = $account->getLastLoginTime();
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$this->assertResponse(403, 'Bogus cancelling request rejected.');
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isActive(), 'User account was not canceled.');
|
||||
|
||||
// Confirm user's content has not been altered.
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$test_node = $node_storage->load($node->id());
|
||||
$this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ability to change the permission for canceling users.
|
||||
*/
|
||||
public function testUserCancelChangePermission() {
|
||||
\Drupal::service('module_installer')->install(array('user_form_test'));
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
|
||||
// Create a regular user.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('cancel other accounts'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Delete regular user.
|
||||
$this->drupalPostForm('user_form_test_cancel/' . $account->id(), array(), t('Cancel account'));
|
||||
|
||||
// Confirm deletion.
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
|
||||
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that user account for uid 1 cannot be cancelled.
|
||||
*
|
||||
* This should never be possible, or the site owner would become unable to
|
||||
* administer the site.
|
||||
*/
|
||||
function testUserCancelUid1() {
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
\Drupal::service('module_installer')->install(array('views'));
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
// Update uid 1's name and password to we know it.
|
||||
$password = user_password();
|
||||
$account = array(
|
||||
'name' => 'user1',
|
||||
'pass' => $this->container->get('password')->hash(trim($password)),
|
||||
);
|
||||
// We cannot use $account->save() here, because this would result in the
|
||||
// password being hashed again.
|
||||
db_update('users_field_data')
|
||||
->fields($account)
|
||||
->condition('uid', 1)
|
||||
->execute();
|
||||
|
||||
// Reload and log in uid 1.
|
||||
$user_storage->resetCache(array(1));
|
||||
$user1 = $user_storage->load(1);
|
||||
$user1->pass_raw = $password;
|
||||
|
||||
// Try to cancel uid 1's account with a different user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array(
|
||||
'action' => 'user_cancel_user_action',
|
||||
'user_bulk_form[0]' => TRUE,
|
||||
);
|
||||
$this->drupalPostForm('admin/people', $edit, t('Apply'));
|
||||
|
||||
// Verify that uid 1's account was not cancelled.
|
||||
$user_storage->resetCache(array(1));
|
||||
$user1 = $user_storage->load(1);
|
||||
$this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt invalid account cancellations.
|
||||
*/
|
||||
function testUserCancelInvalid() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account'));
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalPostForm('user/' . $account->id() . '/edit', NULL, t('Cancel account'));
|
||||
|
||||
// Confirm account cancellation.
|
||||
$timestamp = time();
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
|
||||
|
||||
// Attempt bogus account cancellation request confirmation.
|
||||
$bogus_timestamp = $timestamp + 60;
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account, $bogus_timestamp));
|
||||
$this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Bogus cancelling request rejected.');
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isActive(), 'User account was not canceled.');
|
||||
|
||||
// Attempt expired account cancellation request confirmation.
|
||||
$bogus_timestamp = $timestamp - 86400 - 60;
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account, $bogus_timestamp));
|
||||
$this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Expired cancel account request rejected.');
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isActive(), 'User account was not canceled.');
|
||||
|
||||
// Confirm user's content has not been altered.
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$test_node = $node_storage->load($node->id());
|
||||
$this->assertTrue(($test_node->getOwnerId() == $account->id() && $test_node->isPublished()), 'Node of the user has not been altered.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable account and keep all content.
|
||||
*/
|
||||
function testUserBlock() {
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_block')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$web_user = $this->drupalCreateUser(array('cancel account'));
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($web_user->id()));
|
||||
$account = $user_storage->load($web_user->id());
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertText(t('Your account will be blocked and you will no longer be able to log in. All of your content will remain attributed to your username.'), 'Informs that all content will be remain as is.');
|
||||
$this->assertNoText(t('Select the method to cancel the account above.'), 'Does not allow user to select account cancellation method.');
|
||||
|
||||
// Confirm account cancellation.
|
||||
$timestamp = time();
|
||||
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
|
||||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isBlocked(), 'User has been blocked.');
|
||||
|
||||
// Confirm that the confirmation message made it through to the end user.
|
||||
$this->assertRaw(t('%name has been disabled.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable account and unpublish all content.
|
||||
*/
|
||||
function testUserBlockUnpublish() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_block_unpublish')->save();
|
||||
// Create comment field on page.
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account'));
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a node with two revisions.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$settings = get_object_vars($node);
|
||||
$settings['revision'] = 1;
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Add a comment to the page.
|
||||
$comment_subject = $this->randomMachineName(8);
|
||||
$comment_body = $this->randomMachineName(8);
|
||||
$comment = Comment::create(array(
|
||||
'subject' => $comment_subject,
|
||||
'comment_body' => $comment_body,
|
||||
'entity_id' => $node->id(),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'status' => CommentInterface::PUBLISHED,
|
||||
'uid' => $account->id(),
|
||||
));
|
||||
$comment->save();
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertText(t('Your account will be blocked and you will no longer be able to log in. All of your content will be hidden from everyone but administrators.'), 'Informs that all content will be unpublished.');
|
||||
|
||||
// Confirm account cancellation.
|
||||
$timestamp = time();
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
|
||||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
$this->assertTrue($account->isBlocked(), 'User has been blocked.');
|
||||
|
||||
// Confirm user's content has been unpublished.
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$test_node = $node_storage->load($node->id());
|
||||
$this->assertFalse($test_node->isPublished(), 'Node of the user has been unpublished.');
|
||||
$test_node = node_revision_load($node->getRevisionId());
|
||||
$this->assertFalse($test_node->isPublished(), 'Node revision of the user has been unpublished.');
|
||||
|
||||
$storage = \Drupal::entityManager()->getStorage('comment');
|
||||
$storage->resetCache(array($comment->id()));
|
||||
$comment = $storage->load($comment->id());
|
||||
$this->assertFalse($comment->isPublished(), 'Comment of the user has been unpublished.');
|
||||
|
||||
// Confirm that the confirmation message made it through to the end user.
|
||||
$this->assertRaw(t('%name has been disabled.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete account and anonymize all content.
|
||||
*/
|
||||
function testUserAnonymize() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
// Create comment field on page.
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account'));
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a simple node.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
|
||||
// Add a comment to the page.
|
||||
$comment_subject = $this->randomMachineName(8);
|
||||
$comment_body = $this->randomMachineName(8);
|
||||
$comment = Comment::create(array(
|
||||
'subject' => $comment_subject,
|
||||
'comment_body' => $comment_body,
|
||||
'entity_id' => $node->id(),
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'comment',
|
||||
'status' => CommentInterface::PUBLISHED,
|
||||
'uid' => $account->id(),
|
||||
));
|
||||
$comment->save();
|
||||
|
||||
// Create a node with two revisions, the initial one belonging to the
|
||||
// cancelling user.
|
||||
$revision_node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$revision = $revision_node->getRevisionId();
|
||||
$settings = get_object_vars($revision_node);
|
||||
$settings['revision'] = 1;
|
||||
$settings['uid'] = 1; // Set new/current revision to someone else.
|
||||
$revision_node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => $this->config('user.settings')->get('anonymous'))), 'Informs that all content will be attributed to anonymous account.');
|
||||
|
||||
// Confirm account cancellation.
|
||||
$timestamp = time();
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
|
||||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$this->assertFalse($user_storage->load($account->id()), 'User is not found in the database.');
|
||||
|
||||
// Confirm that user's content has been attributed to anonymous user.
|
||||
$anonymous_user = User::getAnonymousUser();
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$test_node = $node_storage->load($node->id());
|
||||
$this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node of the user has been attributed to anonymous user.');
|
||||
$test_node = node_revision_load($revision, TRUE);
|
||||
$this->assertTrue(($test_node->getRevisionAuthor()->id() == 0 && $test_node->isPublished()), 'Node revision of the user has been attributed to anonymous user.');
|
||||
$node_storage->resetCache(array($revision_node->id()));
|
||||
$test_node = $node_storage->load($revision_node->id());
|
||||
$this->assertTrue(($test_node->getOwnerId() != 0 && $test_node->isPublished()), "Current revision of the user's node was not attributed to anonymous user.");
|
||||
|
||||
$storage = \Drupal::entityManager()->getStorage('comment');
|
||||
$storage->resetCache(array($comment->id()));
|
||||
$test_comment = $storage->load($comment->id());
|
||||
$this->assertTrue(($test_comment->getOwnerId() == 0 && $test_comment->isPublished()), 'Comment of the user has been attributed to anonymous user.');
|
||||
$this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getDisplayName(), 'Comment of the user has been attributed to anonymous user name.');
|
||||
|
||||
// Confirm that the confirmation message made it through to the end user.
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete account and anonymize all content using a batch process.
|
||||
*/
|
||||
public function testUserAnonymizeBatch() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account'));
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create 11 nodes in order to trigger batch processing in
|
||||
// node_mass_update().
|
||||
$nodes = [];
|
||||
for ($i = 0; $i < 11; $i++) {
|
||||
$node = $this->drupalCreateNode(['uid' => $account->id()]);
|
||||
$nodes[$node->id()] = $node;
|
||||
}
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertRaw(t('Your account will be removed and all account information deleted. All of your content will be assigned to the %anonymous-name user.', array('%anonymous-name' => $this->config('user.settings')->get('anonymous'))), 'Informs that all content will be attributed to anonymous account.');
|
||||
|
||||
// Confirm account cancellation.
|
||||
$timestamp = time();
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
|
||||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
$this->assertFalse($user_storage->load($account->id()), 'User is not found in the database.');
|
||||
|
||||
// Confirm that user's content has been attributed to anonymous user.
|
||||
$node_storage->resetCache(array_keys($nodes));
|
||||
$test_nodes = $node_storage->loadMultiple(array_keys($nodes));
|
||||
foreach ($test_nodes as $test_node) {
|
||||
$this->assertTrue(($test_node->getOwnerId() == 0 && $test_node->isPublished()), 'Node ' . $test_node->id() . ' of the user has been attributed to anonymous user.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete account and remove all content.
|
||||
*/
|
||||
function testUserDelete() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_delete')->save();
|
||||
\Drupal::service('module_installer')->install(array('comment'));
|
||||
$this->resetAll();
|
||||
$this->addDefaultCommentField('node', 'page');
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(array('cancel account', 'post comments', 'skip comment approval'));
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
|
||||
// Create a simple node.
|
||||
$node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
|
||||
// Create comment.
|
||||
$edit = array();
|
||||
$edit['subject[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['comment_body[0][value]'] = $this->randomMachineName(16);
|
||||
|
||||
$this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Preview'));
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->assertText(t('Your comment has been posted.'));
|
||||
$comments = entity_load_multiple_by_properties('comment', array('subject' => $edit['subject[0][value]']));
|
||||
$comment = reset($comments);
|
||||
$this->assertTrue($comment->id(), 'Comment found.');
|
||||
|
||||
// Create a node with two revisions, the initial one belonging to the
|
||||
// cancelling user.
|
||||
$revision_node = $this->drupalCreateNode(array('uid' => $account->id()));
|
||||
$revision = $revision_node->getRevisionId();
|
||||
$settings = get_object_vars($revision_node);
|
||||
$settings['revision'] = 1;
|
||||
$settings['uid'] = 1; // Set new/current revision to someone else.
|
||||
$revision_node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Attempt to cancel account.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertText(t('Your account will be removed and all account information deleted. All of your content will also be deleted.'), 'Informs that all content will be deleted.');
|
||||
|
||||
// Confirm account cancellation.
|
||||
$timestamp = time();
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
|
||||
|
||||
// Confirm account cancellation request.
|
||||
$this->drupalGet("user/" . $account->id() . "/cancel/confirm/$timestamp/" . user_pass_rehash($account, $timestamp));
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$this->assertFalse($user_storage->load($account->id()), 'User is not found in the database.');
|
||||
|
||||
// Confirm that user's content has been deleted.
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$this->assertFalse($node_storage->load($node->id()), 'Node of the user has been deleted.');
|
||||
$this->assertFalse(node_revision_load($revision), 'Node revision of the user has been deleted.');
|
||||
$node_storage->resetCache(array($revision_node->id()));
|
||||
$this->assertTrue($node_storage->load($revision_node->id()), "Current revision of the user's node was not deleted.");
|
||||
\Drupal::entityManager()->getStorage('comment')->resetCache(array($comment->id()));
|
||||
$this->assertFalse(Comment::load($comment->id()), 'Comment of the user has been deleted.');
|
||||
|
||||
// Confirm that the confirmation message made it through to the end user.
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), "Confirmation message displayed to user.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an administrative user and delete another user.
|
||||
*/
|
||||
function testUserCancelByAdmin() {
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
|
||||
// Create a regular user.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Delete regular user.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertRaw(t('Are you sure you want to cancel the account %name?', array('%name' => $account->getUsername())), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
|
||||
|
||||
// Confirm deletion.
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
|
||||
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deletion of a user account without an email address.
|
||||
*/
|
||||
function testUserWithoutEmailCancelByAdmin() {
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
|
||||
// Create a regular user.
|
||||
$account = $this->drupalCreateUser(array());
|
||||
// This user has no email address.
|
||||
$account->mail = '';
|
||||
$account->save();
|
||||
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Delete regular user without email address.
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertRaw(t('Are you sure you want to cancel the account %name?', array('%name' => $account->getUsername())), 'Confirmation form to cancel account displayed.');
|
||||
$this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
|
||||
|
||||
// Confirm deletion.
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
|
||||
$this->assertRaw(t('%name has been deleted.', array('%name' => $account->getUsername())), 'User deleted.');
|
||||
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an administrative user and mass-delete other users.
|
||||
*/
|
||||
function testMassUserCancelByAdmin() {
|
||||
\Drupal::service('module_installer')->install(array('views'));
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
$this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save();
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
// Enable account cancellation notification.
|
||||
$this->config('user.settings')->set('notify.status_canceled', TRUE)->save();
|
||||
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Create some users.
|
||||
$users = array();
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$account = $this->drupalCreateUser(array());
|
||||
$users[$account->id()] = $account;
|
||||
}
|
||||
|
||||
// Cancel user accounts, including own one.
|
||||
$edit = array();
|
||||
$edit['action'] = 'user_cancel_user_action';
|
||||
for ($i = 0; $i <= 4; $i++) {
|
||||
$edit['user_bulk_form[' . $i . ']'] = TRUE;
|
||||
}
|
||||
$this->drupalPostForm('admin/people', $edit, t('Apply'));
|
||||
$this->assertText(t('Are you sure you want to cancel these user accounts?'), 'Confirmation form to cancel accounts displayed.');
|
||||
$this->assertText(t('When cancelling these accounts'), 'Allows to select account cancellation method.');
|
||||
$this->assertText(t('Require email confirmation to cancel account'), 'Allows to send confirmation mail.');
|
||||
$this->assertText(t('Notify user when account is canceled'), 'Allows to send notification mail.');
|
||||
|
||||
// Confirm deletion.
|
||||
$this->drupalPostForm(NULL, NULL, t('Cancel accounts'));
|
||||
$status = TRUE;
|
||||
foreach ($users as $account) {
|
||||
$status = $status && (strpos($this->content, $account->getUsername() . '</em> has been deleted.') !== FALSE);
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$status = $status && !$user_storage->load($account->id());
|
||||
}
|
||||
$this->assertTrue($status, 'Users deleted and not found in the database.');
|
||||
|
||||
// Ensure that admin account was not cancelled.
|
||||
$this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');
|
||||
$admin_user = $user_storage->load($admin_user->id());
|
||||
$this->assertTrue($admin_user->isActive(), 'Administrative user is found in the database and enabled.');
|
||||
|
||||
// Verify that uid 1's account was not cancelled.
|
||||
$user_storage->resetCache(array(1));
|
||||
$user1 = $user_storage->load(1);
|
||||
$this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests the create user administration page.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserCreateFailMailTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system_mail_failure_test');
|
||||
|
||||
/**
|
||||
* Tests the create user administration page.
|
||||
*/
|
||||
public function testUserAdd() {
|
||||
$user = $this->drupalCreateUser(array('administer users'));
|
||||
$this->drupalLogin($user);
|
||||
|
||||
// Replace the mail functionality with a fake, malfunctioning service.
|
||||
$this->config('system.mail')->set('interface.default', 'test_php_mail_failure')->save();
|
||||
// Create a user, but fail to send an email.
|
||||
$name = $this->randomMachineName();
|
||||
$edit = array(
|
||||
'name' => $name,
|
||||
'mail' => $this->randomMachineName() . '@example.com',
|
||||
'pass[pass1]' => $pass = $this->randomString(),
|
||||
'pass[pass2]' => $pass,
|
||||
'notify' => TRUE,
|
||||
);
|
||||
$this->drupalPostForm('admin/people/create', $edit, t('Create new account'));
|
||||
|
||||
$this->assertText(t('Unable to send email. Contact the site administrator if the problem persists.'));
|
||||
$this->assertNoText(t('A welcome message with further instructions has been emailed to the new user @name.', array('@name' => $edit['name'])));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests account deleting of users.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserDeleteTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Test deleting multiple users.
|
||||
*/
|
||||
function testUserDeleteMultiple() {
|
||||
// Create a few users with permissions, so roles will be created.
|
||||
$user_a = $this->drupalCreateUser(array('access user profiles'));
|
||||
$user_b = $this->drupalCreateUser(array('access user profiles'));
|
||||
$user_c = $this->drupalCreateUser(array('access user profiles'));
|
||||
|
||||
$uids = array($user_a->id(), $user_b->id(), $user_c->id());
|
||||
|
||||
// These users should have a role
|
||||
$query = db_select('user__roles', 'r');
|
||||
$roles_created = $query
|
||||
->fields('r', array('entity_id'))
|
||||
->condition('entity_id', $uids, 'IN')
|
||||
->countQuery()
|
||||
->execute()
|
||||
->fetchField();
|
||||
|
||||
$this->assertTrue($roles_created > 0, 'Role assignments created for new users and deletion of role assignments can be tested');
|
||||
// We should be able to load one of the users.
|
||||
$this->assertTrue(User::load($user_a->id()), 'User is created and deletion of user can be tested');
|
||||
// Delete the users.
|
||||
user_delete_multiple($uids);
|
||||
// Test if the roles assignments are deleted.
|
||||
$query = db_select('user__roles', 'r');
|
||||
$roles_after_deletion = $query
|
||||
->fields('r', array('entity_id'))
|
||||
->condition('entity_id', $uids, 'IN')
|
||||
->countQuery()
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertTrue($roles_after_deletion == 0, 'Role assignments deleted along with users');
|
||||
// Test if the users are deleted, User::load() will return NULL.
|
||||
$this->assertNull(User::load($user_a->id()), format_string('User with id @uid deleted.', array('@uid' => $user_a->id())));
|
||||
$this->assertNull(User::load($user_b->id()), format_string('User with id @uid deleted.', array('@uid' => $user_b->id())));
|
||||
$this->assertNull(User::load($user_c->id()), format_string('User with id @uid deleted.', array('@uid' => $user_c->id())));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests user edited own account can still log in.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserEditedOwnAccountTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user_form_test');
|
||||
|
||||
function testUserEditedOwnAccount() {
|
||||
// Change account setting 'Who can register accounts?' to Administrators
|
||||
// only.
|
||||
$this->config('user.settings')->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)->save();
|
||||
|
||||
// Create a new user account and log in.
|
||||
$account = $this->drupalCreateUser(array('change own username'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// Change own username.
|
||||
$edit = array();
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
$this->drupalPostForm('user/' . $account->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Log out.
|
||||
$this->drupalLogout();
|
||||
|
||||
// Set the new name on the user account and attempt to log back in.
|
||||
$account->name = $edit['name'];
|
||||
$this->drupalLogin($account);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests specific parts of the user entity like the URI callback and the label
|
||||
* callback.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserEntityCallbacksTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user', 'user_hooks_test');
|
||||
|
||||
/**
|
||||
* An authenticated user to use for testing.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
* An anonymous user to use for testing.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $anonymous;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->account = $this->drupalCreateUser();
|
||||
$this->anonymous = User::create(['uid' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test label callback.
|
||||
*/
|
||||
function testLabelCallback() {
|
||||
$this->assertEqual($this->account->label(), $this->account->getUsername(), 'The username should be used as label');
|
||||
|
||||
// Setup a random anonymous name to be sure the name is used.
|
||||
$name = $this->randomMachineName();
|
||||
$this->config('user.settings')->set('anonymous', $name)->save();
|
||||
$this->assertEqual($this->anonymous->label(), $name, 'The variable anonymous should be used for name of uid 0');
|
||||
$this->assertEqual($this->anonymous->getDisplayName(), $name, 'The variable anonymous should be used for display name of uid 0');
|
||||
$this->assertEqual($this->anonymous->getUserName(), '', 'The raw anonymous user name should be empty string');
|
||||
|
||||
// Set to test the altered username.
|
||||
\Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
|
||||
|
||||
$this->assertEqual($this->account->getDisplayName(), '<em>' . $this->account->id() . '</em>', 'The user display name should be altered.');
|
||||
$this->assertEqual($this->account->getUsername(), $this->account->name->value, 'The user name should not be altered.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Functional tests for a user's ability to change their default language.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserLanguageTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user', 'language');
|
||||
|
||||
/**
|
||||
* Test if user can change their default language.
|
||||
*/
|
||||
function testUserLanguageConfiguration() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
|
||||
// User to change their default language.
|
||||
$web_user = $this->drupalCreateUser();
|
||||
|
||||
// Add custom language.
|
||||
$this->drupalLogin($admin_user);
|
||||
// Code for the language.
|
||||
$langcode = 'xx';
|
||||
// The English name for the language.
|
||||
$name = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->drupalLogout();
|
||||
|
||||
// Log in as normal user and edit account settings.
|
||||
$this->drupalLogin($web_user);
|
||||
$path = 'user/' . $web_user->id() . '/edit';
|
||||
$this->drupalGet($path);
|
||||
// Ensure language settings widget is available.
|
||||
$this->assertText(t('Language'), 'Language selector available.');
|
||||
// Ensure custom language is present.
|
||||
$this->assertText($name, 'Language present on form.');
|
||||
// Switch to our custom language.
|
||||
$edit = array(
|
||||
'preferred_langcode' => $langcode,
|
||||
);
|
||||
$this->drupalPostForm($path, $edit, t('Save'));
|
||||
// Ensure form was submitted successfully.
|
||||
$this->assertText(t('The changes have been saved.'), 'Changes were saved.');
|
||||
// Check if language was changed.
|
||||
$this->assertOptionSelected('edit-preferred-langcode', $langcode, 'Default language successfully updated.');
|
||||
|
||||
$this->drupalLogout();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests that users can be assigned and unassigned roles.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserRolesAssignmentTest extends WebTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$admin_user = $this->drupalCreateUser(array('administer permissions', 'administer users'));
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a user can be assigned a role and that the role can be removed
|
||||
* again.
|
||||
*/
|
||||
function testAssignAndRemoveRole() {
|
||||
$rid = $this->drupalCreateRole(array('administer users'));
|
||||
$account = $this->drupalCreateUser();
|
||||
|
||||
// Assign the role to the user.
|
||||
$this->drupalPostForm('user/' . $account->id() . '/edit', array("roles[$rid]" => $rid), t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'));
|
||||
$this->assertFieldChecked('edit-roles-' . $rid, 'Role is assigned.');
|
||||
$this->userLoadAndCheckRoleAssigned($account, $rid);
|
||||
|
||||
// Remove the role from the user.
|
||||
$this->drupalPostForm('user/' . $account->id() . '/edit', array("roles[$rid]" => FALSE), t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'));
|
||||
$this->assertNoFieldChecked('edit-roles-' . $rid, 'Role is removed from user.');
|
||||
$this->userLoadAndCheckRoleAssigned($account, $rid, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that when creating a user the role can be assigned. And that it can
|
||||
* be removed again.
|
||||
*/
|
||||
function testCreateUserWithRole() {
|
||||
$rid = $this->drupalCreateRole(array('administer users'));
|
||||
// Create a new user and add the role at the same time.
|
||||
$edit = array(
|
||||
'name' => $this->randomMachineName(),
|
||||
'mail' => $this->randomMachineName() . '@example.com',
|
||||
'pass[pass1]' => $pass = $this->randomString(),
|
||||
'pass[pass2]' => $pass,
|
||||
"roles[$rid]" => $rid,
|
||||
);
|
||||
$this->drupalPostForm('admin/people/create', $edit, t('Create new account'));
|
||||
$this->assertText(t('Created a new user account for @name.', array('@name' => $edit['name'])));
|
||||
// Get the newly added user.
|
||||
$account = user_load_by_name($edit['name']);
|
||||
|
||||
$this->drupalGet('user/' . $account->id() . '/edit');
|
||||
$this->assertFieldChecked('edit-roles-' . $rid, 'Role is assigned.');
|
||||
$this->userLoadAndCheckRoleAssigned($account, $rid);
|
||||
|
||||
// Remove the role again.
|
||||
$this->drupalPostForm('user/' . $account->id() . '/edit', array("roles[$rid]" => FALSE), t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'));
|
||||
$this->assertNoFieldChecked('edit-roles-' . $rid, 'Role is removed from user.');
|
||||
$this->userLoadAndCheckRoleAssigned($account, $rid, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check role on user object.
|
||||
*
|
||||
* @param object $account
|
||||
* The user account to check.
|
||||
* @param string $rid
|
||||
* The role ID to search for.
|
||||
* @param bool $is_assigned
|
||||
* (optional) Whether to assert that $rid exists (TRUE) or not (FALSE).
|
||||
* Defaults to TRUE.
|
||||
*/
|
||||
private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) {
|
||||
$user_storage = $this->container->get('entity.manager')->getStorage('user');
|
||||
$user_storage->resetCache(array($account->id()));
|
||||
$account = $user_storage->load($account->id());
|
||||
if ($is_assigned) {
|
||||
$this->assertFalse(array_search($rid, $account->getRoles()) === FALSE, 'The role is present in the user object.');
|
||||
}
|
||||
else {
|
||||
$this->assertTrue(array_search($rid, $account->getRoles()) === FALSE, 'The role is not present in the user object.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests account saving for arbitrary new uid.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserSaveTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Test creating a user with arbitrary uid.
|
||||
*/
|
||||
function testUserImport() {
|
||||
// User ID must be a number that is not in the database.
|
||||
|
||||
$uids = \Drupal::entityManager()->getStorage('user')->getQuery()
|
||||
->sort('uid', 'DESC')
|
||||
->range(0, 1)
|
||||
->execute();
|
||||
$max_uid = reset($uids);
|
||||
$test_uid = $max_uid + mt_rand(1000, 1000000);
|
||||
$test_name = $this->randomMachineName();
|
||||
|
||||
// Create the base user, based on drupalCreateUser().
|
||||
$user = User::create([
|
||||
'name' => $test_name,
|
||||
'uid' => $test_uid,
|
||||
'mail' => $test_name . '@example.com',
|
||||
'pass' => user_password(),
|
||||
'status' => 1,
|
||||
]);
|
||||
$user->enforceIsNew();
|
||||
$user->save();
|
||||
|
||||
// Test if created user exists.
|
||||
$user_by_uid = User::load($test_uid);
|
||||
$this->assertTrue($user_by_uid, 'Loading user by uid.');
|
||||
|
||||
$user_by_name = user_load_by_name($test_name);
|
||||
$this->assertTrue($user_by_name, 'Loading user by name.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that an existing password is unset after the user was saved.
|
||||
*/
|
||||
function testExistingPasswordRemoval() {
|
||||
/** @var \Drupal\user\Entity\User $user */
|
||||
$user = User::create(['name' => $this->randomMachineName()]);
|
||||
$user->save();
|
||||
$user->setExistingPassword('existing password');
|
||||
$this->assertNotNull($user->pass->existing);
|
||||
$user->save();
|
||||
$this->assertNull($user->pass->existing);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests the user search page and verifies that sensitive information is hidden
|
||||
* from unauthorized users.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserSearchTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('search');
|
||||
|
||||
function testUserSearch() {
|
||||
// Verify that a user without 'administer users' permission cannot search
|
||||
// for users by email address.
|
||||
$user1 = $this->drupalCreateUser(array('access user profiles', 'search content'));
|
||||
$this->drupalLogin($user1);
|
||||
$keys = $user1->getEmail();
|
||||
$edit = array('keys' => $keys);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText(t('Your search yielded no results.'), 'Search by email did not work for non-admin user');
|
||||
$this->assertText('no results', 'Search by email gave no-match message');
|
||||
|
||||
// Verify that a non-matching query gives an appropriate message.
|
||||
$keys = 'nomatch';
|
||||
$edit = array('keys' => $keys);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText('no results', 'Non-matching search gave appropriate message');
|
||||
|
||||
// Verify that a user with search permission can search for users by name.
|
||||
$keys = $user1->getUsername();
|
||||
$edit = array('keys' => $keys);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertLink($keys, 0, 'Search by username worked for non-admin user');
|
||||
|
||||
// Verify that searching by sub-string works too.
|
||||
$subkey = substr($keys, 1, 5);
|
||||
$edit = array('keys' => $subkey);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertLink($keys, 0, 'Search by username substring worked for non-admin user');
|
||||
|
||||
// Verify that wildcard search works.
|
||||
$subkey = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
|
||||
$edit = array('keys' => $subkey);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertLink($keys, 0, 'Search with wildcard worked for non-admin user');
|
||||
|
||||
// Verify that a user with 'administer users' permission can search by
|
||||
// email.
|
||||
$user2 = $this->drupalCreateUser(array('administer users', 'access user profiles', 'search content'));
|
||||
$this->drupalLogin($user2);
|
||||
$keys = $user2->getEmail();
|
||||
$edit = array('keys' => $keys);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText($keys, 'Search by email works for administrative user');
|
||||
$this->assertText($user2->getUsername(), 'Search by email resulted in username on page for administrative user');
|
||||
|
||||
// Verify that a substring works too for email.
|
||||
$subkey = substr($keys, 1, 5);
|
||||
$edit = array('keys' => $subkey);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText($keys, 'Search by email substring works for administrative user');
|
||||
$this->assertText($user2->getUsername(), 'Search by email substring resulted in username on page for administrative user');
|
||||
|
||||
// Verify that wildcard search works for email
|
||||
$subkey = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
|
||||
$edit = array('keys' => $subkey);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText($user2->getUsername(), 'Search for email wildcard resulted in username on page for administrative user');
|
||||
|
||||
// Verify that if they search by user name, they see email address too.
|
||||
$keys = $user1->getUsername();
|
||||
$edit = array('keys' => $keys);
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText($keys, 'Search by username works for admin user');
|
||||
$this->assertText($user1->getEmail(), 'Search by username for admin shows email address too');
|
||||
|
||||
// Create a blocked user.
|
||||
$blocked_user = $this->drupalCreateUser();
|
||||
$blocked_user->block();
|
||||
$blocked_user->save();
|
||||
|
||||
// Verify that users with "administer users" permissions can see blocked
|
||||
// accounts in search results.
|
||||
$edit = array('keys' => $blocked_user->getUsername());
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText($blocked_user->getUsername(), 'Blocked users are listed on the user search results for users with the "administer users" permission.');
|
||||
|
||||
// Verify that users without "administer users" permissions do not see
|
||||
// blocked accounts in search results.
|
||||
$this->drupalLogin($user1);
|
||||
$edit = array('keys' => $blocked_user->getUsername());
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText(t('Your search yielded no results.'), 'Blocked users are hidden from the user search results.');
|
||||
|
||||
// Create a user without search permission, and one without user page view
|
||||
// permission. Verify that neither one can access the user search page.
|
||||
$user3 = $this->drupalCreateUser(array('search content'));
|
||||
$this->drupalLogin($user3);
|
||||
$this->drupalGet('search/user');
|
||||
$this->assertResponse('403', 'User without user profile access cannot search');
|
||||
|
||||
$user4 = $this->drupalCreateUser(array('access user profiles'));
|
||||
$this->drupalLogin($user4);
|
||||
$this->drupalGet('search/user');
|
||||
$this->assertResponse('403', 'User without search permission cannot search');
|
||||
$this->drupalLogout();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Generates text using placeholders for dummy content to check user token
|
||||
* replacement.
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class UserTokenReplaceTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'user_hooks_test');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
ConfigurableLanguage::createFromLangcode('de')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a user, then tests the tokens generated from it.
|
||||
*/
|
||||
function testUserTokenReplacement() {
|
||||
$token_service = \Drupal::token();
|
||||
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
|
||||
$url_options = array(
|
||||
'absolute' => TRUE,
|
||||
'language' => $language_interface,
|
||||
);
|
||||
|
||||
\Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
|
||||
\Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);
|
||||
|
||||
// Create two users and log them in one after another.
|
||||
$user1 = $this->drupalCreateUser(array());
|
||||
$user2 = $this->drupalCreateUser(array());
|
||||
$this->drupalLogin($user1);
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($user2);
|
||||
|
||||
$account = User::load($user1->id());
|
||||
$global_account = User::load(\Drupal::currentUser()->id());
|
||||
|
||||
// Generate and test tokens.
|
||||
$tests = array();
|
||||
$tests['[user:uid]'] = $account->id();
|
||||
$tests['[user:name]'] = $account->getAccountName();
|
||||
$tests['[user:account-name]'] = $account->getAccountName();
|
||||
$tests['[user:display-name]'] = $account->getDisplayName();
|
||||
$tests['[user:mail]'] = $account->getEmail();
|
||||
$tests['[user:url]'] = $account->url('canonical', $url_options);
|
||||
$tests['[user:edit-url]'] = $account->url('edit-form', $url_options);
|
||||
$tests['[user:last-login]'] = format_date($account->getLastLoginTime(), 'medium', '', NULL, $language_interface->getId());
|
||||
$tests['[user:last-login:short]'] = format_date($account->getLastLoginTime(), 'short', '', NULL, $language_interface->getId());
|
||||
$tests['[user:created]'] = format_date($account->getCreatedTime(), 'medium', '', NULL, $language_interface->getId());
|
||||
$tests['[user:created:short]'] = format_date($account->getCreatedTime(), 'short', '', NULL, $language_interface->getId());
|
||||
$tests['[current-user:name]'] = $global_account->getAccountName();
|
||||
$tests['[current-user:account-name]'] = $global_account->getAccountName();
|
||||
$tests['[current-user:display-name]'] = $global_account->getDisplayName();
|
||||
|
||||
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($account);
|
||||
$metadata_tests = [];
|
||||
$metadata_tests['[user:uid]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[user:name]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[user:account-name]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[user:display-name]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[user:mail]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[user:url]'] = $base_bubbleable_metadata;
|
||||
$metadata_tests['[user:edit-url]'] = $base_bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
// This test runs with the Language module enabled, which means config is
|
||||
// overridden by LanguageConfigFactoryOverride (to provide translations of
|
||||
// config). This causes the interface language cache context to be added for
|
||||
// config entities. The four next tokens use DateFormat Config entities, and
|
||||
// therefore have the interface language cache context.
|
||||
$bubbleable_metadata->addCacheContexts(['languages:language_interface']);
|
||||
$metadata_tests['[user:last-login]'] = $bubbleable_metadata->addCacheTags(['rendered']);
|
||||
$metadata_tests['[user:last-login:short]'] = $bubbleable_metadata;
|
||||
$metadata_tests['[user:created]'] = $bubbleable_metadata;
|
||||
$metadata_tests['[user:created:short]'] = $bubbleable_metadata;
|
||||
$metadata_tests['[current-user:name]'] = $base_bubbleable_metadata->merge(BubbleableMetadata::createFromObject($global_account)->addCacheContexts(['user']));
|
||||
$metadata_tests['[current-user:account-name]'] = $base_bubbleable_metadata->merge(BubbleableMetadata::createFromObject($global_account)->addCacheContexts(['user']));
|
||||
$metadata_tests['[current-user:display-name]'] = $base_bubbleable_metadata->merge(BubbleableMetadata::createFromObject($global_account)->addCacheContexts(['user']));
|
||||
|
||||
// Test to make sure that we generated something for each token.
|
||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$bubbleable_metadata = new BubbleableMetadata();
|
||||
$output = $token_service->replace($input, ['user' => $account], ['langcode' => $language_interface->getId()], $bubbleable_metadata);
|
||||
$this->assertEqual($output, $expected, new FormattableMarkup('User token %token replaced.', ['%token' => $input]));
|
||||
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
|
||||
}
|
||||
|
||||
// Generate tokens for the anonymous user.
|
||||
$anonymous_user = User::load(0);
|
||||
$tests = [];
|
||||
$tests['[user:uid]'] = t('not yet assigned');
|
||||
$tests['[user:display-name]'] = $anonymous_user->getDisplayName();
|
||||
|
||||
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($anonymous_user);
|
||||
$metadata_tests = [];
|
||||
$metadata_tests['[user:uid]'] = $base_bubbleable_metadata;
|
||||
$bubbleable_metadata = clone $base_bubbleable_metadata;
|
||||
$bubbleable_metadata->addCacheableDependency(\Drupal::config('user.settings'));
|
||||
$metadata_tests['[user:display-name]'] = $bubbleable_metadata;
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$bubbleable_metadata = new BubbleableMetadata();
|
||||
$output = $token_service->replace($input, array('user' => $anonymous_user), array('langcode' => $language_interface->getId()), $bubbleable_metadata);
|
||||
$this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', array('%token' => $input)));
|
||||
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
|
||||
}
|
||||
|
||||
// Generate login and cancel link.
|
||||
$tests = array();
|
||||
$tests['[user:one-time-login-url]'] = user_pass_reset_url($account);
|
||||
$tests['[user:cancel-url]'] = user_cancel_url($account);
|
||||
|
||||
// Generate tokens with interface language.
|
||||
$link = \Drupal::url('user.page', [], array('absolute' => TRUE));
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = $token_service->replace($input, ['user' => $account], ['langcode' => $language_interface->getId(), 'callback' => 'user_mail_tokens', 'clear' => TRUE]);
|
||||
$this->assertTrue(strpos($output, $link) === 0, 'Generated URL is in interface language.');
|
||||
}
|
||||
|
||||
// Generate tokens with the user's preferred language.
|
||||
$account->preferred_langcode = 'de';
|
||||
$account->save();
|
||||
$link = \Drupal::url('user.page', [], array('language' => \Drupal::languageManager()->getLanguage($account->getPreferredLangcode()), 'absolute' => TRUE));
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = $token_service->replace($input, ['user' => $account], ['callback' => 'user_mail_tokens', 'clear' => TRUE]);
|
||||
$this->assertTrue(strpos($output, $link) === 0, "Generated URL is in the user's preferred language.");
|
||||
}
|
||||
|
||||
// Generate tokens with one specific language.
|
||||
$link = \Drupal::url('user.page', [], array('language' => \Drupal::languageManager()->getLanguage('de'), 'absolute' => TRUE));
|
||||
foreach ($tests as $input => $expected) {
|
||||
foreach (array($user1, $user2) as $account) {
|
||||
$output = $token_service->replace($input, ['user' => $account], ['langcode' => 'de', 'callback' => 'user_mail_tokens', 'clear' => TRUE]);
|
||||
$this->assertTrue(strpos($output, $link) === 0, "Generated URL in the requested language.");
|
||||
}
|
||||
}
|
||||
|
||||
// Generate user display name tokens when safe markup is returned.
|
||||
// @see user_hooks_test_user_format_name_alter()
|
||||
\Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);
|
||||
$input = '[user:display-name] [current-user:display-name]';
|
||||
$expected = "<em>{$user1->id()}</em> <em>{$user2->id()}</em>";
|
||||
$output = $token_service->replace($input, ['user' => $user1]);
|
||||
$this->assertEqual($output, $expected, new FormattableMarkup('User token %token does not escape safe markup.', ['%token' => 'display-name']));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\user\Tests\Views;
|
||||
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views_ui\Tests\UITestBase;
|
||||
|
||||
/**
|
||||
* Tests views role access plugin UI.
|
||||
*
|
||||
* @group user
|
||||
* @see Drupal\user\Plugin\views\access\Role
|
||||
*/
|
||||
class AccessRoleUITest extends UITestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_access_role');
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('user', 'user_test_views');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('user_test_views'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the role access plugin UI.
|
||||
*/
|
||||
public function testAccessRoleUI() {
|
||||
$entity_manager = $this->container->get('entity.manager');
|
||||
$entity_manager->getStorage('user_role')->create(array('id' => 'custom_role', 'label' => 'Custom role'))->save();
|
||||
$access_url = "admin/structure/views/nojs/display/test_access_role/default/access_options";
|
||||
$this->drupalPostForm($access_url, array('access_options[role][custom_role]' => 1), t('Apply'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$view = $entity_manager->getStorage('view')->load('test_access_role');
|
||||
|
||||
$display = $view->getDisplay('default');
|
||||
$this->assertEqual($display['display_options']['access']['options']['role'], array('custom_role' => 'custom_role'));
|
||||
|
||||
// Test changing access plugin from role to none.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_access_role/default/access', ['access[type]' => 'none'], t('Apply'));
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
// Verify that role option is not set.
|
||||
$view = $entity_manager->getStorage('view')->load('test_access_role');
|
||||
$display = $view->getDisplay('default');
|
||||
$this->assertFalse(isset($display['display_options']['access']['options']['role']));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user