1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DeGraciaMathieu\Riddler\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use DeGraciaMathieu\Riddler\Formats; |
7
|
|
|
use DeGraciaMathieu\Riddler\Criteria; |
8
|
|
|
use DeGraciaMathieu\Riddler\Password; |
9
|
|
|
use DeGraciaMathieu\Riddler\Occurrences; |
10
|
|
|
use DeGraciaMathieu\Riddler\Dictionaries; |
11
|
|
|
|
12
|
|
|
class IntegrationTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** @test */ |
15
|
|
|
public function emptyPassword() |
16
|
|
|
{ |
17
|
|
|
$pw = new Password(); |
18
|
|
|
|
19
|
|
|
$str = $pw->generate(); |
20
|
|
|
|
21
|
|
|
$this->assertEmpty($str); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** @test */ |
25
|
|
View Code Duplication |
public function letterPasswordOnly() |
26
|
|
|
{ |
27
|
|
|
$pw = new Password(); |
28
|
|
|
|
29
|
|
|
$pw->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(10)); |
30
|
|
|
|
31
|
|
|
$str = $pw->generate(); |
32
|
|
|
|
33
|
|
|
$this->assertNotEmpty($str); |
34
|
|
|
|
35
|
|
|
$this->assertRegExp('/[a-z]/', $str); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** @test */ |
39
|
|
|
public function alphanumericPasswordOnly() |
40
|
|
|
{ |
41
|
|
|
$pw = new Password(); |
42
|
|
|
|
43
|
|
|
$pw->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(5)); |
44
|
|
|
$pw->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(5)); |
45
|
|
|
$pw->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(5)); |
46
|
|
|
|
47
|
|
|
$str = $pw->generate(); |
48
|
|
|
|
49
|
|
|
$this->assertNotEmpty($str); |
50
|
|
|
|
51
|
|
|
$this->assertSame(15, mb_strlen($str)); |
52
|
|
|
|
53
|
|
|
$this->assertRegExp('/[a-zA-Z0-9]/', $str); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** @test */ |
57
|
|
View Code Duplication |
public function accentedLetterOnly() |
58
|
|
|
{ |
59
|
|
|
$pw = new Password(); |
60
|
|
|
|
61
|
|
|
$accentedLetter = new Dictionaries\AccentedLetter(); |
62
|
|
|
|
63
|
|
|
$pw->addCriteria($accentedLetter, new Occurrences\Strict(5)); |
64
|
|
|
|
65
|
|
|
$str = $pw->generate(); |
66
|
|
|
|
67
|
|
|
$this->assertNotEmpty($str); |
68
|
|
|
|
69
|
|
|
$this->assertRegExp('/[' . implode($accentedLetter->handle()) . ']{5}/', $str); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** @test */ |
73
|
|
View Code Duplication |
public function accentedUppercaseLetterOnly() |
74
|
|
|
{ |
75
|
|
|
$pw = new Password(); |
76
|
|
|
|
77
|
|
|
$accentedUppercaseLetter = new Dictionaries\AccentedUppercaseLetter(); |
78
|
|
|
|
79
|
|
|
$pw->addCriteria($accentedUppercaseLetter, new Occurrences\Strict(5)); |
80
|
|
|
|
81
|
|
|
$str = $pw->generate(); |
82
|
|
|
|
83
|
|
|
$this->assertNotEmpty($str); |
84
|
|
|
|
85
|
|
|
$this->assertRegExp('/[' . implode($accentedUppercaseLetter->handle()) . ']{5}/', $str); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** @test */ |
89
|
|
|
public function specialCharacterOnly() |
90
|
|
|
{ |
91
|
|
|
$pw = new Password(); |
92
|
|
|
|
93
|
|
|
$specialCharacter = new Dictionaries\SpecialCharacter(); |
94
|
|
|
|
95
|
|
|
$pw->addCriteria($specialCharacter, new Occurrences\Strict(5)); |
96
|
|
|
|
97
|
|
|
$str = $pw->generate(); |
98
|
|
|
|
99
|
|
|
$this->assertNotEmpty($str); |
100
|
|
|
|
101
|
|
|
$chars = array_map(function ($c) { |
102
|
|
|
return '\\' . $c; |
103
|
|
|
}, $specialCharacter->handle()); |
104
|
|
|
|
105
|
|
|
$this->assertRegExp('/[' . implode($chars) . ']{5}/', $str); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** @test */ |
109
|
|
|
public function longDigitFormatOnly() |
110
|
|
|
{ |
111
|
|
|
$pw = new Password(); |
112
|
|
|
|
113
|
|
|
$pw->addFormat(new Formats\LongDigit()); |
114
|
|
|
|
115
|
|
|
$str = $pw->generate(); |
116
|
|
|
|
117
|
|
|
$this->assertNotEmpty($str); |
118
|
|
|
|
119
|
|
|
$this->assertRegExp('/\d{30}/', $str); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** @test */ |
123
|
|
View Code Duplication |
public function smallAlphanumericFormatOnly() |
124
|
|
|
{ |
125
|
|
|
$pw = new Password(); |
126
|
|
|
|
127
|
|
|
$pw->addFormat(new Formats\SmallAlphanumeric()); |
128
|
|
|
|
129
|
|
|
$str = $pw->generate(); |
130
|
|
|
|
131
|
|
|
$this->assertNotEmpty($str); |
132
|
|
|
|
133
|
|
|
$this->assertSame(15, mb_strlen($str)); |
134
|
|
|
|
135
|
|
|
$this->assertRegExp('/[a-zA-Z0-9]/', $str); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** @test */ |
139
|
|
View Code Duplication |
public function strongAlphanumericFormatOnly() |
140
|
|
|
{ |
141
|
|
|
$pw = new Password(); |
142
|
|
|
|
143
|
|
|
$pw->addFormat(new Formats\StrongAlphanumeric()); |
144
|
|
|
|
145
|
|
|
$str = $pw->generate(); |
146
|
|
|
|
147
|
|
|
$this->assertNotEmpty($str); |
148
|
|
|
|
149
|
|
|
$this->assertSame(30, mb_strlen($str)); |
150
|
|
|
|
151
|
|
|
$this->assertRegExp('/[a-zA-Z0-9]/', $str); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** @test */ |
155
|
|
|
public function mixedStrongFormatOnly() |
156
|
|
|
{ |
157
|
|
|
$pw = new Password(); |
158
|
|
|
|
159
|
|
|
$pw->addFormat(new Formats\MixedStrong()); |
160
|
|
|
|
161
|
|
|
$str = $pw->generate(); |
162
|
|
|
|
163
|
|
|
$this->assertNotEmpty($str); |
164
|
|
|
|
165
|
|
|
// $this->assertEquals(30, mb_strlen($str)); |
166
|
|
|
|
167
|
|
|
// $this->assertRegExp('/[a-zA-Z0-9]/', $str); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** @test */ |
171
|
|
|
public function mixedComplexFormatOnly() |
172
|
|
|
{ |
173
|
|
|
$pw = new Password(); |
174
|
|
|
|
175
|
|
|
$pw->addFormat(new Formats\MixedComplex()); |
176
|
|
|
|
177
|
|
|
$str = $pw->generate(); |
178
|
|
|
|
179
|
|
|
$this->assertNotEmpty($str); |
180
|
|
|
|
181
|
|
|
// $this->assertEquals(30, mb_strlen($str)); |
182
|
|
|
|
183
|
|
|
// $this->assertRegExp('/[a-zA-Z0-9]/', $str); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
/** @test */ |
188
|
|
View Code Duplication |
public function digitPasswordOnly() |
189
|
|
|
{ |
190
|
|
|
$pw = new Password(); |
191
|
|
|
|
192
|
|
|
$pw->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(10)); |
193
|
|
|
|
194
|
|
|
$str = $pw->generate(); |
195
|
|
|
|
196
|
|
|
$this->assertNotEmpty($str); |
197
|
|
|
|
198
|
|
|
$this->assertRegExp('/\d{10}/', $str); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** @test */ |
202
|
|
|
public function strictOccurrences() |
203
|
|
|
{ |
204
|
|
|
$dictionary = new Dictionaries\Letter(); |
205
|
|
|
|
206
|
|
|
$occurrence = new Occurrences\Strict(5); |
207
|
|
|
|
208
|
|
|
$criteria = new Criteria(null, $dictionary, $occurrence); |
209
|
|
|
|
210
|
|
|
$result = $criteria->build(); |
211
|
|
|
|
212
|
|
|
$this->assertInternalType('array', $result); |
213
|
|
|
$this->assertCount(5, $result); |
214
|
|
|
$this->assertContains($result[0], $dictionary->handle()); |
215
|
|
|
$this->assertContains($result[1], $dictionary->handle()); |
216
|
|
|
$this->assertContains($result[2], $dictionary->handle()); |
217
|
|
|
$this->assertContains($result[3], $dictionary->handle()); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** @test */ |
221
|
|
|
public function betweenOccurrences() |
222
|
|
|
{ |
223
|
|
|
$dictionary = new Dictionaries\Letter(); |
224
|
|
|
|
225
|
|
|
$occurrence = new Occurrences\Between(3, 5); |
226
|
|
|
|
227
|
|
|
$criteria = new Criteria(null, $dictionary, $occurrence); |
228
|
|
|
|
229
|
|
|
$result = $criteria->build(); |
230
|
|
|
|
231
|
|
|
$this->assertInternalType('array', $result); |
232
|
|
|
$this->assertGreaterThanOrEqual(3, count($result)); |
233
|
|
|
$this->assertLessThanOrEqual(5, count($result)); |
234
|
|
|
$this->assertContains($result[0], $dictionary->handle()); |
235
|
|
|
$this->assertContains($result[1], $dictionary->handle()); |
236
|
|
|
$this->assertContains($result[2], $dictionary->handle()); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** @test */ |
240
|
|
View Code Duplication |
public function simpleStrictPerfectScore() |
241
|
|
|
{ |
242
|
|
|
$string = '1a2b3c'; |
243
|
|
|
|
244
|
|
|
$password = new Password(); |
245
|
|
|
|
246
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
247
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(3)); |
248
|
|
|
|
249
|
|
|
$this->assertSame(100, $password->score($string)); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** @test */ |
253
|
|
View Code Duplication |
public function simpleBetweenPerfectScore() |
254
|
|
|
{ |
255
|
|
|
$string = '1a2b3c4'; |
256
|
|
|
|
257
|
|
|
$password = new Password(); |
258
|
|
|
|
259
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Between(3, 5)); |
260
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5)); |
261
|
|
|
|
262
|
|
|
$this->assertSame(100, $password->score($string)); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** @test */ |
266
|
|
View Code Duplication |
public function simpleMixedPerfectScore() |
267
|
|
|
{ |
268
|
|
|
$string = '1a2b3cde'; |
269
|
|
|
|
270
|
|
|
$password = new Password(); |
271
|
|
|
|
272
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
273
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5)); |
274
|
|
|
|
275
|
|
|
$this->assertSame(100, $password->score($string)); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** @test */ |
279
|
|
View Code Duplication |
public function simpleMixedIncompleteScore() |
280
|
|
|
{ |
281
|
|
|
$string = '1a2bc'; |
282
|
|
|
|
283
|
|
|
$password = new Password(); |
284
|
|
|
|
285
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
286
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5)); |
287
|
|
|
|
288
|
|
|
$this->assertSame(50, $password->score($string)); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** @test */ |
292
|
|
View Code Duplication |
public function complexStrictPerfectScore() |
293
|
|
|
{ |
294
|
|
|
$string = '123abcABC[&+àáâÀÁÂ'; |
295
|
|
|
|
296
|
|
|
$password = new Password(); |
297
|
|
|
|
298
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
299
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(3)); |
300
|
|
|
$password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(3)); |
301
|
|
|
$password->addCriteria(new Dictionaries\SpecialCharacter(), new Occurrences\Strict(3)); |
302
|
|
|
$password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(3)); |
303
|
|
|
$password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(3)); |
304
|
|
|
|
305
|
|
|
$this->assertSame(100, $password->score($string)); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** @test */ |
309
|
|
View Code Duplication |
public function complexStrictIncompleteScore() |
310
|
|
|
{ |
311
|
|
|
$string = '12abcAB[&+àáâÀÁÂ'; |
312
|
|
|
|
313
|
|
|
$password = new Password(); |
314
|
|
|
|
315
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
316
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(3)); |
317
|
|
|
$password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(3)); |
318
|
|
|
$password->addCriteria(new Dictionaries\SpecialCharacter(), new Occurrences\Strict(3)); |
319
|
|
|
$password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(3)); |
320
|
|
|
$password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(3)); |
321
|
|
|
|
322
|
|
|
$this->assertSame(67, $password->score($string)); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** @test */ |
326
|
|
View Code Duplication |
public function complexMixedPerfectScore() |
327
|
|
|
{ |
328
|
|
|
$string = '123abcdEFG[&+éèàÒÓÔ'; |
329
|
|
|
|
330
|
|
|
$password = new Password(); |
331
|
|
|
|
332
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
333
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5)); |
334
|
|
|
$password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(3)); |
335
|
|
|
$password->addCriteria(new Dictionaries\SpecialCharacter(), new Occurrences\Between(3, 5)); |
336
|
|
|
$password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(3)); |
337
|
|
|
$password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Between(3, 5)); |
338
|
|
|
|
339
|
|
|
$this->assertSame(100, $password->score($string)); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** @test */ |
343
|
|
|
public function checkLettersParticularities() |
344
|
|
|
{ |
345
|
|
|
$string = 'eaEAéèàÉÈÀ'; |
346
|
|
|
|
347
|
|
|
$password = new Password(); |
348
|
|
|
|
349
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(2)); |
350
|
|
|
$password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(2)); |
351
|
|
|
$password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(3)); |
352
|
|
|
$password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(3)); |
353
|
|
|
|
354
|
|
|
$this->assertSame(100, $password->score($string)); |
355
|
|
|
|
356
|
|
|
$string = 'ea'; |
357
|
|
|
|
358
|
|
|
$password = new Password(); |
359
|
|
|
|
360
|
|
|
$password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(2)); |
361
|
|
|
$password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(2)); |
362
|
|
|
$password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(2)); |
363
|
|
|
|
364
|
|
|
$this->assertSame($password->score($string), 0); |
365
|
|
|
|
366
|
|
|
$string = 'EA'; |
367
|
|
|
|
368
|
|
|
$password = new Password(); |
369
|
|
|
|
370
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(2)); |
371
|
|
|
$password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(2)); |
372
|
|
|
$password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(2)); |
373
|
|
|
|
374
|
|
|
$this->assertSame($password->score($string), 0); |
375
|
|
|
|
376
|
|
|
$string = 'éèà'; |
377
|
|
|
|
378
|
|
|
$password = new Password(); |
379
|
|
|
|
380
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(2)); |
381
|
|
|
$password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(2)); |
382
|
|
|
$password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(2)); |
383
|
|
|
|
384
|
|
|
$this->assertSame($password->score($string), 0); |
385
|
|
|
|
386
|
|
|
$string = 'ÉÈÀ'; |
387
|
|
|
|
388
|
|
|
$password = new Password(); |
389
|
|
|
|
390
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(2)); |
391
|
|
|
$password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(2)); |
392
|
|
|
$password->addCriteria(new Dictionaries\AccentedLetter(), new Occurrences\Strict(2)); |
393
|
|
|
|
394
|
|
|
$this->assertSame($password->score($string), 0); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** @test */ |
398
|
|
|
public function generatePasswordWithNoneOccurrence() |
399
|
|
|
{ |
400
|
|
|
$password = new Password(); |
401
|
|
|
|
402
|
|
|
$digit = new Dictionaries\Digit(); |
403
|
|
|
$letter = new Dictionaries\Letter(); |
404
|
|
|
|
405
|
|
|
$password->addCriteria($digit, new Occurrences\Strict(3)); |
406
|
|
|
$password->addCriteria($letter, new Occurrences\None()); |
407
|
|
|
|
408
|
|
|
$str = $password->generate(); |
409
|
|
|
|
410
|
|
|
$this->assertNotEmpty($str); |
411
|
|
|
|
412
|
|
|
$this->assertSame(3, mb_strlen($str)); |
413
|
|
|
|
414
|
|
|
$this->assertRegExp('/[' . implode($digit->handle()) . ']{3}/', $str); |
415
|
|
|
$this->assertRegExp('/[' . implode($letter->handle()) . ']{0}/', $str); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** @test */ |
419
|
|
View Code Duplication |
public function passwordWithoutLetterOk() |
420
|
|
|
{ |
421
|
|
|
$string = '0123'; |
422
|
|
|
|
423
|
|
|
$password = new Password(); |
424
|
|
|
|
425
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\None()); |
426
|
|
|
|
427
|
|
|
$this->assertSame(100, $password->score($string)); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** @test */ |
431
|
|
View Code Duplication |
public function passwordWithoutLetterFail() |
432
|
|
|
{ |
433
|
|
|
$string = '0123a'; |
434
|
|
|
|
435
|
|
|
$password = new Password(); |
436
|
|
|
|
437
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\None()); |
438
|
|
|
|
439
|
|
|
$this->assertSame(0, $password->score($string)); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** @test */ |
443
|
|
|
public function criteriaWithName() |
444
|
|
|
{ |
445
|
|
|
$dictionary = new Dictionaries\Letter(); |
446
|
|
|
|
447
|
|
|
$occurrence = new Occurrences\Strict(5); |
448
|
|
|
|
449
|
|
|
$criteria = new Criteria('name', $dictionary, $occurrence); |
450
|
|
|
|
451
|
|
|
$this->assertSame('name', $criteria->getName()); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** @test */ |
455
|
|
|
public function criteriaWithDefaultName() |
456
|
|
|
{ |
457
|
|
|
$dictionary = new Dictionaries\Letter(); |
458
|
|
|
|
459
|
|
|
$occurrence = new Occurrences\Strict(5); |
460
|
|
|
|
461
|
|
|
$criteria = new Criteria(null, $dictionary, $occurrence); |
462
|
|
|
|
463
|
|
|
$this->assertEquals($criteria->getName(), 'letter_strict_5'); |
464
|
|
|
|
465
|
|
|
$dictionary = new Dictionaries\Digit(); |
466
|
|
|
|
467
|
|
|
$occurrence = new Occurrences\Between(1, 5); |
468
|
|
|
|
469
|
|
|
$criteria = new Criteria(null, $dictionary, $occurrence); |
470
|
|
|
|
471
|
|
|
$this->assertEquals($criteria->getName(), 'digit_between_1_5'); |
472
|
|
|
|
473
|
|
|
$dictionary = new Dictionaries\UppercaseLetter(); |
474
|
|
|
|
475
|
|
|
$occurrence = new Occurrences\None(); |
476
|
|
|
|
477
|
|
|
$criteria = new Criteria(null, $dictionary, $occurrence); |
478
|
|
|
|
479
|
|
|
$this->assertEquals($criteria->getName(), 'uppercaseletter_none'); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** @test */ |
483
|
|
View Code Duplication |
public function simpleStrictPerfectPassed() |
484
|
|
|
{ |
485
|
|
|
$string = '1a2b3c'; |
486
|
|
|
|
487
|
|
|
$password = new Password(); |
488
|
|
|
|
489
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
490
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Strict(3)); |
491
|
|
|
|
492
|
|
|
$expectedArray = [ |
493
|
|
|
[ |
494
|
|
|
'name' => 'digit_strict_3', |
495
|
|
|
'passed' => true, |
496
|
|
|
], |
497
|
|
|
[ |
498
|
|
|
'name' => 'letter_strict_3', |
499
|
|
|
'passed' => true, |
500
|
|
|
], |
501
|
|
|
]; |
502
|
|
|
|
503
|
|
|
$this->assertEquals($expectedArray, $password->passed($string)); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** @test */ |
507
|
|
View Code Duplication |
public function simpleBetweenPerfectPassed() |
508
|
|
|
{ |
509
|
|
|
$string = '1a2b3c4'; |
510
|
|
|
|
511
|
|
|
$password = new Password(); |
512
|
|
|
|
513
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Between(3, 5)); |
514
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5)); |
515
|
|
|
|
516
|
|
|
$expectedArray = [ |
517
|
|
|
[ |
518
|
|
|
'name' => 'digit_between_3_5', |
519
|
|
|
'passed' => true, |
520
|
|
|
], |
521
|
|
|
[ |
522
|
|
|
'name' => 'letter_between_3_5', |
523
|
|
|
'passed' => true, |
524
|
|
|
], |
525
|
|
|
]; |
526
|
|
|
|
527
|
|
|
$this->assertEquals($expectedArray, $password->passed($string)); |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
/** @test */ |
531
|
|
|
public function mixedIncompletePassed() |
532
|
|
|
{ |
533
|
|
|
$string = '1a2bcABC[&+Ó'; |
534
|
|
|
|
535
|
|
|
$password = new Password(); |
536
|
|
|
|
537
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
538
|
|
|
$password->addCriteria(new Dictionaries\UppercaseLetter(), new Occurrences\Strict(3)); |
539
|
|
|
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 5)); |
540
|
|
|
$password->addCriteria(new Dictionaries\SpecialCharacter(), new Occurrences\Between(1, 2)); |
541
|
|
|
$password->addCriteria(new Dictionaries\AccentedUppercaseLetter(), new Occurrences\Strict(1)); |
542
|
|
|
|
543
|
|
|
$expectedArray = [ |
544
|
|
|
[ |
545
|
|
|
'name' => 'digit_strict_3', |
546
|
|
|
'passed' => false, |
547
|
|
|
], |
548
|
|
|
[ |
549
|
|
|
'name' => 'uppercaseletter_strict_3', |
550
|
|
|
'passed' => true, |
551
|
|
|
], |
552
|
|
|
[ |
553
|
|
|
'name' => 'letter_between_3_5', |
554
|
|
|
'passed' => true, |
555
|
|
|
], |
556
|
|
|
[ |
557
|
|
|
'name' => 'specialcharacter_between_1_2', |
558
|
|
|
'passed' => false, |
559
|
|
|
], |
560
|
|
|
[ |
561
|
|
|
'name' => 'accenteduppercaseletter_strict_1', |
562
|
|
|
'passed' => true, |
563
|
|
|
], |
564
|
|
|
]; |
565
|
|
|
|
566
|
|
|
$this->assertEquals($expectedArray, $password->passed($string)); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** @test */ |
570
|
|
View Code Duplication |
public function mixedPerfecPassedWithName() |
571
|
|
|
{ |
572
|
|
|
$string = '1a2b3c'; |
573
|
|
|
|
574
|
|
|
$password = new Password(); |
575
|
|
|
|
576
|
|
|
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(3)); |
577
|
|
|
$password->addNamedCriteria('name', new Dictionaries\Letter(), new Occurrences\Between(3, 5)); |
578
|
|
|
|
579
|
|
|
$expectedArray = [ |
580
|
|
|
[ |
581
|
|
|
'name' => 'digit_strict_3', |
582
|
|
|
'passed' => true, |
583
|
|
|
], |
584
|
|
|
[ |
585
|
|
|
'name' => 'name', |
586
|
|
|
'passed' => true, |
587
|
|
|
], |
588
|
|
|
]; |
589
|
|
|
|
590
|
|
|
$this->assertEquals($expectedArray, $password->passed($string)); |
591
|
|
|
} |
592
|
|
|
} |
593
|
|
|
|