示例#1
0
 /**
  * test simple validation
  */
 public function testValidate()
 {
     $result = $this->validator->validate('test', 'this is not numeric', 'numeric|email');
     $this->assertFalse($result, 'validate() should invalidate incorrect test');
     // we are not only checking that a correct test passes, but also that the Validator doesn't remember a
     // negative state from before (we might accidentally build something like that in the future)
     $result = $this->validator->validate('test', '*****@*****.**', 'email');
     $this->assertTrue($result, 'validate() should validate correct entry');
     // however, the Validator class should still keep track of all the validate errors
     $errors = $this->validator->getAttributeErrors('test');
     $this->assertCount(2, $errors, 'the Validator class should remember all errors');
 }
示例#2
0
 /**
  * return the found error messages using $this->validate()
  * optionally prefixed with given message and optionally formatted in error div
  * @param null $message
  * @param bool $inErrorDiv
  * @return string
  */
 public function renderValidationErrors($message = null, $inErrorDiv = true)
 {
     $errors = $this->validator->getAttributeErrors($this->name);
     if (empty($errors)) {
         return null;
     }
     $errorString = implode("<br/>\n", $errors);
     $message = !empty($message) ? '<p>' . $message . "</p>\n" : "";
     if ($inErrorDiv === true) {
         $message = '<div class="error">' . $message . "<p>" . $errorString . "</p></div>\n";
     } else {
         $message = $message . $errorString;
     }
     return $message;
 }