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

Commit

Permalink
Merge branch 'hotfix/42'
Browse files Browse the repository at this point in the history
Close #42
  • Loading branch information
weierophinney committed Jun 7, 2016
2 parents 0276e9d + b7a1803 commit 235281f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#42](https://github.com/zendframework/zend-i18n/pull/42) fixes the
behavior of the `PhoneNumber` validator to store the country using the casing
provided, but validate based on the uppercased country value. This ensures
the same validation behavior, and prevents the value from being transformed,
potentially breaking later retrieval.

## 2.7.2 - 2016-04-18

Expand Down
6 changes: 3 additions & 3 deletions src/Validator/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function getCountry()
*/
public function setCountry($country)
{
$this->country = strtoupper($country);
$this->country = $country;

return $this;
}
Expand Down Expand Up @@ -201,12 +201,12 @@ public function isValid($value = null, $context = null)

$country = $this->getCountry();

if (!$countryPattern = $this->loadPattern($country)) {
if (!$countryPattern = $this->loadPattern(strtoupper($country))) {
if (isset($context[$country])) {
$country = $context[$country];
}

if (!$countryPattern = $this->loadPattern($country)) {
if (!$countryPattern = $this->loadPattern(strtoupper($country))) {
$this->error(self::UNSUPPORTED);

return false;
Expand Down
18 changes: 15 additions & 3 deletions test/Validator/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3164,10 +3164,12 @@ public function testAllowPossibleSetterGetter()
$this->assertTrue($this->validator->allowPossible());
}

public function testSetCountryMethodIsCaseInsensitive()
public function testCountryIsCaseInsensitive()
{
$this->validator->setCountry('us');
$this->assertSame('US', $this->validator->getCountry());
$this->validator->setCountry('lt');
$this->assertTrue($this->validator->isValid('+37067811268'));
$this->validator->setCountry('LT');
$this->assertTrue($this->validator->isValid('+37067811268'));
}

/**
Expand Down Expand Up @@ -3202,4 +3204,14 @@ public function testInvalidTypes($country, $code, $patterns)
}
}
}

public function testCanSpecifyCountryWithContext()
{
Locale::setDefault('ZW');
$validator = new PhoneNumber([
'country' => 'country-code',
]);

$this->assertTrue($validator->isValid('+37067811268', ['country-code' => 'LT']));
}
}

0 comments on commit 235281f

Please sign in to comment.