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