Skip to content

Commit

Permalink
Update PhoneValidatorTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Propaganistas authored Aug 10, 2020
1 parent e1ccf35 commit 4e0c8b1
Showing 1 changed file with 99 additions and 102 deletions.
201 changes: 99 additions & 102 deletions tests/PhoneValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use libphonenumber\PhoneNumberType;
use Propaganistas\LaravelPhone\Rules\Phone as Rule;
use Propaganistas\LaravelPhone\PhoneServiceProvider;
use Propaganistas\LaravelPhone\Exceptions\InvalidParameterException;

class PhoneValidatorTest extends TestCase
Expand Down Expand Up @@ -360,117 +359,115 @@ public function it_validates_lenient()
/** @test */
public function it_validates_array_input()
{
if (PhoneServiceProvider::canUseDependentValidation()) {
// Validator with correct country value.
$this->assertTrue($this->validator->make(
[
'container' => [
['field' => '012345678'],
['field' => '0470123456'],
],
// Validator with correct country value.
$this->assertTrue($this->validator->make(
[
'container' => [
['field' => '012345678'],
['field' => '0470123456'],
],
['container.*.field' => 'phone:BE'])->passes()
);

// Validator with wrong country value.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678'],
['field' => '0470123456'],
],
],
['container.*.field' => 'phone:BE'])->passes()
);

// Validator with wrong country value.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678'],
['field' => '0470123456'],
],
['container.*.field' => 'phone:NL'])->passes()
);

// Validator with correct country value, one wrong input.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '01234'],
['field' => '0470123456'],
],
],
['container.*.field' => 'phone:NL'])->passes()
);

// Validator with correct country value, one wrong input.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '01234'],
['field' => '0470123456'],
],
['container.*.field' => 'phone:BE'])->passes()
);

// Validator with correct country value, one wrong input.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678'],
['field' => '047012'],
],
],
['container.*.field' => 'phone:BE'])->passes()
);

// Validator with correct country value, one wrong input.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678'],
['field' => '047012'],
],
['container.*.field' => 'phone:BE'])->passes()
);

// Validator with correct country value.
$this->assertTrue($this->validator->make(
[
'container' => [
['field' => '0470123456'],
['field' => '0471123456'],
],
],
['container.*.field' => 'phone:BE'])->passes()
);

// Validator with correct country value.
$this->assertTrue($this->validator->make(
[
'container' => [
['field' => '0470123456'],
['field' => '0471123456'],
],
['container.*.field' => 'phone:BE,mobile'])->passes()
);

// Validator with correct country value, one input wrong type.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678'],
['field' => '0470123456'],
],
],
['container.*.field' => 'phone:BE,mobile'])->passes()
);

// Validator with correct country value, one input wrong type.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678'],
['field' => '0470123456'],
],
['container.*.field' => 'phone:BE,mobile'])->passes()
);

// Validator with correct country fields.
$this->assertTrue($this->validator->make(
[
'container' => [
['field' => '012345678', 'field_country' => 'BE'],
['field' => '2015550123', 'field_country' => 'US'],
],
],
['container.*.field' => 'phone:BE,mobile'])->passes()
);

// Validator with correct country fields.
$this->assertTrue($this->validator->make(
[
'container' => [
['field' => '012345678', 'field_country' => 'BE'],
['field' => '2015550123', 'field_country' => 'US'],
],
['container.*.field' => 'phone'])->passes()
);

// Validator with correct country fields.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678', 'field_country' => 'BE'],
['field' => '2015550123', 'field_country' => 'BE'],
],
],
['container.*.field' => 'phone'])->passes()
);

// Validator with correct country fields.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678', 'field_country' => 'BE'],
['field' => '2015550123', 'field_country' => 'BE'],
],
['container.*.field' => 'phone'])->passes()
);

// Validator with correct custom country fields.
$this->assertTrue($this->validator->make(
[
'container' => [
['field' => '012345678', 'country_code' => 'BE'],
['field' => '2015550123', 'country_code' => 'US'],
],
],
['container.*.field' => 'phone'])->passes()
);

// Validator with correct custom country fields.
$this->assertTrue($this->validator->make(
[
'container' => [
['field' => '012345678', 'country_code' => 'BE'],
['field' => '2015550123', 'country_code' => 'US'],
],
['container.*.field' => 'phone:container.*.country_code'])->passes()
);

// Validator with wrong custom country fields.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678', 'country_code' => 'BE'],
['field' => '2015550123', 'country_code' => 'BE'],
],
],
['container.*.field' => 'phone:container.*.country_code'])->passes()
);

// Validator with wrong custom country fields.
$this->assertFalse($this->validator->make(
[
'container' => [
['field' => '012345678', 'country_code' => 'BE'],
['field' => '2015550123', 'country_code' => 'BE'],
],
['container.*.field' => 'phone:container.*.country_code'])->passes()
);
}
],
['container.*.field' => 'phone:container.*.country_code'])->passes()
);
}

/** @test */
Expand Down

0 comments on commit 4e0c8b1

Please sign in to comment.