ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
PasswordContraintsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
24 class PasswordContraintsTest extends TestCase
25 {
31  public static function constraintsProvider(): array
32  {
33  $lng = new class () implements \ILIAS\Language\Language {
34  public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string
35  {
36  return $a_topic;
37  }
38  public function loadLanguageModule(string $a_module): void
39  {
40  }
41  };
42  $d = new \ILIAS\Data\Factory();
43  $refinery = new \ILIAS\Refinery\Factory($d, $lng);
44  $v = $refinery->password();
45 
46  return [
47  [
48  $v->hasMinLength(3),
49  [$d->password('abc'), $d->password('abcd')],
50  [$d->password('a'), $d->password('ab')]
51  ],
52  [
53  $v->hasLowerChars(),
54  [$d->password('abc'), $d->password('AbC')],
55  [$d->password('AB'), $d->password('21'), $d->password('#*+')]
56  ],
57 
58  [
59  $v->hasUpperChars(),
60  [$d->password('Abc'), $d->password('ABC')],
61  [$d->password('abc'), $d->password('21'), $d->password('#*+')]
62  ],
63  [
64  $v->hasNumbers(),
65  [$d->password('Ab1'), $d->password('123')],
66  [$d->password('abc'), $d->password('ABC'), $d->password('#*+')]
67  ],
68 
69  [
70  $v->hasSpecialChars(),
71  [$d->password('Ab+'), $d->password('123#')],
72  [$d->password('abc'), $d->password('ABC'), $d->password('123')]
73  ]
74  ];
75  }
76 
83  public function testAccept(Constraint $constraint, array $ok_values, array $error_values): void
84  {
85  foreach ($ok_values as $ok_value) {
86  $this->assertTrue($constraint->accepts($ok_value));
87  }
88  foreach ($error_values as $error_value) {
89  $this->assertFalse($constraint->accepts($error_value));
90  }
91  }
92 }
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)
constraintsProvider
accepts($value)
Tells if the provided value complies.
global $lng
Definition: privfeed.php:32