ILIAS  release_8 Revision v8.24
PasswordContraintsTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22use PHPUnit\Framework\TestCase;
23
24class PasswordContraintsTest extends TestCase
25{
31 public function constraintsProvider(): array
32 {
33 $lng = $this->createMock(\ilLanguage::class);
34 $d = new \ILIAS\Data\Factory();
35 $refinery = new \ILIAS\Refinery\Factory($d, $lng);
36 $v = $refinery->password();
37
38 return [
39 [
40 $v->hasMinLength(3),
41 [$d->password('abc'), $d->password('abcd')],
42 [$d->password('a'), $d->password('ab')]
43 ],
44 [
45 $v->hasLowerChars(),
46 [$d->password('abc'), $d->password('AbC')],
47 [$d->password('AB'), $d->password('21'), $d->password('#*+')]
48 ],
49
50 [
51 $v->hasUpperChars(),
52 [$d->password('Abc'), $d->password('ABC')],
53 [$d->password('abc'), $d->password('21'), $d->password('#*+')]
54 ],
55 [
56 $v->hasNumbers(),
57 [$d->password('Ab1'), $d->password('123')],
58 [$d->password('abc'), $d->password('ABC'), $d->password('#*+')]
59 ],
60
61 [
62 $v->hasSpecialChars(),
63 [$d->password('Ab+'), $d->password('123#')],
64 [$d->password('abc'), $d->password('ABC'), $d->password('123')]
65 ]
66 ];
67 }
68
75 public function testAccept(Constraint $constraint, array $ok_values, array $error_values): void
76 {
77 foreach ($ok_values as $ok_value) {
78 $this->assertTrue($constraint->accepts($ok_value));
79 }
80 foreach ($error_values as $error_value) {
81 $this->assertFalse($constraint->accepts($error_value));
82 }
83 }
84}
password(string $pass)
Definition: Factory.php:98
testAccept(Constraint $constraint, array $ok_values, array $error_values)
@dataProvider constraintsProvider
constraintsProvider()
Test a set of values.
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
accepts($value)
Tells if the provided value complies.
Refinery Factory $refinery
$lng