Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Locale aware fix #5034

Merged
merged 2 commits into from

3 participants

@corentin-larose
  • This patch makes PhoneNumber validator locale aware.
  • This installs a new dependency on INTL extension which was already there for a lot of filters/validators in Zend/I18n.
  • If agreed, I will add unit tests.
@weierophinney

@corentin-larose Go for it.

@Maks3w
Collaborator

Closed due inactivity

@Maks3w Maks3w closed this
@corentin-larose

Sorry for inactivity, added U.T in #5312, I think this fix is very important !

@Maks3w Maks3w reopened this
@Maks3w Maks3w was assigned
@Maks3w Maks3w merged commit 1dfd2e8 into from
@corentin-larose corentin-larose deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 27, 2013
  1. @corentin-larose
Commits on Oct 21, 2013
  1. @corentin-larose

    Added U.T

    corentin-larose authored
This page is out of date. Refresh to see the latest.
View
4 library/Zend/I18n/Validator/PhoneNumber.php
@@ -9,6 +9,7 @@
namespace Zend\I18n\Validator;
+use Locale;
use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\AbstractValidator;
@@ -86,6 +87,9 @@ public function __construct($options = array())
if (array_key_exists('country', $options)) {
$this->setCountry($options['country']);
+ } else {
+ $country = Locale::getRegion(Locale::getDefault());
+ $this->setCountry($country);
}
if (array_key_exists('allowed_types', $options)) {
View
47 tests/ZendTest/I18n/Validator/PhoneNumberTest.php
@@ -10,6 +10,7 @@
namespace Zend\I18nTest\Validator;
+use Locale;
use Zend\I18n\Validator\PhoneNumber;
class PhoneNumberTest extends \PHPUnit_Framework_TestCase
@@ -3032,6 +3033,49 @@ public function setUp()
$this->validator = new PhoneNumber();
}
+ /**
+ * @covers PhoneNumber::__construct()
+ * @dataProvider constructDataProvider
+ *
+ * @param array $args
+ * @param array $options
+ * @param string $locale
+ */
+ public function testConstruct(array $args, array $options, $locale = null)
+ {
+ if ($locale) {
+ Locale::setDefault($locale);
+ }
+
+ $validator = new PhoneNumber($args);
+
+ $this->assertSame($options['country'], $validator->getCountry());
+ }
+
+ public function constructDataProvider()
+ {
+ return array(
+ array(
+ array(),
+ array('country' => Locale::getRegion(Locale::getDefault())),
+ null
+ ),
+ array(
+ array(),
+ array('country' => 'CN'),
+ 'zh_CN'
+ ),
+ array(
+ array('country' => 'CN'),
+ array('country' => 'CN'),
+ null
+ ),
+ );
+ }
+
+ /**
+ * @TODO: use dataProvider for this in order to enforce clean context
+ */
public function testExampleNumbers()
{
foreach ($this->phone as $country => $parameters) {
@@ -3046,6 +3090,9 @@ public function testExampleNumbers()
}
}
+ /**
+ * @TODO: use dataProvider for this in order to enforce clean context
+ */
public function testExampleNumbersAgainstPossible()
{
$this->validator->allowPossible(true);
Something went wrong with that request. Please try again.