@@ -344,6 +344,7 @@ public function testIntList()
344344 $ this ->assertFalse (Validators::intList (['a ' => 'v ' ]));
345345 $ this ->assertFalse (Validators::intList (['value ' , 'a ' => 'v ' ]));
346346 $ this ->assertFalse (Validators::intList ([2 => '343 ' , 45 ]));
347+ $ this ->assertFalse (Validators::intList ([45 , 2 => '343 ' ]));
347348
348349 $ this ->assertTrue (Validators::intList (['343 ' , 45 ]));
349350 $ this ->assertTrue (Validators::intList ([565 , 3234 , -56 ]));
@@ -416,6 +417,22 @@ public function testDistinct()
416417 $ this ->assertTrue (Validators::distinct (['a ' , 'b ' , 'c ' ]));
417418 }
418419
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+
419436 public function testJson ()
420437 {
421438 $ this ->assertFalse (Validators::json ('test ' ));
@@ -446,7 +463,9 @@ public function testContains()
446463
447464 public function testStartWith ()
448465 {
466+ $ this ->assertFalse (Validators::startWith (null , 'ell ' ));
449467 $ this ->assertFalse (Validators::startWith ('hello, world ' , 'ell ' ));
468+ $ this ->assertFalse (Validators::startWith ('hello, world ' , '' ));
450469
451470 $ this ->assertTrue (Validators::startWith ('hello, world ' , 'hell ' ));
452471 $ this ->assertTrue (Validators::startWith (['hello ' , 'world ' ], 'hello ' ));
@@ -460,21 +479,32 @@ public function testEndWith()
460479 $ this ->assertTrue (Validators::endWith (['hello ' , 'world ' ], 'world ' ));
461480 }
462481
463- public function testDate ()
482+ public function testDateCheck ()
464483 {
484+ // date
465485 $ this ->assertFalse (Validators::date ('hello ' ));
466-
467486 $ this ->assertTrue (Validators::date (170526 ));
468487 $ this ->assertTrue (Validators::date ('20170526 ' ));
469- }
470488
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+
473494 // dateFormat
474495 $ this ->assertFalse (Validators::dateFormat ('hello ' ));
475496 $ this ->assertFalse (Validators::dateFormat ('170526 ' , 'ymd ' ));
476497 $ this ->assertTrue (Validators::dateFormat ('20170526 ' , 'Ymd ' ));
477498
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+
478508 // afterDate
479509 $ this ->assertTrue (Validators::afterDate ('20170526 ' , '20170524 ' ));
480510 $ this ->assertFalse (Validators::afterDate ('20170526 ' , '20170526 ' ));
@@ -485,6 +515,13 @@ public function testDateCheck()
485515 $ this ->assertTrue (Validators::afterOrEqualDate ('20170526 ' , '20170526 ' ));
486516 $ this ->assertTrue (Validators::afterOrEqualDate ('20170526 ' , '20170524 ' ));
487517 $ 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 ' ));
488525 }
489526
490527 public function testPhone ()
@@ -502,6 +539,48 @@ public function testPostCode()
502539 public function testPrice ()
503540 {
504541 $ 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 ' ));
506585 }
507586}
0 commit comments