You are here

public function RptTestUserInput::testUserInputPassword in Registration Password Token 8

Test predefined passwords.

@dataProvider getUserInputPasswordData

File

tests/src/Kernel/RptTestUserInput.php, line 47

Class

RptTestUserInput
Test RPT fully.

Namespace

Drupal\Tests\rpt\Kernel

Code

public function testUserInputPassword($pass) {

  /** @var \Drupal\Core\Form\FormBuilderInterface $formBuilder */
  $formBuilder = $this->container
    ->get('form_builder');

  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager */
  $entityTypeManager = $this->container
    ->get('entity_type.manager');

  /** @var \Drupal\Core\Utility\Token $entityTypeManager */
  $token = $this->container
    ->get('token');
  $entity = $entityTypeManager
    ->getStorage('user')
    ->create([]);
  $formObject = $entityTypeManager
    ->getFormObject('user', 'register')
    ->setEntity($entity);
  $formState = new FormState();
  $formObject
    ->buildForm([], $formState);
  $formState
    ->setValues([
    'mail' => 'test@example.com',
    'name' => 'test',
    'pass' => [
      'pass1' => $pass,
      'pass2' => $pass,
    ],
  ]);
  $formBuilder
    ->submitForm($formObject, $formState);
  $replacedToken = $token
    ->replace('[user:password]', [
    'user' => $formState
      ->getFormObject()
      ->getEntity(),
  ]);
  $this
    ->assertSame($pass, $replacedToken);
  $replacedToken = $token
    ->replace('[account:password]', [
    'user' => $formState
      ->getFormObject()
      ->getEntity(),
  ]);
  $this
    ->assertSame($pass, $replacedToken);
}