You are here

public function EmailRegistrationTestCase::testUsernamePermissions in Email Registration 8

Test the "change own username" permission and user edit save.

File

tests/src/Functional/EmailRegistrationTestCase.php, line 136

Class

EmailRegistrationTestCase
Tests the email registration module.

Namespace

Drupal\Tests\email_registration\Functional

Code

public function testUsernamePermissions() {

  // Set login_with_username to TRUE for $this->>drupalLogin.
  $this->container
    ->get('config.factory')
    ->getEditable('email_registration.settings')
    ->set('login_with_username', TRUE)
    ->save(TRUE);
  $user = $this
    ->createUser([
    'change own username',
  ]);
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('user/' . $user
    ->id() . '/edit');
  $this
    ->assertSession()
    ->fieldExists('edit-name');
  $this
    ->drupalLogout();
  $user = $this
    ->createUser();
  $username = $user
    ->getAccountName();
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('user/' . $user
    ->id() . '/edit');

  // Test that the field is set to type=value.
  $this
    ->assertSession()
    ->fieldNotExists('edit-name');
  $this
    ->assertSession()
    ->pageTextContains($username);

  // Make sure the email isn't changed on save.
  $this
    ->drupalPostForm('user/' . $user
    ->id() . '/edit', [], 'Save');
  $this
    ->assertSession()
    ->pageTextContains($username);
}