update
This commit is contained in:
@@ -78,7 +78,10 @@ class UserAccountLinksTest extends BrowserTestBase {
|
||||
*/
|
||||
public function testDisabledAccountLink() {
|
||||
// Create an admin user and log in.
|
||||
$this->drupalLogin($this->drupalCreateUser(['access administration pages', 'administer menu']));
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'access administration pages',
|
||||
'administer menu',
|
||||
]));
|
||||
|
||||
// Verify that the 'My account' link exists before we check for its
|
||||
// disappearance.
|
||||
@@ -134,7 +137,7 @@ class UserAccountLinksTest extends BrowserTestBase {
|
||||
// Check the page title for registered users is "My Account" in menus.
|
||||
$this->drupalLogin($this->drupalCreateUser());
|
||||
// After login, the client is redirected to /user.
|
||||
$this->assertLink(t('My account'), 0, "Page title of /user is 'My Account' in menus for registered users");
|
||||
$this->assertSession()->linkExists(t('My account'), 0, "Page title of /user is 'My Account' in menus for registered users");
|
||||
$this->assertLinkByHref(\Drupal::urlGenerator()->generate('user.page'), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,10 @@ class UserAdminLanguageTest extends BrowserTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// User to add and remove language.
|
||||
$this->adminUser = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'administer languages',
|
||||
'access administration pages',
|
||||
]);
|
||||
// User to check non-admin access.
|
||||
$this->regularUser = $this->drupalCreateUser();
|
||||
}
|
||||
|
||||
@@ -162,7 +162,10 @@ class UserAdminTest extends BrowserTestBase {
|
||||
*/
|
||||
public function testNotificationEmailAddress() {
|
||||
// Test that the Notification Email address field is on the config page.
|
||||
$admin_user = $this->drupalCreateUser(['administer users', 'administer account settings']);
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer users',
|
||||
'administer account settings',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalGet('admin/config/people/accounts');
|
||||
$this->assertRaw('id="edit-mail-notification-address"', 'Notification Email address field exists');
|
||||
|
||||
@@ -420,7 +420,11 @@ class UserCancelTest extends BrowserTestBase {
|
||||
$user_storage = $this->container->get('entity_type.manager')->getStorage('user');
|
||||
|
||||
// Create a user.
|
||||
$account = $this->drupalCreateUser(['cancel account', 'post comments', 'skip comment approval']);
|
||||
$account = $this->drupalCreateUser([
|
||||
'cancel account',
|
||||
'post comments',
|
||||
'skip comment approval',
|
||||
]);
|
||||
$this->drupalLogin($account);
|
||||
// Load a real user object.
|
||||
$user_storage->resetCache([$account->id()]);
|
||||
|
||||
@@ -30,7 +30,11 @@ class UserLanguageCreationTest extends BrowserTestBase {
|
||||
*/
|
||||
public function testLocalUserCreation() {
|
||||
// User to add and remove language and create new users.
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'administer users']);
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer languages',
|
||||
'access administration pages',
|
||||
'administer users',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Add predefined language.
|
||||
|
||||
@@ -29,7 +29,10 @@ class UserLanguageTest extends BrowserTestBase {
|
||||
*/
|
||||
public function testUserLanguageConfiguration() {
|
||||
// User to add and remove language.
|
||||
$admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer languages',
|
||||
'access administration pages',
|
||||
]);
|
||||
// User to change their default language.
|
||||
$web_user = $this->drupalCreateUser();
|
||||
|
||||
|
||||
@@ -391,28 +391,28 @@ class UserPasswordResetTest extends BrowserTestBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to make assertions about a password reset triggering user flood cotrol.
|
||||
* Makes assertions about a password reset triggering user flood control.
|
||||
*/
|
||||
public function assertPasswordUserFlood() {
|
||||
$this->assertText(t('Too many password recovery requests for this account. It is temporarily blocked. Try again later or contact the site administrator.'), 'User password reset flood error message shown.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to make assertions about a password reset not triggering user flood control.
|
||||
* Makes assertions about a password reset not triggering user flood control.
|
||||
*/
|
||||
public function assertNoPasswordUserFlood() {
|
||||
$this->assertNoText(t('Too many password recovery requests for this account. It is temporarily blocked. Try again later or contact the site administrator.'), 'User password reset flood error message not shown.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to make assertions about a password reset triggering IP flood cotrol.
|
||||
* Makes assertions about a password reset triggering IP flood control.
|
||||
*/
|
||||
public function assertPasswordIpFlood() {
|
||||
$this->assertText(t('Too many password recovery requests from your IP address. It is temporarily blocked. Try again later or contact the site administrator.'), 'IP password reset flood error message shown.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to make assertions about a password reset not triggering IP flood control.
|
||||
* Makes assertions about a password reset not triggering IP flood control.
|
||||
*/
|
||||
public function assertNoPasswordIpFlood() {
|
||||
$this->assertNoText(t('Too many password recovery requests from your IP address. It is temporarily blocked. Try again later or contact the site administrator.'), 'IP password reset flood error message not shown.');
|
||||
|
||||
@@ -36,7 +36,13 @@ class UserPermissionsTest extends BrowserTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(['administer permissions', 'access user profiles', 'administer site configuration', 'administer modules', 'administer account settings']);
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'administer permissions',
|
||||
'access user profiles',
|
||||
'administer site configuration',
|
||||
'administer modules',
|
||||
'administer account settings',
|
||||
]);
|
||||
|
||||
// Find the new role ID.
|
||||
$all_rids = $this->adminUser->getRoles();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\Tests\user\Functional;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperManager;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\image\Entity\ImageStyle;
|
||||
@@ -159,4 +160,21 @@ class UserPictureTest extends BrowserTestBase {
|
||||
return File::load($account->user_picture->target_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests user picture field with a non-standard field formatter.
|
||||
*
|
||||
* @see user_user_view_alter()
|
||||
*/
|
||||
public function testUserViewAlter() {
|
||||
\Drupal::service('module_installer')->install(['image_module_test']);
|
||||
// Set dummy_image_formatter to the default view mode of user entity.
|
||||
EntityViewDisplay::load('user.user.default')->setComponent('user_picture', [
|
||||
'region' => 'content',
|
||||
'type' => 'dummy_image_formatter',
|
||||
])->save();
|
||||
$this->drupalLogin($this->webUser);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextContains('Dummy');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,10 @@ class UserRoleAdminTest extends BrowserTestBase {
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->adminUser = $this->drupalCreateUser(['administer permissions', 'administer users']);
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'administer permissions',
|
||||
'administer users',
|
||||
]);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,10 @@ class UserRolesAssignmentTest extends BrowserTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$admin_user = $this->drupalCreateUser(['administer permissions', 'administer users']);
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer permissions',
|
||||
'administer users',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ class UserSearchTest extends BrowserTestBase {
|
||||
// Verify that a user without 'administer users' permission cannot search
|
||||
// for users by email address. Additionally, ensure that the username has a
|
||||
// plus sign to ensure searching works with that.
|
||||
$user1 = $this->drupalCreateUser(['access user profiles', 'search content'], "foo+bar");
|
||||
$user1 = $this->drupalCreateUser([
|
||||
'access user profiles',
|
||||
'search content',
|
||||
], "foo+bar");
|
||||
$this->drupalLogin($user1);
|
||||
$keys = $user1->getEmail();
|
||||
$edit = ['keys' => $keys];
|
||||
@@ -46,23 +49,27 @@ class UserSearchTest extends BrowserTestBase {
|
||||
$keys = $user1->getAccountName();
|
||||
$edit = ['keys' => $keys];
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertLink($keys, 0, 'Search by username worked for non-admin user');
|
||||
$this->assertSession()->linkExists($keys, 0, 'Search by username worked for non-admin user');
|
||||
|
||||
// Verify that searching by sub-string works too.
|
||||
$subkey = substr($keys, 1, 5);
|
||||
$edit = ['keys' => $subkey];
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertLink($keys, 0, 'Search by username substring worked for non-admin user');
|
||||
$this->assertSession()->linkExists($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 = ['keys' => $subkey];
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertLink($keys, 0, 'Search with wildcard worked for non-admin user');
|
||||
$this->assertSession()->linkExists($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(['administer users', 'access user profiles', 'search content']);
|
||||
$user2 = $this->drupalCreateUser([
|
||||
'administer users',
|
||||
'access user profiles',
|
||||
'search content',
|
||||
]);
|
||||
$this->drupalLogin($user2);
|
||||
$keys = $user2->getEmail();
|
||||
$edit = ['keys' => $keys];
|
||||
|
||||
@@ -56,7 +56,9 @@ abstract class AccessTestBase extends UserTestBase {
|
||||
$this->webRole = $roles[0];
|
||||
|
||||
$this->normalRole = $this->drupalCreateRole([]);
|
||||
$this->normalUser = $this->drupalCreateUser(['views_test_data test permission']);
|
||||
$this->normalUser = $this->drupalCreateUser([
|
||||
'views_test_data test permission',
|
||||
]);
|
||||
$this->normalUser->addRole($this->normalRole);
|
||||
$this->normalUser->save();
|
||||
// @todo when all the plugin information is cached make a reset function and
|
||||
|
||||
@@ -114,7 +114,11 @@ class BulkFormTest extends UserTestBase {
|
||||
$this->assertTrue($anonymous_account->isBlocked(), 'Ensure the anonymous user got blocked.');
|
||||
|
||||
// Test the list of available actions with a value that contains a dot.
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer permissions', 'administer views', 'administer users']));
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'administer permissions',
|
||||
'administer views',
|
||||
'administer users',
|
||||
]));
|
||||
$action_id = 'user_add_role_action.' . $role;
|
||||
$edit = [
|
||||
'options[include_exclude]' => 'exclude',
|
||||
|
||||
@@ -43,12 +43,15 @@ class FilterPermissionUiTest extends ViewTestBase {
|
||||
* Tests basic filter handler settings in the UI.
|
||||
*/
|
||||
public function testHandlerUI() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer views', 'administer users']));
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'administer views',
|
||||
'administer users',
|
||||
]));
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_filter_permission/edit/default');
|
||||
// Verify that the handler summary is correctly displaying the selected
|
||||
// permission.
|
||||
$this->assertLink('User: Permission (= View user information)');
|
||||
$this->assertSession()->linkExists('User: Permission (= View user information)');
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
// Verify that we can save the view.
|
||||
$this->assertNoText('No valid values found on filter: User: Permission.');
|
||||
@@ -63,7 +66,7 @@ class FilterPermissionUiTest extends ViewTestBase {
|
||||
],
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_permission/default/filter/permission', $edit, 'Apply');
|
||||
$this->assertLink('User: Permission (or View us…)');
|
||||
$this->assertSession()->linkExists('User: Permission (or View us…)');
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
// Verify that we can save the view.
|
||||
$this->assertNoText('No valid values found on filter: User: Permission.');
|
||||
|
||||
@@ -90,7 +90,10 @@ class HandlerFilterUserNameTest extends ViewTestBase {
|
||||
* Tests using the user interface.
|
||||
*/
|
||||
public function testAdminUserInterface() {
|
||||
$admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer views',
|
||||
'administer site configuration',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$path = 'admin/structure/views/nojs/handler/test_user_name/default/filter/uid';
|
||||
|
||||
@@ -96,24 +96,24 @@ class TempStoreDatabaseTest extends KernelTestBase {
|
||||
$this->assertEqual(!$i, $stores[0]->setIfNotExists($key, $this->objects[$i]));
|
||||
$metadata = $stores[0]->getMetadata($key);
|
||||
$this->assertEqual($users[0], $metadata->owner);
|
||||
$this->assertIdenticalObject($this->objects[0], $stores[0]->get($key));
|
||||
$this->assertEquals($this->objects[0], $stores[0]->get($key));
|
||||
// Another user should get the same result.
|
||||
$metadata = $stores[1]->getMetadata($key);
|
||||
$this->assertEqual($users[0], $metadata->owner);
|
||||
$this->assertIdenticalObject($this->objects[0], $stores[1]->get($key));
|
||||
$this->assertEquals($this->objects[0], $stores[1]->get($key));
|
||||
}
|
||||
|
||||
// Remove the item and try to set it again.
|
||||
$stores[0]->delete($key);
|
||||
$stores[0]->setIfNotExists($key, $this->objects[1]);
|
||||
// This time it should succeed.
|
||||
$this->assertIdenticalObject($this->objects[1], $stores[0]->get($key));
|
||||
$this->assertEquals($this->objects[1], $stores[0]->get($key));
|
||||
|
||||
// This user can update the object.
|
||||
$stores[0]->set($key, $this->objects[2]);
|
||||
$this->assertIdenticalObject($this->objects[2], $stores[0]->get($key));
|
||||
$this->assertEquals($this->objects[2], $stores[0]->get($key));
|
||||
// The object is the same when another user loads it.
|
||||
$this->assertIdenticalObject($this->objects[2], $stores[1]->get($key));
|
||||
$this->assertEquals($this->objects[2], $stores[1]->get($key));
|
||||
|
||||
// This user should be allowed to get, update, delete.
|
||||
$this->assertTrue($stores[0]->getIfOwner($key) instanceof \stdClass);
|
||||
@@ -122,8 +122,8 @@ class TempStoreDatabaseTest extends KernelTestBase {
|
||||
|
||||
// Another user can update the object and become the owner.
|
||||
$stores[1]->set($key, $this->objects[3]);
|
||||
$this->assertIdenticalObject($this->objects[3], $stores[0]->get($key));
|
||||
$this->assertIdenticalObject($this->objects[3], $stores[1]->get($key));
|
||||
$this->assertEquals($this->objects[3], $stores[0]->get($key));
|
||||
$this->assertEquals($this->objects[3], $stores[1]->get($key));
|
||||
$metadata = $stores[1]->getMetadata($key);
|
||||
$this->assertEqual($users[1], $metadata->owner);
|
||||
|
||||
|
||||
@@ -135,9 +135,6 @@ class UserAccountFormFieldsTest extends KernelTestBase {
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($entity_type)
|
||||
->create($fields);
|
||||
$this->container->get('entity_type.manager')
|
||||
->getFormObject($entity_type, $operation)
|
||||
->setEntity($entity);
|
||||
|
||||
// @see EntityFormBuilder::getForm()
|
||||
return $this->container->get('entity.form_builder')->getForm($entity, $operation);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\user\Kernel;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
@@ -33,22 +32,22 @@ class UserInstallTest extends KernelTestBase {
|
||||
* Test that the initial users have correct values.
|
||||
*/
|
||||
public function testUserInstall() {
|
||||
$result = Database::getConnection()->query('SELECT u.uid, u.uuid, u.langcode, uf.status FROM {users} u INNER JOIN {users_field_data} uf ON u.uid=uf.uid ORDER BY u.uid')
|
||||
->fetchAllAssoc('uid');
|
||||
$anon = $result[0];
|
||||
$admin = $result[1];
|
||||
$this->assertFalse(empty($anon->uuid), 'Anon user has a UUID');
|
||||
$this->assertFalse(empty($admin->uuid), 'Admin user has a UUID');
|
||||
$user_ids = \Drupal::entityQuery('user')->sort('uid')->execute();
|
||||
$users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple($user_ids);
|
||||
$anon = $users[0];
|
||||
$admin = $users[1];
|
||||
$this->assertNotEmpty($anon->uuid(), 'Anon user has a UUID');
|
||||
$this->assertNotEmpty($admin->uuid(), 'Admin user has a UUID');
|
||||
|
||||
// Test that the anonymous and administrators languages are equal to the
|
||||
// site's default language.
|
||||
$this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->getId());
|
||||
$this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->getId());
|
||||
$this->assertEquals('en', $anon->language()->getId());
|
||||
$this->assertEquals('en', $admin->language()->getId());
|
||||
|
||||
// Test that the administrator is active.
|
||||
$this->assertEqual($admin->status, 1);
|
||||
$this->assertTrue($admin->isActive());
|
||||
// Test that the anonymous user is blocked.
|
||||
$this->assertEqual($anon->status, 0);
|
||||
$this->assertTrue($anon->isBlocked());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user