/**
  * @depends testAddErrors
  * @covers W3C\Validation\Result::getErrorCount
  */
 public function testAddErrorsSetsErrorCount()
 {
     $this->assertEquals(0, $this->result->getErrorCount());
     $this->result->addError(new Violation());
     $this->assertEquals(1, $this->result->getErrorCount());
     $this->result->addError(new Violation());
     $this->assertEquals(2, $this->result->getErrorCount());
 }
Exemple #2
0
 public function run(Result $result, $offset)
 {
     $result->addError($offset);
     $result->addSuccesses(15);
     $result->addFailures(10);
     return $result;
 }
Exemple #3
0
 /**
  * @group response-validation
  * @test
  */
 public function the_result_correctly_reports_whether_or_not_it_is_valid()
 {
     $result = new Result();
     $this->assertTrue($result->isValid());
     $this->assertCount(0, $result->getErrors());
     $result->addError('Oh noooos!');
     $this->assertFalse($result->isValid());
     $this->assertCount(1, $result->getErrors());
 }
Exemple #4
0
 function validate_cancel_input()
 {
     $result = new Result();
     if (!isset($_POST['leave_to_cancel']) || empty($_POST['leave_to_cancel'])) {
         $result->setResult(FALSE);
         $result->addError("Please select leave to cancel");
     }
     return $result;
 }
Exemple #5
0
 /**
  * Добавление сущности
  *
  * @param $data
  */
 public function add($data)
 {
     $data = $this->factoryEntity($data)->toArray();
     // Фильтруем данные
     $data = $this->filterOnAdd($data);
     // Валидируем данные
     $validator = $this->validateOnAdd($data);
     $result = new Result();
     if ($validator->isValid()) {
         try {
             $id = $this->insert($this->getName(), $data);
             if (!$id) {
                 $result->addError('Add ' . $this->getName() . ' failed', 'add_product_failed');
             }
         } catch (Exception $e) {
             $result->addError($e->getMessage(), $e->getCode());
         }
     }
     return $result->setResult($id);
 }
 /**
  * Validates the given markup
  *
  * @param  string $markup
  *
  * @return Result
  */
 public function validate($markup)
 {
     $result = new Result();
     $messages = $this->processor->execute($markup);
     foreach ($messages as $message) {
         if (Validator::MESSAGE_TYPE_ERROR === $message['type']) {
             $result->addError(new Error($message['line'], $message['column'], $message['message']));
         } else {
             if (Validator::MESSAGE_TYPE_WARNING === $message['type']) {
                 $result->addWarning(new Warning($message['line'], $message['column'], $message['message']));
             }
         }
     }
     return $result;
 }
Exemple #7
0
 public function validateValue($value, $primary, $row, Result $result)
 {
     $validators = $this->getValidators();
     foreach ($validators as $validator) {
         if (is_object($validator)) {
             $vResult = $validator->validate($value, $primary, $row, $this);
         } else {
             $vResult = call_user_func_array($validator, array($value, $primary, $row, $this));
         }
         if ($vResult !== true) {
             $result->addError(new FieldError($this, $vResult, FieldError::INVALID_VALUE));
             break;
         }
     }
 }
 function is_valid_casual_leave($emp_id, $leave_start_date, $leave_end_date)
 {
     $result = new Result();
     // check if leave is comming into already taken leaves period
     $this->load->model('leave/leave_helper', 'lh');
     $clash_verification = $this->lh->verify_leaves_period($emp_id, $leave_start_date, $leave_end_date);
     $result->updateResult($clash_verification);
     // check if valid balance of casual leaves
     $avail_bal = $this->get_casual_leave_balance($emp_id);
     $applied_period = strtotime($leave_end_date) - strtotime($leave_start_date);
     $applied_period = floor($applied_period / (60 * 60 * 24)) + 1;
     if ($avail_bal < $applied_period) {
         $result->setResult(FALSE);
         $error = "Your leave length is more than available balance. " . "Your available casual leave balance is " . $avail_bal;
         $result->addError($error);
     }
     // check for maximum allowed casual leaves in one stretch
     if ($applied_period > 5) {
         $result->setResult(FALSE);
         $error = "You can take atmost 5 casual leaves in one stretch.";
         $result->addError($error);
     }
     return $result;
 }
 function is_valid_restricted_leave($emp_id, $leave_date)
 {
     $result = new Result();
     // modify date to match db date format
     $leave_date = date('Y-m-d', strtotime($leave_date));
     // check if restricted holiday available
     $sql = "SELECT * FROM " . Leave_constants::$TABLE_RESTRICTED_HOLIDAYS . " WHERE holiday_date = '{$leave_date}'";
     $query = $this->db->query($sql);
     if ($query->num_rows() == 0) {
         $result->setResult(FALSE);
         $result->addError("No restricted holiday available.");
     }
     // check if leave is comming into already taken leaves period
     $this->load->model('leave/leave_helper', 'lh');
     $clash_verification = $this->lh->verify_leaves_period($emp_id, $leave_date, $leave_date);
     $result->updateResult($clash_verification);
     // check if balance for leave available
     $balance = $this->get_restricted_leave_balance($emp_id);
     if ($balance < 1) {
         $result->setResult(FALSE);
         $result->addError("Your don't have restricted leaves left.");
     }
     return $result;
 }
Exemple #10
0
 function check_for_weekend()
 {
     // result to resturn
     $result = new Result();
     $time = $this->leave_start_time;
     while ($this->leave_end_time >= $time) {
         $day_of_week = date('w', $time);
         if ($day_of_week == 0 || $day_of_week == 6) {
             $result->setResult(FALSE);
             $result->addError("Your leave includes weekend(s) please break it around them.");
             break;
         }
         $time += 24 * 60 * 60;
     }
     return $result;
 }
Exemple #11
0
 function is_valid_date_field()
 {
     // validate emptiness and format of date
     // start date <= end date
     // start date > todays date
     // start date must be less than 3 months from today
     // result to return
     $result = new Result();
     // check for valid start date
     $start_date = strtotime($_POST[Leave_application::LEAVE_START_DATE]);
     if (empty($start_date) || $start_date == FALSE) {
         $result->setResult(FALSE);
         $result->addError("Invalid start date format. It should be in format mm/dd/yyyy");
     }
     // check for valid end date if not restricted leave
     if (Leave_constants::$TYPE_RESTRICTED_LEAVE != $_POST[Leave_application::LEAVE_TYPE]) {
         // check for empty or invalid date field
         $end_date = strtotime($_POST[Leave_application::LEAVE_END_DATE]);
         if (empty($end_date) || $end_date == FALSE) {
             $result->setResult(FALSE);
             $result->addError("Invalid end date format. It should be in format mm/dd/yyyy");
         }
         // check if start date <= end date
         $diff = $end_date - $start_date;
         if ($diff < 0) {
             $result->setResult(FALSE);
             $result->addError("End date can not be before start date. Valid date format mm/dd/yyyy");
         }
     }
     // check if start date > todays date
     $today = strtotime(date('Y-m-d'));
     $diff = $start_date - $today;
     if ($diff <= 0) {
         $result->setResult(FALSE);
         $result->addError("Start date should be after today's date. Valid date format mm/dd/yyyy");
     }
     // leave can be applied only before 90 days from today
     $three_months_time = 90 * 24 * 60 * 60;
     if ($diff > $three_months_time) {
         $result->setResult(FALSE);
         $result->addError("Leave can be applied within 90 days from today");
     }
     return $result;
 }