buildAccountForm example

// @todo: Replace with $request->getSession() as soon as the session is     // present in KernelTestBase.     // see: https://www.drupal.org/node/2484991     $session = new Session();
    $request->setSession($session);

    $token = 'VALID_TOKEN';
    $session->set('pass_reset_1', $token);

    // Set token in query string.     $request->query->set('pass-reset-token', $token);
    $form = $this->buildAccountForm('default');
    // User shouldn't see current password field.     $this->assertFalse($form['account']['current_pass']['#access']);

    $request->query->set('pass-reset-token', NULL);
    $request->attributes->set('pass-reset-token', $token);
    $form = $this->buildAccountForm('default');
    $this->assertTrue($form['account']['current_pass']['#access']);
  }

  /** * Builds the user account form for a given operation. * * @param string $operation * The entity operation; one of 'register' or 'default'. * * @return array * The form array. */

  public function testUserRegistrationForm() {
    // Install default configuration; required for AccountFormController.     $this->installConfig(['user']);

    // Disable email confirmation to unlock the password field.     $this->config('user.settings')
      ->set('verify_mail', FALSE)
      ->save();

    $form = $this->buildAccountForm('register');

    // Verify name and pass field order.     $this->assertFieldOrder($form['account']);

    // Verify that web browsers may autocomplete the email value and     // autofill/prefill the name and pass values.     foreach (['mail', 'name', 'pass'] as $key) {
      $this->assertFalse(isset($form['account'][$key]['#attributes']['autocomplete']), "'$key' field: 'autocomplete' attribute not found.");
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.