/** * Validates the file control attached to. * * @param string $input The input of the file field (not relevant here). * * @return boolean True in case the control is valid, false otherwise. * * @author Christian Achatz * @version * Version 0.1, 03.02.2010<br /> * Version 0.2, 21.02.2010 (Added min required file size)<br /> */ public function validate($input) { // check, whether file was specified /* @var $control FileUploadTag */ $control = $this->control; if ($control->hasUploadedFile()) { // retrieve file model to check the file size against the max size $fileModel = $control->getFile(); $size = (int) $fileModel->getSize(); $allowed = (int) $this->getMaxSize(); $required = (int) $this->getMinSize(); $validator = new NumberScopeValidatorImpl($required, $allowed, true, true, true); return $validator->isValid($size); } return false; }
/** * Re-implements the <em>validate()</em> method for the number scope validator. * Supports min and max value definition of the number to validate. * * @param string $input The number to validate. * * @return boolean true, in case the control to validate is considered valid, false otherwise. * * @author Jan Wiese * @version * Version 0.1, 02.01.2013<br /> * Version 0.2, 23.08.2014 (ID#138: extracted validation to allow unit testing and easy controller validation)<br /> */ public function validate($input) { $validator = new NumberScopeValidatorImpl($this->getMinValue(), $this->getMaxValue(), $this->onlyIntegers()); return $validator->isValid($input); }
public function testAcceptIntegersOnly() { $validator = new NumberScopeValidator(3, 5, true, true, true); $this->assertTrue($validator->isValid(3)); $this->assertTrue($validator->isValid(4)); $this->assertTrue($validator->isValid(5)); $this->assertFalse($validator->isValid('4')); $this->assertFalse($validator->isValid(3.0)); $this->assertFalse($validator->isValid(5.0)); $this->assertFalse($validator->isValid(0)); $this->assertFalse($validator->isValid(6)); $this->assertFalse($validator->isValid('6')); $this->assertFalse($validator->isValid(6.1)); $this->assertFalse($validator->isValid('ABC')); }