Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Updated the PhoneNumber test to support arrays of possible phone numbers
to test against.
  • Loading branch information
EvanDotPro committed Mar 4, 2014
1 parent f5f8cf1 commit e4c17d1
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions test/Validator/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ class PhoneNumberTest extends \PHPUnit_Framework_TestCase
'patterns' => array(
'example' => array(
'fixed' => '21234567',
'mobile' => '81234567',
'mobile' => array('81234567','71234567'),
'tollfree' => '18001234',
'emergency' => '118',
),
Expand Down Expand Up @@ -3035,20 +3035,23 @@ public function testExampleNumbers()
{
foreach ($this->phone as $country => $parameters) {
$this->validator->setCountry($country);
foreach ($parameters['patterns']['example'] as $type => $value) {
$this->validator->allowedTypes(array($type));
$this->assertTrue($this->validator->isValid($value));
foreach ($parameters['patterns']['example'] as $type => $values) {
$values = is_array($values) ? $values : array($values);
foreach ($values as $value) {
$this->validator->allowedTypes(array($type));
$this->assertTrue($this->validator->isValid($value));

// check with country code:
$countryCodePrefixed = $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($countryCodePrefixed));
// check with country code:
$countryCodePrefixed = $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($countryCodePrefixed));

// check fully qualified E.123/E.164 international variants
$fullyQualifiedDoubleO = '00' . $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($fullyQualifiedDoubleO));
// check fully qualified E.123/E.164 international variants
$fullyQualifiedDoubleO = '00' . $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($fullyQualifiedDoubleO));

$fullyQualifiedPlus = '+' . $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($fullyQualifiedPlus));
$fullyQualifiedPlus = '+' . $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($fullyQualifiedPlus));
}
}
}
}
Expand All @@ -3058,20 +3061,23 @@ public function testExampleNumbersAgainstPossible()
$this->validator->allowPossible(true);
foreach ($this->phone as $country => $parameters) {
$this->validator->setCountry($country);
foreach ($parameters['patterns']['example'] as $type => $value) {
$this->validator->allowedTypes(array($type));
$this->assertTrue($this->validator->isValid($value));
foreach ($parameters['patterns']['example'] as $type => $values) {
$values = is_array($values) ? $values : array($values);
foreach ($values as $value) {
$this->validator->allowedTypes(array($type));
$this->assertTrue($this->validator->isValid($value));

// check with country code:
$countryCodePrefixed = $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($countryCodePrefixed));
// check with country code:
$countryCodePrefixed = $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($countryCodePrefixed));

// check fully qualified E.123/E.164 international variants
$fullyQualifiedDoubleO = '00'. $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($fullyQualifiedDoubleO), $fullyQualifiedDoubleO);
// check fully qualified E.123/E.164 international variants
$fullyQualifiedDoubleO = '00'. $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($fullyQualifiedDoubleO), $fullyQualifiedDoubleO);

$fullyQualifiedPlus = '+'. $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($fullyQualifiedPlus), $fullyQualifiedPlus);
$fullyQualifiedPlus = '+'. $parameters['code'] . $value;
$this->assertTrue($this->validator->isValid($fullyQualifiedPlus), $fullyQualifiedPlus);
}
}
}
}
Expand Down

0 comments on commit e4c17d1

Please sign in to comment.