示例#1
0
 /**
  * Validates the set data attributes against the model rules
  *
  * @return  bool
  * @since   2.0.0
  **/
 public function validate()
 {
     $validity = Rules::validate($this->attributes, $this->getRules());
     if ($validity === true) {
         return true;
     }
     $this->setErrors($validity);
     return false;
 }
示例#2
0
 /**
  * Test to make sure custom validation rules result in failure
  *
  * @return  void
  **/
 public function testCustomRules()
 {
     $endAfterStart = function ($data) {
         return $data['end'] > $data['start'] ? false : 'The end must be after the beginning';
     };
     $fail = Rules::validate(['start' => '2015-07-01 00:00:00', 'end' => '2015-06-01 00:00:00'], ['end' => $endAfterStart]);
     $beSquare = function ($data) {
         return $data['height'] == $data['width'] ? false : 'It\'s not a square!';
     };
     $pass = Rules::validate(['height' => 5, 'width' => 5], ['width' => $beSquare]);
     $this->assertCount(1, $fail, 'Rules (custom) should have returned one error for an end date before the beginning date');
     $this->assertTrue($pass, 'Rule (custom) should have validated with an equal height and width');
 }