public function testLoadRulesAndDataMultipleTimes() { $v = new Validator(); $v->loadData(['email' => '*****@*****.**'])->loadData(['first_name' => 'John']); $v->loadData(['last_name' => 'Doe'])->setRules([['email', 'email']])->setRules([[['first_name', 'last_name'], 'string', 'max' => 10]]); $isValid = $v->validate(); $this->assertTrue($isValid); }
public function testLessOrEqualComparison() { $data = [12345 => 12345, 12344 => 12345]; $isValid = true; foreach ($data as $val => $compVal) { $valid = Validator::validateFor('compare', $val, ['compareValue' => $compVal, 'operator' => '<='])->isValid; if (!$valid) { $isValid = false; } } $this->assertTrue($isValid); }
/** * @expectedException \mysqli_sql_exception */ public function testIsExceptionThrownOnEmptyConnectionParams() { Validator::validateFor('unique', '123', ['table' => 'table', 'column' => 'column']); }
public function testIsLessThanAllowedValid() { $isValid = Validator::validateFor('number', 656.35, ['min' => 657])->isValid; $this->assertFalse($isValid); }
public function testIsEqualToRequiredValueUsingStrictComparison() { $isValid = Validator::validateFor('required', '1', ['requiredValue' => 1, 'strict' => true])->isValid; $this->assertFalse($isValid); }
public function testIsStrictComparisonWorking() { $isValid = Validator::validateFor('in', "5", ['range' => range(1, 5), 'strict' => true])->isValid; $this->assertFalse($isValid); }
public function testIsValidWitCountryCode() { $isValid = Validator::validateFor('phone', '+999 55555555')->isValid; $this->assertTrue($isValid); }
public function testStrictAnythingElseIsValid() { $data = ['notBool1' => 'bar', 'notBool2' => 2, 'notBool3' => 123.456, 'notBool4' => true, 'notBool5' => null]; $isValid = Validator::validateFor('boolean', $data, ['strict' => true])->isValid; $this->assertFalse($isValid); }
public function testIsProperFileValidationWorking() { $data = ['testFile' => ['name' => 'testfile.txt', 'type' => $this->mimeType, 'size' => $this->size, 'tmp_name' => $this->path, 'error' => 0]]; $isValid = Validator::validateFor('file', $data, ['extensions' => ['txt']])->isValid; $this->assertTrue($isValid); }
public function testIsEnabledIDNCheckWorking() { $isValid = Validator::validateFor('url', 'http://täst.de', ['enableIDN' => true])->isValid; $this->assertTrue($isValid); }
public function testIsStringValidWithRestrictions() { $isValid = Validator::validateFor('string', '123qwe456rty', ['min' => 6, 'max' => 20])->isValid; $this->assertTrue($isValid); }
public function testIsEmailValid() { $isValid = Validator::validateFor('email', '*****@*****.**', ['checkDNS' => true])->isValid; $this->assertTrue($isValid); }
<?php /** * This is fully-working example, showing how to use framework in action. * You can copy the content of this file and use it in a bootstrap script in your project, * or paste it in any other file that can be executed directly from the browser. * But don't try to execute this file itself :) */ use valify\Validator; require 'vendor/autoload.php'; $validator = new Validator(); // require "your/own/path/to/ValidatorClass.php"; $rules = [['username', 'required'], [['username', 'password'], 'string', 'max' => 10], ['email', 'email', 'message' => 'Please provide a valid email'], ['remember_me', 'boolean'], ['file', 'file', 'minSize' => 10000, 'maxFiles' => 2, 'extensions' => ['jpg'], 'checkExtensionByMimeType' => false]]; if (!empty($_POST)) { $data = $_POST; $data['file'] = $_FILES['file']; $isValid = $validator->setRules($rules)->loadData($data)->validate(); } function getValue($val) { return isset($_POST[$val]) ? $_POST[$val] : ''; } ?> <html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <style> .help-block { color: red; }