Laravel version update
Laravel version update
This commit is contained in:
44
vendor/propaganistas/laravel-phone/.travis.yml
vendored
44
vendor/propaganistas/laravel-phone/.travis.yml
vendored
@@ -1,15 +1,45 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache/files
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# Test lowest possible PHP version for all Laravel releases
|
||||
- php: 5.4
|
||||
env: ILLUMINATE_VERSION=4.0.*
|
||||
- php: 5.4
|
||||
env: ILLUMINATE_VERSION=4.1.*
|
||||
- php: 5.4
|
||||
env: ILLUMINATE_VERSION=4.2.*
|
||||
- php: 5.4
|
||||
env: ILLUMINATE_VERSION=5.0.*
|
||||
- php: 5.5
|
||||
env: ILLUMINATE_VERSION=5.1.*
|
||||
- php: 5.5
|
||||
env: ILLUMINATE_VERSION=5.2.*
|
||||
- php: 5.6
|
||||
env: ILLUMINATE_VERSION=5.3.*
|
||||
- php: 5.6
|
||||
env: ILLUMINATE_VERSION=5.4.*
|
||||
# Test remaining PHP versions on the latest release
|
||||
- php: 7.0
|
||||
env: ILLUMINATE_VERSION=5.4.*
|
||||
- php: 7.1
|
||||
env: ILLUMINATE_VERSION=5.4.*
|
||||
- php: hhvm
|
||||
env: ILLUMINATE_VERSION=5.4.*
|
||||
|
||||
before_install:
|
||||
- composer require "illuminate/support:${ILLUMINATE_VERSION}" --no-update
|
||||
- composer require "illuminate/validation:${ILLUMINATE_VERSION}" --no-update
|
||||
|
||||
install:
|
||||
- travis_wait composer install --prefer-dist --no-suggest --no-interaction
|
||||
|
||||
before_script:
|
||||
- if [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; then echo 'xdebug.enable = On' >> /etc/hhvm/php.ini; fi
|
||||
- composer install
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit --coverage-clover=coverage.clover
|
||||
|
||||
36
vendor/propaganistas/laravel-phone/README.md
vendored
36
vendor/propaganistas/laravel-phone/README.md
vendored
@@ -1,4 +1,4 @@
|
||||
# Laravel Phone Validator
|
||||
# Laravel Phone
|
||||
|
||||
[](https://travis-ci.org/Propaganistas/Laravel-Phone)
|
||||
[](https://scrutinizer-ci.com/g/Propaganistas/Laravel-Phone/?branch=master)
|
||||
@@ -7,7 +7,7 @@
|
||||
[](https://packagist.org/packages/propaganistas/laravel-phone)
|
||||
[](https://packagist.org/packages/propaganistas/laravel-phone)
|
||||
|
||||
Adds a phone validator to Laravel 4|5 and Lumen based on the [PHP port](https://github.com/giggsey/libphonenumber-for-php) of [Google's libphonenumber API](https://github.com/googlei18n/libphonenumber) by [giggsey](https://github.com/giggsey).
|
||||
Adds a phone validator & formatter to Laravel 4 & 5 and Lumen based on the [PHP port](https://github.com/giggsey/libphonenumber-for-php) of [Google's libphonenumber API](https://github.com/googlei18n/libphonenumber) by [giggsey](https://github.com/giggsey).
|
||||
|
||||
### Installation
|
||||
|
||||
@@ -19,7 +19,7 @@ composer require propaganistas/laravel-phone
|
||||
|
||||
**Laravel**
|
||||
|
||||
In your app config, add the Service Provider to the `$providers` array
|
||||
In your app config, add the Service Provider to the `$providers` array *(only for Laravel 5.4 or below)*:
|
||||
|
||||
```php
|
||||
'providers' => [
|
||||
@@ -42,40 +42,40 @@ In `bootstrap/app.php`, register the Service Provider
|
||||
$app->register(Propaganistas\LaravelPhone\LaravelPhoneServiceProvider::class);
|
||||
```
|
||||
|
||||
### Usage
|
||||
### Validator
|
||||
|
||||
To validate a field using the phone validator, use the `phone` keyword in your validation rules array. The phone validator is able to operate in **three** ways.
|
||||
|
||||
- You either specify [*ISO 3166-1 alpha-2 compliant*](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) country codes yourself as parameters for the validator, e.g.:
|
||||
|
||||
```php
|
||||
'phonefield' => 'phone:US,BE',
|
||||
'phonefield' => 'phone:US,BE',
|
||||
```
|
||||
|
||||
The validator will check if the number is valid in at least one of provided countries, so feel free to add as many country codes as you like.
|
||||
|
||||
- You don't specify any parameters but you plug in a dedicated country input field (keyed by *ISO 3166-1 compliant* country codes) to allow end users to supply a country on their own. The easiest method by far is to install the [CountryList package by monarobase](https://github.com/Monarobase/country-list). Make sure the country field is named similar as the phone field but with *_country* appended for automatic discovery, or provide your custom country field name as a parameter to the validator:
|
||||
- You don't specify any parameters but you plug in a dedicated country input field (keyed by *ISO 3166-1 compliant* country codes) to allow end users to supply a country on their own. The easiest method by far is to install the [Laravel-Intl](https://github.com/Propaganistas/Laravel-Intl) package. Make sure the country field is named similar as the phone field but with *_country* appended for automatic discovery, or provide your custom country field name as a parameter to the validator:
|
||||
|
||||
```php
|
||||
'phonefield' => 'phone',
|
||||
'phonefield_country' => 'required_with:phonefield',
|
||||
'phonefield' => 'phone',
|
||||
'phonefield_country' => 'required_with:phonefield',
|
||||
```
|
||||
|
||||
```php
|
||||
'phonefield' => 'phone:custom_country_field',
|
||||
'custom_country_field' => 'required_with:phonefield',
|
||||
'phonefield' => 'phone:custom_country_field',
|
||||
'custom_country_field' => 'required_with:phonefield',
|
||||
```
|
||||
|
||||
If using the CountryList package, you could then use the following snippet to populate a country selection list:
|
||||
If using [Laravel-Intl](https://github.com/Propaganistas/Laravel-Intl), you could then use the following snippet to populate a country selection list. It will automatically present translated country names according to your application locale:
|
||||
|
||||
```php
|
||||
Countries::getList(App::getLocale(), 'php', 'cldr'))
|
||||
Country::all()
|
||||
```
|
||||
|
||||
- You instruct the validator to detect which country the number belongs to using the `AUTO` keyword (and optionally any fallback countries):
|
||||
|
||||
```php
|
||||
'phonefield' => 'phone:AUTO,US',
|
||||
'phonefield' => 'phone:AUTO,US',
|
||||
```
|
||||
|
||||
The validator will try to extract the country from the number itself and then check if the number is valid for that country. If the country could not be guessed it will be validated using the fallback countries if provided. Note that country guessing will only work when phone numbers are entered in *international format* (prefixed with a `+` sign, e.g. +32 ....). Leading double zeros will **NOT** be parsed correctly as this isn't an established consistency.
|
||||
@@ -85,7 +85,7 @@ To specify constraints on the number type, just append the allowed types to the
|
||||
```php
|
||||
'phonefield' => 'phone:US,BE,mobile',
|
||||
```
|
||||
The most common types are `mobile` and `fixed_line`, but feel free to use any of the types defined [here](https://github.com/giggsey/libphonenumber-for-php/blob/master/src/libphonenumber/PhoneNumberType.php).
|
||||
The most common types are `mobile` and `fixed_line`, but feel free to use any of the types defined [here](https://github.com/giggsey/libphonenumber-for-php/blob/master/src/PhoneNumberType.php).
|
||||
|
||||
You can also enable more lenient validation (for example, fixed lines without area codes) by using the `LENIENT` parameter. This feature inherently doesn't play well with country autodetection and number type validation, so use such combo at own risk.
|
||||
|
||||
@@ -93,11 +93,11 @@ You can also enable more lenient validation (for example, fixed lines without ar
|
||||
'phonefield' => 'phone:LENIENT,US',
|
||||
```
|
||||
|
||||
### Helper function
|
||||
Format a fetched phone value using the `phone()` helper function. `$country_code` is the country the phone number belongs to.
|
||||
### Formatter
|
||||
Format a phone number using the `phone()` helper function. `$country_code` is the country the phone number belongs to.
|
||||
|
||||
```php
|
||||
phone($phone_number, $country_code = null, $format = PhoneNumberFormat::INTERNATIONAL)
|
||||
```
|
||||
If no `$country_code` was given, the current application locale will be used as default.
|
||||
The `$format` parameter is optional and should be a constant of `libphonenumber\PhoneNumberFormat` (defaults to `libphonenumber\PhoneNumberFormat::INTERNATIONAL`)
|
||||
Always try to provide a `$country_code` in order for the phone number to be recognized correctly. If no `$country_code` was given, the current application locale will be used as a sensible default.
|
||||
The `$format` parameter defines the output format and is optional. The format defaults to international format but can be any constant of `libphonenumber\PhoneNumberFormat`.
|
||||
|
||||
88
vendor/propaganistas/laravel-phone/composer.json
vendored
88
vendor/propaganistas/laravel-phone/composer.json
vendored
@@ -1,45 +1,51 @@
|
||||
{
|
||||
"name": "propaganistas/laravel-phone",
|
||||
"description": "Adds a phone validator to Laravel and Lumen based on Google's libphonenumber API.",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"lumen",
|
||||
"libphonenumber",
|
||||
"validation",
|
||||
"phone"
|
||||
],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Propaganistas",
|
||||
"email": "Propaganistas@users.noreply.github.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/support": "^4.0|^5.0",
|
||||
"illuminate/validation": "^4.0|^5.0",
|
||||
"giggsey/libphonenumber-for-php": "^7.0",
|
||||
"julien-c/iso3166": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"orchestra/testbench": "^2.0|^3.0",
|
||||
"phpunit/phpunit": "^4.0|^5.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Propaganistas\\LaravelPhone\\": "src/"
|
||||
"name": "propaganistas/laravel-phone",
|
||||
"description": "Adds a phone validator to Laravel and Lumen based on Google's libphonenumber API.",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"lumen",
|
||||
"libphonenumber",
|
||||
"validation",
|
||||
"phone"
|
||||
],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Propaganistas",
|
||||
"email": "Propaganistas@users.noreply.github.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"illuminate/support": "^4.0|^5.0",
|
||||
"illuminate/validation": "^4.0|^5.0",
|
||||
"giggsey/libphonenumber-for-php": "^7.0|^8.0",
|
||||
"julien-c/iso3166": "^2.0"
|
||||
},
|
||||
"files": [
|
||||
"src/helpers.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Propaganistas\\LaravelPhone\\Tests\\": "tests/"
|
||||
"require-dev": {
|
||||
"orchestra/testbench": "^2.0|^3.0",
|
||||
"phpunit/phpunit": "^4.0|^5.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Propaganistas\\LaravelPhone\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/helpers.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Propaganistas\\LaravelPhone\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"propaganistas/laravel-intl": "Adds internationalization functions, including a compatible and fully translated country list API."
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Propaganistas\\LaravelPhone\\LaravelPhoneServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"monarobase/country-list": "Adds a compatible (and fully translated) country list API."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="Package Test Suite">
|
||||
<directory suffix=".php">./tests/</directory>
|
||||
@@ -20,7 +19,4 @@
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-clover" target="./clover.xml"/>
|
||||
</logging>
|
||||
</phpunit>
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use ReflectionClass;
|
||||
|
||||
class LaravelPhoneServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
@@ -13,7 +13,9 @@ class LaravelPhoneServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->app['validator']->extend('phone', 'Propaganistas\LaravelPhone\PhoneValidator@validatePhone');
|
||||
$extend = static::canUseDependentValidation() ? 'extendDependent' : 'extend';
|
||||
|
||||
$this->app['validator']->{$extend}('phone', 'Propaganistas\LaravelPhone\PhoneValidator@validatePhone');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,4 +31,16 @@ class LaravelPhoneServiceProvider extends ServiceProvider
|
||||
|
||||
$this->app->alias('libphonenumber', 'libphonenumber\PhoneNumberUtil');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether we can register a dependent validator.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function canUseDependentValidation()
|
||||
{
|
||||
$validator = new ReflectionClass('\Illuminate\Validation\Factory');
|
||||
|
||||
return $validator->hasMethod('extendDependent');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use Illuminate\Support\Facades\App;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
|
||||
if (! function_exists('phone_format')) {
|
||||
if (! function_exists('phone')) {
|
||||
/**
|
||||
* Get the PhoneNumberUtil or format a phone number for display.
|
||||
*
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<?php namespace Propaganistas\LaravelPhone\Tests;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Orchestra\Testbench\TestCase;
|
||||
use Phone;
|
||||
use Propaganistas\LaravelPhone\LaravelPhoneServiceProvider;
|
||||
|
||||
class PhoneValidatorTest extends TestCase
|
||||
{
|
||||
@@ -32,26 +34,6 @@ class PhoneValidatorTest extends TestCase
|
||||
$this->validator = $this->app['validator'];
|
||||
}
|
||||
|
||||
private function performValidation($data)
|
||||
{
|
||||
$rule = 'phone' . (isset($data['rule']) ? ':' . $data['rule'] : '');
|
||||
|
||||
$input = array_except($data, ['rule']);
|
||||
$input['nested']['field'] = $input['field'];
|
||||
if (isset($input['field_country'])) {
|
||||
$input['nested']['field_country'] = $input['field_country'];
|
||||
}
|
||||
|
||||
$validator = $this->validator->make($input,
|
||||
[
|
||||
'field' => $rule,
|
||||
'nested.field' => $rule,
|
||||
]
|
||||
);
|
||||
|
||||
return $validator->passes();
|
||||
}
|
||||
|
||||
public function testFacade()
|
||||
{
|
||||
$phoneNumber = Phone::parse('650-429-2057', 'US');
|
||||
@@ -61,195 +43,187 @@ class PhoneValidatorTest extends TestCase
|
||||
public function testValidatePhoneWithDefaultCountryNoType()
|
||||
{
|
||||
// Validator with correct country field.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'BE',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:BE'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country value.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'NL',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:NL'])->passes()
|
||||
);
|
||||
|
||||
// Validator with multiple country values, one correct.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'BE,NL',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:BE,NL'])->passes()
|
||||
);
|
||||
|
||||
// Validator with multiple country values, value correct for second country in list.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'NL,BE',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:NL,BE'])->passes()
|
||||
);
|
||||
|
||||
// Validator with multiple wrong country values.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'DE,NL',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:DE,NL'])->passes()
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidatePhoneWithCountryFieldNoType()
|
||||
{
|
||||
// Validator with correct country field supplied.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'field_country' => 'BE',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '016123456', 'field_country' => 'BE'],
|
||||
['field' => 'phone'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country field supplied.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'field_country' => 'NL',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456', 'field_country' => 'NL'],
|
||||
['field' => 'phone'])->passes()
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidatePhoneWithDefaultCountryWithType()
|
||||
{
|
||||
// Validator with correct country value, correct type.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'BE,mobile',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '0499123456'],
|
||||
['field' => 'phone:BE,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country value, wrong type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'BE,mobile',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:BE,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country value, correct type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'NL,mobile',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '0499123456'],
|
||||
['field' => 'phone:NL,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country value, wrong type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'NL,mobile',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:NL,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with multiple country values, one correct, correct type.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'BE,NL,mobile',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '0499123456'],
|
||||
['field' => 'phone:BE,NL,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with multiple country values, one correct, wrong type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'BE,NL,mobile',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:BE,NL,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with multiple country values, none correct, correct type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'DE,NL,mobile',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '0499123456'],
|
||||
['field' => 'phone:DE,NL,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with multiple country values, none correct, wrong type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'DE,NL,mobile',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:DE,NL,mobile'])->passes()
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidatePhoneWithCountryFieldWithType()
|
||||
{
|
||||
// Validator with correct country field supplied, correct type.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'mobile',
|
||||
'field_country' => 'BE',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '0499123456', 'field_country' => 'BE'],
|
||||
['field' => 'phone:mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country field supplied, wrong type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'mobile',
|
||||
'field_country' => 'BE',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456', 'field_country' => 'BE'],
|
||||
['field' => 'phone:mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country field supplied, correct type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'mobile',
|
||||
'field_country' => 'NL',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '0499123456', 'field_country' => 'NL'],
|
||||
['field' => 'phone:mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country field supplied, wrong type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'mobile',
|
||||
'field_country' => 'NL',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456', 'field_country' => 'NL'],
|
||||
['field' => 'phone:mobile'])->passes()
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidatePhoneWithCustomCountryField()
|
||||
{
|
||||
// Validator with correct country field supplied, correct type.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'mobile,country_code',
|
||||
'country_code' => 'BE',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '0499123456', 'country_code' => 'BE'],
|
||||
['field' => 'phone:mobile,country_code'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country field supplied, wrong type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'mobile,country_code',
|
||||
'country_code' => 'BE',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456', 'country_code' => 'BE'],
|
||||
['field' => 'phone:mobile,country_code'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country field supplied, correct type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'mobile,country_code',
|
||||
'country_code' => 'NL',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '0499123456', 'country_code' => 'NL'],
|
||||
['field' => 'phone:mobile,country_code'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country field supplied, wrong type.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'mobile,country_code',
|
||||
'country_code' => 'NL',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456', 'country_code' => 'NL'],
|
||||
['field' => 'phone:mobile,country_code'])->passes()
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidatePhoneAutomaticDetectionFromInternationalInput()
|
||||
{
|
||||
// Validator with correct international input.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '+3216123456',
|
||||
'rule' => 'AUTO',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '+3216123456'],
|
||||
['field' => 'phone:AUTO'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong international input.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '003216123456',
|
||||
'rule' => 'AUTO',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '003216123456'],
|
||||
['field' => 'phone:AUTO'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong international input.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '+321456',
|
||||
'rule' => 'AUTO',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '+321234'],
|
||||
['field' => 'phone:AUTO'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong international input but correct default country.
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'AUTO,NL,BE',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:AUTO,NL,BE'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong international input and wrong default country.
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'AUTO,NL,DE',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:AUTO,DE,NL'])->passes()
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidatePhoneNoDefaultCountryNoCountryField()
|
||||
@@ -257,92 +231,91 @@ class PhoneValidatorTest extends TestCase
|
||||
$this->setExpectedException('Propaganistas\LaravelPhone\Exceptions\NoValidCountryFoundException');
|
||||
|
||||
// Validator with no country field or given country.
|
||||
$this->performValidation([
|
||||
'field' => '016123456',
|
||||
]);
|
||||
$this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone']
|
||||
)->passes();
|
||||
|
||||
// Validator with no country field or given country, wrong type.
|
||||
$this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'mobile',
|
||||
]);
|
||||
$this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:mobile']
|
||||
)->passes();
|
||||
|
||||
// Validator with no country field or given country, correct type.
|
||||
$this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'mobile',
|
||||
]);
|
||||
$this->validator->make(
|
||||
['field' => '0499359308'],
|
||||
['field' => 'phone:mobile']
|
||||
)->passes();
|
||||
|
||||
// Validator with no country field or given country, correct type, faulty parameter.
|
||||
$this->performValidation([
|
||||
'field' => '0499123456',
|
||||
'rule' => 'mobile,xyz',
|
||||
]);
|
||||
$this->validator->make(
|
||||
['field' => '0499359308'],
|
||||
['field' => 'phone:mobile,xyt']
|
||||
)->passes();
|
||||
}
|
||||
|
||||
public function testValidatePhoneLenient()
|
||||
{
|
||||
// Validator with AU area code, lenient off
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '88885555',
|
||||
'rule' => 'AU',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '88885555'],
|
||||
['field' => 'phone:AU'])->passes()
|
||||
);
|
||||
|
||||
// Validator with AU area code, lenient on
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '88885555',
|
||||
'rule' => 'LENIENT,AU',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '88885555'],
|
||||
['field' => 'phone:LENIENT,AU'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country field supplied, lenient on
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '88885555',
|
||||
'rule' => 'LENIENT',
|
||||
'field_country' => 'AU',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '88885555', 'field_country' => 'AU'],
|
||||
['field' => 'phone:LENIENT'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country field supplied, lenient on
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '88885555',
|
||||
'rule' => 'LENIENT',
|
||||
'field_country' => 'BE',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '88885555', 'field_country' => 'BE'],
|
||||
['field' => 'phone:LENIENT'])->passes()
|
||||
);
|
||||
|
||||
// Validator with no area code, lenient on
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '+16502530000',
|
||||
'rule' => 'LENIENT',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '+16502530000'],
|
||||
['field' => 'phone:LENIENT'])->passes()
|
||||
);
|
||||
|
||||
// Validator with US area code, lenient on
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '+16502530000',
|
||||
'rule' => 'LENIENT,US',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '+16502530000'],
|
||||
['field' => 'phone:LENIENT,US'])->passes()
|
||||
);
|
||||
|
||||
// Validator with no area code, lenient off
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '6502530000',
|
||||
'rule' => 'LENIENT',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '6502530000'],
|
||||
['field' => 'phone:LENIENT'])->passes()
|
||||
);
|
||||
|
||||
// Validator with US area code, lenient on
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '6502530000',
|
||||
'rule' => 'LENIENT,US',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '6502530000'],
|
||||
['field' => 'phone:LENIENT,US'])->passes()
|
||||
);
|
||||
|
||||
// Validator with US area code, lenient off
|
||||
$this->assertFalse($this->performValidation([
|
||||
'field' => '2530000',
|
||||
'rule' => 'LENIENT',
|
||||
]));
|
||||
$this->assertFalse($this->validator->make(
|
||||
['field' => '2530000'],
|
||||
['field' => 'phone:LENIENT'])->passes()
|
||||
);
|
||||
|
||||
// Validator with US area code, lenient on
|
||||
$this->assertTrue($this->performValidation([
|
||||
'field' => '2530000',
|
||||
'rule' => 'LENIENT,US',
|
||||
]));
|
||||
$this->assertTrue($this->validator->make(
|
||||
['field' => '2530000'],
|
||||
['field' => 'phone:LENIENT,US'])->passes()
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidatePhoneFaultyParameters()
|
||||
@@ -350,17 +323,131 @@ class PhoneValidatorTest extends TestCase
|
||||
$this->setExpectedException('Propaganistas\LaravelPhone\Exceptions\InvalidParameterException');
|
||||
|
||||
// Validator with given country, correct type, faulty parameter.
|
||||
$this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'BE,mobile,xyz',
|
||||
]);
|
||||
$this->validator->make(
|
||||
['field' => '016123456'],
|
||||
['field' => 'phone:BE,mobile,xyz']
|
||||
)->passes();
|
||||
|
||||
// Validator with country field, correct type, faulty parameter.
|
||||
$this->performValidation([
|
||||
'field' => '016123456',
|
||||
'rule' => 'mobile,xyz',
|
||||
'field_country' => 'BE',
|
||||
]);
|
||||
$this->validator->make(
|
||||
['field' => '016123456', 'field_country' => 'BE'],
|
||||
['field' => 'phone:mobile,xyz']
|
||||
)->passes();
|
||||
}
|
||||
|
||||
public function testValidatePhoneWithArrayInput()
|
||||
{
|
||||
if (LaravelPhoneServiceProvider::canUseDependentValidation()) {
|
||||
// Validator with correct country value.
|
||||
$this->assertTrue($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '016123456'],
|
||||
['field' => '0499123456']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone:BE'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong country value.
|
||||
$this->assertFalse($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '016123456'],
|
||||
['field' => '0499123456']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone:NL'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country value, one wrong input.
|
||||
$this->assertFalse($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '01612'],
|
||||
['field' => '0499123456']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone:BE'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country value, one wrong input.
|
||||
$this->assertFalse($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '016123456'],
|
||||
['field' => '049912']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone:BE'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country value.
|
||||
$this->assertTrue($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '0477123456'],
|
||||
['field' => '0499123456']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone:BE,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country value, one input wrong type.
|
||||
$this->assertFalse($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '016123456'],
|
||||
['field' => '0499123456']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone:BE,mobile'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country fields.
|
||||
$this->assertTrue($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '016123456', 'field_country' => 'BE'],
|
||||
['field' => '6502530000', 'field_country' => 'US']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct country fields.
|
||||
$this->assertFalse($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '016123456', 'field_country' => 'BE'],
|
||||
['field' => '6502530000', 'field_country' => 'BE']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone'])->passes()
|
||||
);
|
||||
|
||||
// Validator with correct custom country fields.
|
||||
$this->assertTrue($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '016123456', 'country_code' => 'BE'],
|
||||
['field' => '6502530000', 'country_code' => 'US']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone:container.*.country_code'])->passes()
|
||||
);
|
||||
|
||||
// Validator with wrong custom country fields.
|
||||
$this->assertFalse($this->validator->make(
|
||||
[
|
||||
'container' => [
|
||||
['field' => '016123456', 'country_code' => 'BE'],
|
||||
['field' => '6502530000', 'country_code' => 'BE']
|
||||
]
|
||||
],
|
||||
['container.*.field' => 'phone:container.*.country_code'])->passes()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testHelperFunction()
|
||||
@@ -378,5 +465,4 @@ class PhoneValidatorTest extends TestCase
|
||||
// Test fetching of util.
|
||||
$this->assertTrue(phone() instanceof PhoneNumberUtil);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user