mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fadce39f5f | ||
|
|
5659b0a942 | ||
|
|
fdc64d193a | ||
|
|
0cbc5834b0 | ||
|
|
1b86b4f454 | ||
|
|
fbb596d220 | ||
|
|
57a9f68f22 | ||
|
|
fd902d1def | ||
|
|
ac960d625f | ||
|
|
d0fb8ee84c | ||
|
|
94c97e3e8e | ||
|
|
9bf11f4374 | ||
|
|
b619ef16ba | ||
|
|
b4e0d07495 | ||
|
|
5ebd5d7af8 | ||
|
|
f189549d2d | ||
|
|
fe2ca630fb | ||
|
|
035eca3093 | ||
|
|
da91bdea70 | ||
|
|
ba90097aa5 | ||
|
|
d12a77deed | ||
|
|
be8cb9e074 | ||
|
|
500472808c | ||
|
|
567fbb9965 | ||
|
|
ae5a778541 | ||
|
|
1c0674c23f | ||
|
|
4c7d0070dd | ||
|
|
33148fa4ed | ||
|
|
f0c48c4adf | ||
|
|
0282ca420b | ||
|
|
5deb47049a | ||
|
|
f7e662e3c0 | ||
|
|
6b3c5ae608 |
73
.github/workflows/test.yml
vendored
Normal file
73
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
name: Run Tests
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: ['ubuntu-latest']
|
||||
php-versions:
|
||||
- '5.4'
|
||||
- '5.5'
|
||||
- '5.6'
|
||||
- '7.0'
|
||||
- '7.1'
|
||||
- '7.2'
|
||||
- '7.3'
|
||||
- '7.4'
|
||||
- '8.0'
|
||||
# - '8.1'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
- name: Cache composer packages
|
||||
id: composer-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-php-${{ matrix.php-versions }}-
|
||||
- name: Validate composer configuration
|
||||
run: |
|
||||
composer validate
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
composer install --no-progress
|
||||
- name: Run tests
|
||||
run: |
|
||||
composer run-script test
|
||||
|
||||
# test-hhvm:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout
|
||||
# uses: actions/checkout@v2
|
||||
# - name: Setup HHVM
|
||||
# uses: azjezz/setup-hhvm@v1
|
||||
# with:
|
||||
# version: latest
|
||||
# debug: false
|
||||
# - name: Cache composer packages
|
||||
# id: composer-cache
|
||||
# uses: actions/cache@v2
|
||||
# with:
|
||||
# path: vendor
|
||||
# key: ${{ runner.os }}-hhvm-${{ hashFiles('**/composer.lock') }}
|
||||
# restore-keys: |
|
||||
# ${{ runner.os }}-hhvm-
|
||||
# - name: Validate composer configuration
|
||||
# run: |
|
||||
# composer validate
|
||||
# - name: Install dependencies
|
||||
# run: |
|
||||
# composer install --no-progress
|
||||
# - name: Run tests
|
||||
# run: |
|
||||
# composer run-script test
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ composer.phar
|
||||
composer.lock
|
||||
vendor
|
||||
.idea/
|
||||
.phpunit.result.cache
|
||||
32
.travis.yml
32
.travis.yml
@ -1,32 +0,0 @@
|
||||
#see https://travis-ci.community/t/php-5-4-and-5-5-archives-missing/3723
|
||||
dist: trusty
|
||||
|
||||
# see http://about.travis-ci.org/docs/user/languages/php/ for more hints
|
||||
language: php
|
||||
|
||||
# list any PHP version you want to test against
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
- nightly
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
- php: nightly
|
||||
include:
|
||||
- php: 5.3
|
||||
dist: precise
|
||||
|
||||
before_script:
|
||||
- composer install
|
||||
|
||||
# Script to run tests
|
||||
script: composer test
|
||||
@ -6,7 +6,7 @@ methods with a focus on readable and concise syntax. Valitron is the
|
||||
simple and pragmatic validation library you've been looking for.
|
||||
|
||||
[](https://travis-ci.org/vlucas/valitron)
|
||||
Status](https://github.com/vlucas/valitron/actions/workflows/test.yml/badge.svg)](https://github.com/vlucas/valitron/actions/workflows/test.yml)
|
||||
[](https://packagist.org/packages/vlucas/valitron)
|
||||
[](https://packagist.org/packages/vlucas/valitron)
|
||||
|
||||
|
||||
@ -3,20 +3,20 @@
|
||||
"type": "library",
|
||||
"description": "Simple, elegant, stand-alone validation library with NO dependencies",
|
||||
"keywords": ["validation", "validator", "valid"],
|
||||
"homepage": "http://github.com/vlucas/valitron",
|
||||
"homepage": "https://github.com/vlucas/valitron",
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Vance Lucas",
|
||||
"email": "vance@vancelucas.com",
|
||||
"homepage": "http://www.vancelucas.com"
|
||||
"homepage": "https://www.vancelucas.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.5 || ^6.5"
|
||||
"phpunit/phpunit": ">=4.8.35"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "It can support the multiple bytes string length."
|
||||
|
||||
42
lang/fa.php
Normal file
42
lang/fa.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'required' => "الزامی است",
|
||||
'equals' => " باید برابر باشد با '%s'",
|
||||
'different' => "باید متفاوت باشد از '%s'",
|
||||
'accepted' => "باید پذیرفته شده باشد",
|
||||
'numeric' => "باید مقدار عددی باشد",
|
||||
'integer' => "باید عددی طبیعی باشد",
|
||||
'length' => "طول باید %d باشد",
|
||||
'min' => "حداقل باید %s کاراکتر باشد",
|
||||
'max' => "نباید بیشتر از %s کارکتر باشد",
|
||||
'listContains' => "حاوی مقدار نامعتبر",
|
||||
'in' => "حاوی مقدار نامعتبر",
|
||||
'notIn' => "حاوی مقدار نامعتبر",
|
||||
'ip' => " آدرس معتبر نیست IP",
|
||||
'ipv4' => "آدرس معتبر نیست IPv4",
|
||||
'ipv6' => "آدرس معتبر نیست IPv6",
|
||||
'email' => "آدرس ایمیل معتبر نیست",
|
||||
'url' => "معتبر نیست URL",
|
||||
'urlActive' => "دامنه باید فعال باشد",
|
||||
'alpha' => "باید حاوی حروف a-z باشد",
|
||||
'alphaNum' => "باید حاوی حروف a-z و/یا اعداد 0-9 باشد",
|
||||
'slug' => "باید حاوی حروف a-z, اعداد 0-9, دش و آندراسکور باشد",
|
||||
'regex' => "حاوی کارکترهای نامعتبر",
|
||||
'date' => "تاریخ معتبر نیست",
|
||||
'dateFormat' => "فرمت تاریخ باید به این شکل '%s' باشد",
|
||||
'dateBefore' => "تاریخ باید قبل از '%s' باشد",
|
||||
'dateAfter' => "تاریخ باید بعد از '%s' باشد",
|
||||
'contains' => "باید حاوی %s باشد",
|
||||
'boolean' => "مقدار باید بولین باشد",
|
||||
'lengthBetween' => "طول باید بین %d و %d کاراکتر باشد",
|
||||
'creditCard' => "شماره کارت اعتباری معتبر نیست",
|
||||
'lengthMin' => "طول باید حداقل %d کاراکتر باشد",
|
||||
'lengthMax' => "طول نباید بیشتر از %d کاراکتر باشد",
|
||||
'instanceOf' => "باید آبجکتی از نوع '%s' باشد",
|
||||
'containsUnique' => "باید حاوی المان ها یونیک باشد",
|
||||
'requiredWith' => "الزامی است",
|
||||
'requiredWithout'=> "الزامی است",
|
||||
'subset' => "حاوی آیتمی است که در لیست موجود نیست",
|
||||
'arrayHasKeys' => "همه کلیدهای الزامی را ندارد",
|
||||
);
|
||||
@ -14,6 +14,8 @@ return array(
|
||||
'in' => "には選択できない値が含まれています",
|
||||
'notIn' => "には選択できない値が含まれています",
|
||||
'ip' => "はIPアドレスの書式として正しくありません",
|
||||
'ipv4' => "はIPv4のIPアドレスの書式として正しくありません",
|
||||
'ipv6' => "はIPv6のIPアドレスの書式として正しくありません",
|
||||
'email' => "はメールアドレスの書式として正しくありません",
|
||||
'url' => "はURLの書式として正しくありません",
|
||||
'urlActive' => "はアクティブなドメインではありません",
|
||||
@ -32,4 +34,9 @@ return array(
|
||||
'lengthMin' => "は%d文字以上入力してください",
|
||||
'lengthMax' => "は%d文字以内で入力してください",
|
||||
'instanceOf' => "は「%s」のインスタンスではありません",
|
||||
'containsUnique' => "は重複のないように入力してください",
|
||||
'requiredWith' => "を入力してください",
|
||||
'requiredWithout' => "を入力してください",
|
||||
'subset' => "には選択できない値が含まれています",
|
||||
'arrayHasKeys' => "の必要な項目が選択されていません",
|
||||
);
|
||||
|
||||
20
lang/sv.php
20
lang/sv.php
@ -13,23 +13,23 @@ return array(
|
||||
'listContains' => "innehåller ogiltigt värde",
|
||||
'in' => "innehåller ogiltigt värde",
|
||||
'notIn' => "innehåller ogiltigt värde",
|
||||
'ip' => "är inte en giltlig IP-adress",
|
||||
'email' => "är inte en giltlig e-postadress",
|
||||
'url' => "är inte en giltlig URL",
|
||||
'ip' => "är inte en giltig IP-adress",
|
||||
'email' => "är inte en giltig e-postadress",
|
||||
'url' => "är inte en giltig URL",
|
||||
'urlActive' => "måste vara ett aktivt domännamn",
|
||||
'alpha' => "får bara inehålla bokstäver a-z",
|
||||
'alphaNum' => "får bara inehålla bokstäver a-z och/eller siffror 0-9",
|
||||
'slug' => "får bara inehålla bokstäver a-z och/eller siffror 0-9, bindesträck og understräck",
|
||||
'regex' => "inehåller ogiltliga tecken",
|
||||
'date' => "är inte ett giltligt datum",
|
||||
'alpha' => "får bara innehålla bokstäver a-z",
|
||||
'alphaNum' => "får bara innehålla bokstäver a-z och/eller siffror 0-9",
|
||||
'slug' => "får bara innehålla bokstäver a-z och/eller siffror 0-9, bindesstreck och understreck",
|
||||
'regex' => "innehåller ogiltiga tecken",
|
||||
'date' => "är inte ett giltigt datum",
|
||||
'dateFormat' => "måste vara ett datum med formatet '%s'",
|
||||
'dateBefore' => "måste vara ett datum före '%s'",
|
||||
'dateAfter' => "måste vara ett datum efter '%s'",
|
||||
'contains' => "måste innehålla %s",
|
||||
'boolean' => "måste vara ett booleskt värde",
|
||||
'lengthBetween' => "måste vara mellan %d och %d tecken långt",
|
||||
'creditCard' => "måste vara et gyldig kredittkortnummer",
|
||||
'creditCard' => "måste vara ett giltigt kreditkortsnummer",
|
||||
'lengthMin' => "måste vara minst %d tecken långt",
|
||||
'lengthMax' => "får itne överstiga %d tecken",
|
||||
'lengthMax' => "får inte överstiga %d tecken",
|
||||
'instanceOf' => "måste vara en instans av '%s'"
|
||||
);
|
||||
|
||||
@ -29,7 +29,7 @@ return array(
|
||||
'boolean' => "boolean olmalı",
|
||||
'lengthBetween' => "%d ve %d karakter arasında olmalı",
|
||||
'creditCard' => "geçerli bir kredi kartı numarası olmalı",
|
||||
"lengthMin" => "%d katakterden fazla içermeli",
|
||||
"lengthMin" => "%d karakterden fazla içermeli",
|
||||
"lengthMax" => "%d karakterden az içermeli",
|
||||
"instanceOf" => "bunun bir örneği olmalı '%s'"
|
||||
);
|
||||
|
||||
@ -7,7 +7,7 @@ return array(
|
||||
'accepted' => "必须接受",
|
||||
'numeric' => "只能是数字",
|
||||
'integer' => "只能是整数",
|
||||
'length' => "长度必须大于 %d",
|
||||
'length' => "长度必须等于 %d",
|
||||
'min' => "必须大于 %s",
|
||||
'max' => "必须小于 %s",
|
||||
'listContains' => "无效的值",
|
||||
@ -30,5 +30,11 @@ return array(
|
||||
'lengthBetween' => "长度只能介于 %d 和 %d 之间",
|
||||
'creditCard' => "信用卡号码不正确",
|
||||
'lengthMin' => "长度必须大于 %d",
|
||||
'lengthMax' => "长度必须小于 %d"
|
||||
'lengthMax' => "长度必须小于 %d",
|
||||
'instanceOf' => "必须是 '%s' 的实例",
|
||||
'containsUnique' => "必须仅包含唯一的元素",
|
||||
'requiredWith' => "是必须的",
|
||||
'requiredWithout' => "是必须的",
|
||||
'subset' => "包含不在列表中的项目",
|
||||
'arrayHasKeys' => "不包含所有必需的键",
|
||||
);
|
||||
|
||||
@ -25,5 +25,16 @@ return array(
|
||||
'dateFormat' => "日期的格式應該為 '%s'",
|
||||
'dateBefore' => "日期必須在 '%s' 之前",
|
||||
'dateAfter' => "日期必須在 '%s' 之後",
|
||||
'contains' => "必須包含 %s"
|
||||
'contains' => "必須包含 %s",
|
||||
'boolean' => "必須是真或假",
|
||||
'lengthBetween' => "長度只能介於 %d 和 %d 之間",
|
||||
'creditCard' => "信用卡號碼不正確",
|
||||
'lengthMin' => "長度必須大於 %d",
|
||||
'lengthMax' => "長度必須小於 %d",
|
||||
'instanceOf' => "必須是 '%s' 的實例",
|
||||
'containsUnique' => "必須僅包含唯一的元素",
|
||||
'requiredWith' => "是必須的",
|
||||
'requiredWithout' => "是必須的",
|
||||
'subset' => "包含不在列表中的項目",
|
||||
'arrayHasKeys' => "不包含所有必需的鍵",
|
||||
);
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
@ -15,12 +14,4 @@
|
||||
<directory suffix="Test.php">tests/Valitron</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src/</directory>
|
||||
</whitelist>
|
||||
<blacklist>
|
||||
<directory suffix=".php">vendor/</directory>
|
||||
</blacklist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
||||
@ -172,9 +172,7 @@ class Validator
|
||||
return $find[1];
|
||||
}
|
||||
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
} elseif (is_string($value) && trim($value) === '') {
|
||||
if (is_null($value) || (is_string($value) && trim($value) === '')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -422,8 +420,12 @@ class Validator
|
||||
*/
|
||||
protected function validateIn($field, $value, $params)
|
||||
{
|
||||
$isAssoc = array_values($params[0]) !== $params[0];
|
||||
if ($isAssoc) {
|
||||
$forceAsAssociative = false;
|
||||
if (isset($params[2])) {
|
||||
$forceAsAssociative = (bool) $params[2];
|
||||
}
|
||||
|
||||
if ($forceAsAssociative || $this->isAssociativeArray($params[0])) {
|
||||
$params[0] = array_keys($params[0]);
|
||||
}
|
||||
|
||||
@ -445,8 +447,12 @@ class Validator
|
||||
*/
|
||||
protected function validateListContains($field, $value, $params)
|
||||
{
|
||||
$isAssoc = array_values($value) !== $value;
|
||||
if ($isAssoc) {
|
||||
$forceAsAssociative = false;
|
||||
if (isset($params[2])) {
|
||||
$forceAsAssociative = (bool) $params[2];
|
||||
}
|
||||
|
||||
if ($forceAsAssociative || $this->isAssociativeArray($value)) {
|
||||
$value = array_keys($value);
|
||||
}
|
||||
|
||||
@ -624,12 +630,17 @@ class Validator
|
||||
*/
|
||||
protected function validateEmailDNS($field, $value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->validateEmail($field, $value)) {
|
||||
$domain = ltrim(stristr($value, '@'), '@') . '.';
|
||||
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46')) {
|
||||
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||
}
|
||||
return checkdnsrr($domain, 'ANY');
|
||||
|
||||
return checkdnsrr($domain, 'MX');
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -644,6 +655,10 @@ class Validator
|
||||
*/
|
||||
protected function validateUrl($field, $value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->validUrlPrefixes as $prefix) {
|
||||
if (strpos($value, $prefix) !== false) {
|
||||
return filter_var($value, \FILTER_VALIDATE_URL) !== false;
|
||||
@ -662,6 +677,10 @@ class Validator
|
||||
*/
|
||||
protected function validateUrlActive($field, $value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->validUrlPrefixes as $prefix) {
|
||||
if (strpos($value, $prefix) !== false) {
|
||||
$host = parse_url(strtolower($value), PHP_URL_HOST);
|
||||
@ -890,13 +909,11 @@ class Validator
|
||||
} elseif (isset($cards)) {
|
||||
// if we have cards, check our users card against only the ones we have
|
||||
foreach ($cards as $card) {
|
||||
if (in_array($card, array_keys($cardRegex))) {
|
||||
if (in_array($card, array_keys($cardRegex)) && preg_match($cardRegex[$card], $value) === 1) {
|
||||
// if the card is valid, we want to stop looping
|
||||
if (preg_match($cardRegex[$card], $value) === 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// loop through every card
|
||||
foreach ($cardRegex as $regex) {
|
||||
@ -954,8 +971,8 @@ class Validator
|
||||
$emptyFields = 0;
|
||||
foreach ($reqParams as $requiredField) {
|
||||
// check the field is set, not null, and not the empty string
|
||||
if (isset($fields[$requiredField]) && !is_null($fields[$requiredField])
|
||||
&& (is_string($fields[$requiredField]) ? trim($fields[$requiredField]) !== '' : true)) {
|
||||
list($requiredFieldValue, $multiple) = $this->getPart($fields, explode('.', $requiredField));
|
||||
if (isset($requiredFieldValue) && (!is_string($requiredFieldValue) || trim($requiredFieldValue) !== '')) {
|
||||
if (!$allRequired) {
|
||||
$conditionallyReq = true;
|
||||
break;
|
||||
@ -998,8 +1015,8 @@ class Validator
|
||||
$filledFields = 0;
|
||||
foreach ($reqParams as $requiredField) {
|
||||
// check the field is NOT set, null, or the empty string, in which case we are requiring this value be present
|
||||
if (!isset($fields[$requiredField]) || (is_null($fields[$requiredField])
|
||||
|| (is_string($fields[$requiredField]) && trim($fields[$requiredField]) === ''))) {
|
||||
list($requiredFieldValue, $multiple) = $this->getPart($fields, explode('.', $requiredField));
|
||||
if (!isset($requiredFieldValue) || (is_string($requiredFieldValue) && trim($requiredFieldValue) === '')) {
|
||||
if (!$allEmpty) {
|
||||
$conditionallyReq = true;
|
||||
break;
|
||||
@ -1102,11 +1119,9 @@ class Validator
|
||||
}
|
||||
}
|
||||
// Use custom label instead of field name if set
|
||||
if (is_string($params[0])) {
|
||||
if (isset($this->_labels[$param])) {
|
||||
if (is_string($params[0]) && isset($this->_labels[$param])) {
|
||||
$param = $this->_labels[$param];
|
||||
}
|
||||
}
|
||||
$values[] = $param;
|
||||
}
|
||||
|
||||
@ -1291,12 +1306,10 @@ class Validator
|
||||
protected function hasRule($name, $field)
|
||||
{
|
||||
foreach ($this->_validations as $validation) {
|
||||
if ($validation['rule'] == $name) {
|
||||
if (in_array($field, $validation['fields'])) {
|
||||
if ($validation['rule'] == $name && in_array($field, $validation['fields'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1573,4 +1586,9 @@ class Validator
|
||||
$me->mapFieldRules($field, $rules[$field]);
|
||||
}, array_keys($rules));
|
||||
}
|
||||
|
||||
private function isAssociativeArray($input){
|
||||
//array contains at least one key that's not an can not be cast to an integer
|
||||
return count(array_filter(array_keys($input), 'is_string')) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,10 +4,8 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BaseTestCase extends TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
public function tearDown()
|
||||
{
|
||||
$this->resetProperty('_lang');
|
||||
@ -23,4 +21,5 @@ class BaseTestCase extends TestCase
|
||||
$prop->setValue($value);
|
||||
$prop->setAccessible(false);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ class LangTest extends BaseTestCase
|
||||
{
|
||||
$lang = 'ar';
|
||||
Validator::lang($lang);
|
||||
$validator = new Validator(array());
|
||||
$this->assertEquals($lang, Validator::lang());
|
||||
Validator::lang('en');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,13 +42,15 @@ class LangTest extends BaseTestCase
|
||||
$this->assertEquals(realpath($this->getLangDir()), realpath(Validator::langDir()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage Fail to load language file '/this/dir/does/not/exists/en.php'
|
||||
*/
|
||||
|
||||
public function testLangException()
|
||||
{
|
||||
try{
|
||||
new Validator(array(), array(), 'en', '/this/dir/does/not/exists');
|
||||
} catch (Exception $exception){
|
||||
$this->assertInstanceOf("InvalidArgumentException", $exception);
|
||||
$this->assertEquals("Fail to load language file '/this/dir/does/not/exists/en.php'", $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ class StaticVsInstanceTest extends BaseTestCase
|
||||
$this->assertEquals(
|
||||
'ar', Validator::lang(), 'instance defined lang should not replace static global lang'
|
||||
);
|
||||
Validator::lang('en');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -980,6 +980,7 @@ class ValidateTest extends BaseTestCase
|
||||
array('color', array('blue', 'green', 'red', 'yellow'))
|
||||
)
|
||||
));
|
||||
$this->assertFalse($v->validate());
|
||||
}
|
||||
|
||||
public function testAsciiValid()
|
||||
@ -2919,6 +2920,46 @@ class ValidateTest extends BaseTestCase
|
||||
$v->rule('optional', 'address');
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see https://github.com/vlucas/valitron/issues/332
|
||||
*/
|
||||
public function testInRuleSearchesValuesForNumericArray(){
|
||||
|
||||
$v = new Valitron\Validator(array('color' => 'purple'));
|
||||
|
||||
$v->rules(array(
|
||||
'in' => array(
|
||||
array('color', array(3=>'green', 2=>'purple'))
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
|
||||
public function testInRuleSearchesKeysForAssociativeArray(){
|
||||
$v = new Valitron\Validator(array('color' => 'c-2'));
|
||||
|
||||
$v->rules(array(
|
||||
'in' => array(
|
||||
array('color', array('c-3'=>'green', 'c-2'=>'purple'))
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
|
||||
public function testInRuleSearchesKeysWhenForcedTo(){
|
||||
$v = new Valitron\Validator(array('color' => 2));
|
||||
|
||||
$v->rules(array(
|
||||
'in' => array(
|
||||
array('color', array('3'=>'green', '2'=>'purple'), null, true)
|
||||
)
|
||||
));
|
||||
$this->assertTrue($v->validate());
|
||||
}
|
||||
}
|
||||
|
||||
function sampleFunctionCallback($field, $value, array $params)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user