Exemplo n.º 1
0
Arquivo: Id.php Projeto: t4web/base
 public function __construct($name = null)
 {
     $validatorGreaterThan = new Validator\GreaterThan(array('min' => 0));
     $validatorGreaterThan->setMessages(array(Validator\GreaterThan::NOT_GREATER => "Значение обязательное и не может быть пустым"));
     $validatorDigits = new Validator\Digits(array('min' => 0));
     $validatorDigits->setMessages(array(Validator\Digits::INVALID => "Значение обязательное и не может быть пустым", Validator\Digits::NOT_DIGITS => "Значение обязательное и не может быть пустым", Validator\Digits::STRING_EMPTY => "Значение обязательное и не может быть пустым"));
     $this->getValidatorChain()->attach($validatorGreaterThan, true)->attach($validatorDigits, true);
     parent::__construct($name);
 }
Exemplo n.º 2
0
 /**
  * Ensures that getInclusive() returns expected default value
  *
  * @return void
  */
 public function testGetInclusive()
 {
     $validator = new GreaterThan(10);
     $this->assertEquals(false, $validator->getInclusive());
 }
Exemplo n.º 3
0
 /**
  * Ensures that getMin() returns expected value
  *
  * @return void
  */
 public function testGetMin()
 {
     $validator = new Validator\GreaterThan(10);
     $this->assertEquals(10, $validator->getMin());
 }
Exemplo n.º 4
0
 /**
  * @param $min
  * @param bool $inclusive
  * @return GreaterThan
  */
 public static function greaterThanValidator($min, $inclusive = false)
 {
     $validator = new GreaterThan(compact('min', 'inclusive'));
     if ($inclusive) {
         $validator->setMessage(sprintf("Input tidak boleh lebih kecil dari %s.", $min));
     } else {
         $validator->setMessage(sprintf("Input tidak boleh lebih kecil dari atau sama dengan %s.", $min));
     }
     return $validator;
 }
Exemplo n.º 5
0
 public function getInputFilter()
 {
     if ($this->filter == null) {
         $this->filter = new InputFilter();
         $customer = new Input('customer');
         $customer->setRequired(false);
         $customer->setAllowEmpty(true);
         $this->filter->add($customer);
         $supplier = new Input('supplier');
         $supplier->setRequired(false);
         $supplier->setAllowEmpty(true);
         $this->filter->add($supplier);
         $supplierDocNumber = new Input('supplierDocNumber');
         $supplierDocNumber->setRequired(false);
         $supplierDocNumber->setAllowEmpty(true);
         $this->filter->add($supplierDocNumber);
         $paymentType = new Input('paymentType');
         $paymentType->setRequired(false);
         $paymentType->setAllowEmpty(true);
         $this->filter->add($paymentType);
         $comment = new Input('comment');
         $comment->setRequired(false);
         $comment->setAllowEmpty(true);
         $this->filter->add($comment);
         $vat = new Input('vat');
         $vat->setRequired(false);
         $vat->setAllowEmpty(true);
         $this->filter->add($vat);
         $docDate = new Input('docDate');
         $docDate->setRequired(true);
         $docDate->setAllowEmpty(false);
         $this->filter->add($docDate);
         $digits = new Digits();
         $deadlineDays = new Input('deadlineDays');
         $deadlineDays->setRequired(false);
         $deadlineDays->setAllowEmpty(true);
         $deadlineDays->getValidatorChain()->attach($digits);
         $this->filter->add($deadlineDays);
         $moneyValidator = new MoneyValidator();
         $delayPercent = new Input('delayPercent');
         $delayPercent->setRequired(false);
         $delayPercent->setAllowEmpty(true);
         $delayPercent->getValidatorChain()->attach($moneyValidator);
         $this->filter->add($delayPercent);
         $greaterThan = new GreaterThan();
         $greaterThan->setMin(0.001);
         $amount = new Input('amount');
         $amount->setRequired(true);
         $amount->setAllowEmpty(false);
         $amount->getValidatorChain()->attach($moneyValidator)->attach($greaterThan);
         $this->filter->add($amount);
         $taxAmount = new Input('taxAmount');
         $taxAmount->setRequired(false);
         $taxAmount->setAllowEmpty(true);
         $taxAmount->getValidatorChain()->attach($moneyValidator);
         $this->filter->add($taxAmount);
         $amountTax = new Input('amountTax');
         $amountTax->setRequired(true);
         $amountTax->setAllowEmpty(false);
         $amountTax->getValidatorChain()->attach($moneyValidator);
         $this->filter->add($amountTax);
     }
     return $this->filter;
 }
Exemplo n.º 6
0
 public function testCorrectNotInclusiveMessageReturn()
 {
     $valuesToValidate = array(0, 0.5, 5, 9);
     foreach ($valuesToValidate as $value) {
         $validator = new GreaterThan(array('min' => 10, 'inclusive' => true));
         $validator->isValid($value);
         $message = $validator->getMessages();
         $this->assertArrayHaskey('notGreaterThanInclusive', $message);
         $this->assertEquals($message['notGreaterThanInclusive'], "The input is not greater or equal than '10'");
     }
 }