UserEditedOwnAccountTest.php in Drupal 8        
                          
                  
                        
  
  
  
  
File
  core/modules/user/tests/src/Functional/UserEditedOwnAccountTest.php
  
    View source  
  <?php
namespace Drupal\Tests\user\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\UserInterface;
class UserEditedOwnAccountTest extends BrowserTestBase {
  
  protected $defaultTheme = 'stark';
  public function testUserEditedOwnAccount() {
    
    $this
      ->config('user.settings')
      ->set('register', UserInterface::REGISTER_ADMINISTRATORS_ONLY)
      ->save();
    
    $account = $this
      ->drupalCreateUser([
      'change own username',
    ]);
    $this
      ->drupalLogin($account);
    
    $edit = [];
    $edit['name'] = $this
      ->randomMachineName();
    $this
      ->drupalPostForm('user/' . $account
      ->id() . '/edit', $edit, t('Save'));
    
    $this
      ->drupalLogout();
    
    $account->name = $edit['name'];
    $this
      ->drupalLogin($account);
  }
}