@@ -344,6 +344,7 @@ public function testIntList()
344
344
$ this ->assertFalse (Validators::intList (['a ' => 'v ' ]));
345
345
$ this ->assertFalse (Validators::intList (['value ' , 'a ' => 'v ' ]));
346
346
$ this ->assertFalse (Validators::intList ([2 => '343 ' , 45 ]));
347
+ $ this ->assertFalse (Validators::intList ([45 , 2 => '343 ' ]));
347
348
348
349
$ this ->assertTrue (Validators::intList (['343 ' , 45 ]));
349
350
$ this ->assertTrue (Validators::intList ([565 , 3234 , -56 ]));
@@ -416,6 +417,22 @@ public function testDistinct()
416
417
$ this ->assertTrue (Validators::distinct (['a ' , 'b ' , 'c ' ]));
417
418
}
418
419
420
+ public function testInANDNotIn ()
421
+ {
422
+ $ samples = [
423
+ [true , 1 , [1 , 2 , 3 ], false ],
424
+ [true , 1 , [1 , 2 , 3 ], true ],
425
+ [true , '1 ' , [1 , 2 , 3 ], false ],
426
+ [false , '1 ' , [1 , 2 , 3 ], true ],
427
+ [true , '1 ' , '1,2,3 ' , true ],
428
+ ];
429
+
430
+ foreach ($ samples as list ($ want , $ val , $ dict , $ strict )) {
431
+ $ this ->assertSame ($ want , Validators::in ($ val , $ dict , $ strict ));
432
+ $ this ->assertSame (!$ want , Validators::notIn ($ val , $ dict , $ strict ));
433
+ }
434
+ }
435
+
419
436
public function testJson ()
420
437
{
421
438
$ this ->assertFalse (Validators::json ('test ' ));
@@ -446,7 +463,9 @@ public function testContains()
446
463
447
464
public function testStartWith ()
448
465
{
466
+ $ this ->assertFalse (Validators::startWith (null , 'ell ' ));
449
467
$ this ->assertFalse (Validators::startWith ('hello, world ' , 'ell ' ));
468
+ $ this ->assertFalse (Validators::startWith ('hello, world ' , '' ));
450
469
451
470
$ this ->assertTrue (Validators::startWith ('hello, world ' , 'hell ' ));
452
471
$ this ->assertTrue (Validators::startWith (['hello ' , 'world ' ], 'hello ' ));
@@ -460,21 +479,32 @@ public function testEndWith()
460
479
$ this ->assertTrue (Validators::endWith (['hello ' , 'world ' ], 'world ' ));
461
480
}
462
481
463
- public function testDate ()
482
+ public function testDateCheck ()
464
483
{
484
+ // date
465
485
$ this ->assertFalse (Validators::date ('hello ' ));
466
-
467
486
$ this ->assertTrue (Validators::date (170526 ));
468
487
$ this ->assertTrue (Validators::date ('20170526 ' ));
469
- }
470
488
471
- public function testDateCheck ()
472
- {
489
+ // dateEquals
490
+ $ this ->assertTrue (Validators::dateEquals ('20170526 ' , '20170526 ' ));
491
+ $ this ->assertTrue (Validators::dateEquals ('2017-05-26 ' , '20170526 ' ));
492
+ $ this ->assertFalse (Validators::dateEquals ('20170525 ' , '20170526 ' ));
493
+
473
494
// dateFormat
474
495
$ this ->assertFalse (Validators::dateFormat ('hello ' ));
475
496
$ this ->assertFalse (Validators::dateFormat ('170526 ' , 'ymd ' ));
476
497
$ this ->assertTrue (Validators::dateFormat ('20170526 ' , 'Ymd ' ));
477
498
499
+ // beforeDate
500
+ $ this ->assertTrue (Validators::beforeDate ('20170524 ' , '20170526 ' ));
501
+ $ this ->assertFalse (Validators::beforeDate ('20170526 ' , '20170526 ' ));
502
+
503
+ // beforeOrEqualDate
504
+ $ this ->assertTrue (Validators::beforeOrEqualDate ('20170524 ' , '20170526 ' ));
505
+ $ this ->assertTrue (Validators::beforeOrEqualDate ('20170526 ' , '20170526 ' ));
506
+ $ this ->assertFalse (Validators::beforeOrEqualDate ('20170527 ' , '20170526 ' ));
507
+
478
508
// afterDate
479
509
$ this ->assertTrue (Validators::afterDate ('20170526 ' , '20170524 ' ));
480
510
$ this ->assertFalse (Validators::afterDate ('20170526 ' , '20170526 ' ));
@@ -485,6 +515,13 @@ public function testDateCheck()
485
515
$ this ->assertTrue (Validators::afterOrEqualDate ('20170526 ' , '20170526 ' ));
486
516
$ this ->assertTrue (Validators::afterOrEqualDate ('20170526 ' , '20170524 ' ));
487
517
$ this ->assertFalse (Validators::afterOrEqualDate ('20170524 ' , '20170526 ' ));
518
+
519
+ // isDate
520
+ $ this ->assertTrue (Validators::isDate ('2017-05-26 ' ));
521
+ $ this ->assertFalse (Validators::isDate ('20170526 ' ));
522
+ // isDateFormat
523
+ $ this ->assertTrue (Validators::isDateFormat ('2017-05-26 ' ));
524
+ $ this ->assertFalse (Validators::isDateFormat ('20170526 ' ));
488
525
}
489
526
490
527
public function testPhone ()
@@ -502,6 +539,48 @@ public function testPostCode()
502
539
public function testPrice ()
503
540
{
504
541
$ this ->assertTrue (Validators::price ('610.45 ' ));
505
- $ this ->assertFalse (Validators::price ('-20170526 ' ));
542
+ $ this ->assertFalse (Validators::price ('-201.26 ' ));
543
+ $ this ->assertFalse (Validators::price ('abc ' ));
544
+
545
+ $ this ->assertTrue (Validators::negativePrice ('610.45 ' ));
546
+ $ this ->assertTrue (Validators::negativePrice ('-201.26 ' ));
547
+ $ this ->assertFalse (Validators::negativePrice ('abc ' ));
548
+ }
549
+
550
+ public function testOther ()
551
+ {
552
+ // isFloat
553
+ $ this ->assertFalse (Validators::isFloat ([]));
554
+ $ this ->assertFalse (Validators::isFloat ('abc ' ));
555
+ $ this ->assertTrue (Validators::isFloat ('23.34 ' ));
556
+ $ this ->assertTrue (Validators::isFloat ('-23.34 ' ));
557
+
558
+ // isUnsignedFloat
559
+ $ this ->assertTrue (Validators::isUnsignedFloat ('23.34 ' ));
560
+ $ this ->assertFalse (Validators::isUnsignedFloat ('-23.34 ' ));
561
+
562
+ // isInt
563
+ $ this ->assertTrue (Validators::isInt ('23 ' ));
564
+ $ this ->assertTrue (Validators::isInt ('-23 ' ));
565
+ $ this ->assertFalse (Validators::isInt ('-23.34 ' ));
566
+
567
+ // isUnsignedInt
568
+ $ this ->assertTrue (Validators::isUnsignedInt ('23 ' ));
569
+ $ this ->assertFalse (Validators::isUnsignedInt ('-23 ' ));
570
+ $ this ->assertFalse (Validators::isUnsignedInt ('-23.34 ' ));
571
+
572
+ // macAddress
573
+ $ this ->assertTrue (Validators::macAddress ('01:23:45:67:89:ab ' ));
574
+ $ this ->assertFalse (Validators::macAddress ([]));
575
+ $ this ->assertFalse (Validators::macAddress (null ));
576
+ $ this ->assertFalse (Validators::macAddress ('123 abc ' ));
577
+
578
+ // md5
579
+ $ this ->assertFalse (Validators::md5 ('123 abc ' ));
580
+ $ this ->assertFalse (Validators::md5 (true ));
581
+
582
+ // sha1
583
+ $ this ->assertFalse (Validators::sha1 (true ));
584
+ $ this ->assertFalse (Validators::sha1 ('123 abc ' ));
506
585
}
507
586
}
0 commit comments