View source
<?php
namespace Drupal\Tests\rpt\Kernel;
use Drupal\Core\Form\FormState;
use Drupal\KernelTests\KernelTestBase;
class RptTestUserInput extends KernelTestBase {
public static $modules = [
'rpt',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
\Drupal::service('router.builder')
->rebuild();
$configFactory = \Drupal::service('config.factory');
$configFactory
->getEditable('user.settings')
->set('verify_mail', FALSE)
->save();
$configFactory
->getEditable('rpt.settings')
->set('password_generate', FALSE)
->save();
}
public function testUserInputPassword($pass) {
$formBuilder = $this->container
->get('form_builder');
$entityTypeManager = $this->container
->get('entity_type.manager');
$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);
}
public function getUserInputPasswordData() {
return [
[
'fM4izYvqTS',
],
[
'CposTronfg',
],
[
'cGZ2oNAAut',
],
[
'3gbi2ztqfC',
],
[
'PeaTAwNreX',
],
];
}
}