/**
* Fills out a user's personal contact form and submits it.
*
* @param \Drupal\Core\Session\AccountInterface $account
* A user object of the user being contacted.
* @param array $message
* (optional) An array with the form fields being used. Defaults to an empty
* array.
*
* @return array
* An array with the form fields being used.
*/
$this->drupalGet($langcode . '/admin/people/create'); $this->submitForm($edit, 'Create new account');
$user = user_load_by_name($username); $this->assertEquals($langcode, $user->getPreferredLangcode(), 'New user has correct preferred language set.'); $this->assertEquals($langcode, $user->language()->getId(), 'New user has correct profile language set.');
// Register a new user and check if the language selector is hidden.
$this->drupalLogout();
// triggered by drupalCreateUser).
$edit = []; $edit['name'] = $name; $edit['mail'] = $name . '@example.com'; $edit['pass[pass1]'] = $pass; $edit['pass[pass2]'] = $pass; $edit['status'] = 1; $this->drupalGet('admin/people/create'); $this->submitForm($edit, 'Create new account'); $this->assertSession()->statusCodeEquals(200); // Retrieve the user object.
$user = user_load_by_name($name); $this->assertNotNull($user, newFormattableMarkup('User @name was loaded', ['@name' => $name])); // pass_raw property is needed by drupalLogin.
$user->passRaw = $pass; // Log in user.
$this->drupalLogin($user); // Log out user.
$this->drupalLogout(); // Fetch the row IDs in watchdog that relate to the user.
$result = Database::getConnection()->select('watchdog', 'w')->fields('w', ['wid'])->condition('uid', $user->id())->execute(); foreach($resultas$row){ $ids[] = $row->wid; }
if($notify){ $this->assertSession()->pageTextContains('A welcome message with further instructions has been emailed to the new user ' . $edit['name'] . '.'); $this->assertCount(1, $this->drupalGetMails(), 'Notification email sent'); } else{ $this->assertSession()->pageTextContains('Created a new user account for ' . $edit['name'] . '. No email has been sent.'); $this->assertCount(0, $this->drupalGetMails(), 'Notification email not sent'); }
// Test that the password '0' is considered a password.
// @see https://www.drupal.org/node/2563751.
$name = $this->randomMachineName(); $edit = [ 'name' => $name, 'mail' => $this->randomMachineName() . '@example.com', 'pass[pass1]' => 0, 'pass[pass2]' => 0,
protectedfunctionregisterUser($name, $include_password = TRUE, $include_email = TRUE){ // Verify that an anonymous user can register.
$response = $this->registerRequest($name, $include_password, $include_email); $this->assertResourceResponse(200, FALSE, $response); $user = user_load_by_name($name); $this->assertNotEmpty($user, 'User was create as expected'); return$user; }
/**
* Make a REST user registration request.
*
* @param string $name
* The name.
* @param bool $include_password
* Include the password?
* @param bool $include_email
* Include the email?
*
* @return \Psr\Http\Message\ResponseInterface
* Return the Response.
*/