ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
PasswordContraintsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
32  public static function constraintsProvider(): array
33  {
34  $lng = new class () implements \ILIAS\Language\Language {
35  public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string
36  {
37  return $a_topic;
38  }
39  public function loadLanguageModule(string $a_module): void
40  {
41  }
42  public function getLangKey(): string
43  {
44  return '';
45  }
46  public function toJS($key): void
47  {
48  }
49  };
50  $d = new \ILIAS\Data\Factory();
51  $refinery = new \ILIAS\Refinery\Factory($d, $lng);
52  $v = $refinery->password();
53 
54  return [
55  [
56  $v->hasMinLength(3),
57  [$d->password('abc'), $d->password('abcd')],
58  [$d->password('a'), $d->password('ab')]
59  ],
60  [
61  $v->hasLowerChars(),
62  [$d->password('abc'), $d->password('AbC')],
63  [$d->password('AB'), $d->password('21'), $d->password('#*+')]
64  ],
65 
66  [
67  $v->hasUpperChars(),
68  [$d->password('Abc'), $d->password('ABC')],
69  [$d->password('abc'), $d->password('21'), $d->password('#*+')]
70  ],
71  [
72  $v->hasNumbers(),
73  [$d->password('Ab1'), $d->password('123')],
74  [$d->password('abc'), $d->password('ABC'), $d->password('#*+')]
75  ],
76 
77  [
78  $v->hasSpecialChars(),
79  [$d->password('Ab+'), $d->password('123#')],
80  [$d->password('abc'), $d->password('ABC'), $d->password('123')]
81  ]
82  ];
83  }
84 
90  #[DataProvider('constraintsProvider')]
91  public function testAccept(Constraint $constraint, array $ok_values, array $error_values): void
92  {
93  foreach ($ok_values as $ok_value) {
94  $this->assertTrue($constraint->accepts($ok_value));
95  }
96  foreach ($error_values as $error_value) {
97  $this->assertFalse($constraint->accepts($error_value));
98  }
99  }
100 }
static constraintsProvider()
Test a set of values.
Interface Observer Contains several chained tasks and infos about them.
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
testAccept(Constraint $constraint, array $ok_values, array $error_values)
accepts($value)
Tells if the provided value complies.
global $lng
Definition: privfeed.php:31