Issue #2723551 by valthebald, John Cook: Remove entity_load* usage for user entity type
parent
77a2d8fb4e
commit
501e8b434a
|
@ -108,7 +108,8 @@ class Name extends InOperator {
|
|||
$this->valueOptions = array();
|
||||
|
||||
if ($this->value) {
|
||||
$result = entity_load_multiple_by_properties('user', array('uid' => $this->value));
|
||||
$result = \Drupal::entityTypeManager()->getStorage('user')
|
||||
->loadByProperties(['uid' => $this->value]);
|
||||
foreach ($result as $account) {
|
||||
if ($account->id()) {
|
||||
$this->valueOptions[$account->id()] = $account->label();
|
||||
|
|
|
@ -40,7 +40,10 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$this->drupalPostForm('user/register', $edit, t('Create new account'));
|
||||
$this->assertText(t('A welcome message with further instructions has been sent to your email address.'), 'User registered successfully.');
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
|
||||
/** @var EntityStorageInterface $storage */
|
||||
$storage = $this->container->get('entity_type.manager')->getStorage('user');
|
||||
$accounts = $storage->loadByProperties(['name' => $name, 'mail' => $mail]);
|
||||
$new_user = reset($accounts);
|
||||
$this->assertTrue($new_user->isActive(), 'New account is active after registration.');
|
||||
$resetURL = user_pass_reset_url($new_user);
|
||||
|
@ -54,7 +57,7 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$this->drupalPostForm('user/register', $edit, t('Create new account'));
|
||||
$this->container->get('entity.manager')->getStorage('user')->resetCache();
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$accounts = $storage->loadByProperties(['name' => $name, 'mail' => $mail]);
|
||||
$new_user = reset($accounts);
|
||||
$this->assertFalse($new_user->isActive(), 'New account is blocked until approved by an administrator.');
|
||||
}
|
||||
|
@ -83,7 +86,8 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['pass[pass2]'] = $new_pass;
|
||||
$this->drupalPostForm('user/register', $edit, t('Create new account'));
|
||||
$this->container->get('entity.manager')->getStorage('user')->resetCache();
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$accounts = $this->container->get('entity_type.manager')->getStorage('user')
|
||||
->loadByProperties(['name' => $name, 'mail' => $mail]);
|
||||
$new_user = reset($accounts);
|
||||
$this->assertNotNull($new_user, 'New account successfully created with matching passwords.');
|
||||
$this->assertText(t('Registration successful. You are now logged in.'), 'Users are logged in after registering.');
|
||||
|
@ -108,7 +112,8 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->assertText(t('The username @name has not been activated or is blocked.', array('@name' => $name)), 'User cannot log in yet.');
|
||||
|
||||
// Activate the new account.
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$accounts = $this->container->get('entity_type.manager')->getStorage('user')
|
||||
->loadByProperties(['name' => $name, 'mail' => $mail]);
|
||||
$new_user = reset($accounts);
|
||||
$admin_user = $this->drupalCreateUser(array('administer users'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
@ -248,7 +253,8 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$this->drupalPostForm(NULL, $edit, t('Create new account'));
|
||||
|
||||
// Check user fields.
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$accounts = $this->container->get('entity_type.manager')->getStorage('user')
|
||||
->loadByProperties(['name' => $name, 'mail' => $mail]);
|
||||
$new_user = reset($accounts);
|
||||
$this->assertEqual($new_user->getUsername(), $name, 'Username matches.');
|
||||
$this->assertEqual($new_user->getEmail(), $mail, 'Email address matches.');
|
||||
|
@ -338,7 +344,8 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['test_user_field[0][value]'] = $value;
|
||||
$this->drupalPostForm(NULL, $edit, t('Create new account'));
|
||||
// Check user fields.
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$accounts = $this->container->get('entity_type.manager')->getStorage('user')
|
||||
->loadByProperties(['name' => $name, 'mail' => $mail]);
|
||||
$new_user = reset($accounts);
|
||||
$this->assertEqual($new_user->test_user_field->value, $value, 'The field value was correctly saved.');
|
||||
|
||||
|
@ -367,7 +374,8 @@ class UserRegistrationTest extends WebTestBase {
|
|||
$edit['mail'] = $mail = $edit['name'] . '@example.com';
|
||||
$this->drupalPostForm(NULL, $edit, t('Create new account'));
|
||||
// Check user fields.
|
||||
$accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail));
|
||||
$accounts = $this->container->get('entity_type.manager')->getStorage('user')
|
||||
->loadByProperties(array('name' => $name, 'mail' => $mail));
|
||||
$new_user = reset($accounts);
|
||||
$this->assertEqual($new_user->test_user_field[0]->value, $value, format_string('@js : The field value was correctly saved.', array('@js' => $js)));
|
||||
$this->assertEqual($new_user->test_user_field[1]->value, $value + 1, format_string('@js : The field value was correctly saved.', array('@js' => $js)));
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\user\Tests\Views;
|
||||
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\views\Views;
|
||||
|
||||
|
@ -130,7 +131,7 @@ class BulkFormTest extends UserTestBase {
|
|||
*/
|
||||
public function testBulkFormCombineFilter() {
|
||||
// Add a user.
|
||||
$account = entity_load('user', $this->users[0]->id());
|
||||
User::load($this->users[0]->id());
|
||||
$view = Views::getView('test_user_bulk_form_combine_filter');
|
||||
$errors = $view->validate();
|
||||
$this->assertEqual(reset($errors['default']), t('Field %field set in %filter is not usable for this filter type. Combined field filter only works for simple fields.', array('%field' => 'User: Bulk update', '%filter' => 'Global: Combine fields filter')));
|
||||
|
|
|
@ -232,7 +232,8 @@ function user_load($uid, $reset = FALSE) {
|
|||
* @see \Drupal\user\Entity\User::loadMultiple()
|
||||
*/
|
||||
function user_load_by_mail($mail) {
|
||||
$users = entity_load_multiple_by_properties('user', array('mail' => $mail));
|
||||
$users = \Drupal::entityTypeManager()->getStorage('user')
|
||||
->loadByProperties(['mail' => $mail]);
|
||||
return $users ? reset($users) : FALSE;
|
||||
}
|
||||
|
||||
|
@ -248,7 +249,8 @@ function user_load_by_mail($mail) {
|
|||
* @see \Drupal\user\Entity\User::loadMultiple()
|
||||
*/
|
||||
function user_load_by_name($name) {
|
||||
$users = entity_load_multiple_by_properties('user', array('name' => $name));
|
||||
$users = \Drupal::entityTypeManager()->getStorage('user')
|
||||
->loadByProperties(['name' => $name]);
|
||||
return $users ? reset($users) : FALSE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue