ILIAS  release_7 Revision v7.30-3-g800a261c036
PasswordContraintsTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once("libs/composer/vendor/autoload.php");
6
8use ILIAS\Data;
9use PHPUnit\Framework\TestCase;
10
16class PasswordContraintsTest extends TestCase
17{
18
24 public function constraintsProvider()
25 {
26 $lng = $this->createMock(\ilLanguage::class);
27 $d = new \ILIAS\Data\Factory();
28 $refinery = new \ILIAS\Refinery\Factory($d, $lng);
29 $v = $refinery->password();
30
31 return array(
32 array(
33 $v->hasMinLength(3),
34 [$d->password('abc'), $d->password('abcd')],
35 [$d->password('a'), $d->password('ab')]
36 ),
37 array(
38 $v->hasLowerChars(),
39 [$d->password('abc'), $d->password('AbC')],
40 [$d->password('AB'), $d->password('21'), $d->password('#*+')]
41 ),
42
43 array(
44 $v->hasUpperChars(),
45 [$d->password('Abc'), $d->password('ABC')],
46 [$d->password('abc'), $d->password('21'), $d->password('#*+')]
47 ),
48 array(
49 $v->hasNumbers(),
50 [$d->password('Ab1'), $d->password('123')],
51 [$d->password('abc'), $d->password('ABC'), $d->password('#*+')]
52 ),
53
54 array(
55 $v->hasSpecialChars(),
56 [$d->password('Ab+'), $d->password('123#')],
57 [$d->password('abc'), $d->password('ABC'), $d->password('123')]
58 )
59 );
60 }
61
65 public function testAccept($constraint, $ok_values, $error_values)
66 {
67 foreach ($ok_values as $ok_value) {
68 $this->assertTrue($constraint->accepts($ok_value));
69 }
70 foreach ($error_values as $error_value) {
71 $this->assertFalse($constraint->accepts($error_value));
72 }
73 }
74}
An exception for terminatinating execution or to throw for unit testing.
Test standard-constraints of a password.
constraintsProvider()
Test a set of values.
testAccept($constraint, $ok_values, $error_values)
@dataProvider constraintsProvider
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$lng