From 52d8676399117dde482cc7e30a0474c02d5438a9 Mon Sep 17 00:00:00 2001 From: Douglas Greenshields Date: Wed, 24 Jul 2013 15:40:20 +0100 Subject: [PATCH] [Intl] made RegionBundle and LanguageBundle merge fallback data when using a country-specific locale --- .../Component/Intl/ResourceBundle/LanguageBundle.php | 6 +++--- .../Component/Intl/ResourceBundle/RegionBundle.php | 4 ++-- .../Intl/Tests/ResourceBundle/RegionBundleTest.php | 4 ++-- .../Tests/Constraints/CountryValidatorTest.php | 10 ++++++++++ .../Tests/Constraints/LanguageValidatorTest.php | 12 ++++++++++++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php b/src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php index c449f9c1996cd..6b98a29e39741 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php +++ b/src/Symfony/Component/Intl/ResourceBundle/LanguageBundle.php @@ -27,7 +27,7 @@ public function getLanguageName($lang, $region = null, $locale = null) $locale = \Locale::getDefault(); } - if (null === ($languages = $this->readEntry($locale, array('Languages')))) { + if (null === ($languages = $this->readEntry($locale, array('Languages'), true))) { return null; } @@ -49,7 +49,7 @@ public function getLanguageNames($locale = null) $locale = \Locale::getDefault(); } - if (null === ($languages = $this->readEntry($locale, array('Languages')))) { + if (null === ($languages = $this->readEntry($locale, array('Languages'), true))) { return array(); } @@ -102,7 +102,7 @@ public function getScriptNames($locale = null) $locale = \Locale::getDefault(); } - if (null === ($scripts = $this->readEntry($locale, array('Scripts')))) { + if (null === ($scripts = $this->readEntry($locale, array('Scripts'), true))) { return array(); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php b/src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php index a3cd9bd39a436..bbfbedeed9ddf 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php +++ b/src/Symfony/Component/Intl/ResourceBundle/RegionBundle.php @@ -27,7 +27,7 @@ public function getCountryName($country, $locale = null) $locale = \Locale::getDefault(); } - return $this->readEntry($locale, array('Countries', $country)); + return $this->readEntry($locale, array('Countries', $country), true); } /** @@ -39,7 +39,7 @@ public function getCountryNames($locale = null) $locale = \Locale::getDefault(); } - if (null === ($countries = $this->readEntry($locale, array('Countries')))) { + if (null === ($countries = $this->readEntry($locale, array('Countries'), true))) { return array(); } diff --git a/src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php b/src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php index ccdf904c91366..8155040806732 100644 --- a/src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php +++ b/src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php @@ -40,7 +40,7 @@ public function testGetCountryName() { $this->reader->expects($this->once()) ->method('readEntry') - ->with(self::RES_DIR, 'en', array('Countries', 'AT')) + ->with(self::RES_DIR, 'en', array('Countries', 'AT'), true) ->will($this->returnValue('Austria')); $this->assertSame('Austria', $this->bundle->getCountryName('AT', 'en')); @@ -55,7 +55,7 @@ public function testGetCountryNames() $this->reader->expects($this->once()) ->method('readEntry') - ->with(self::RES_DIR, 'en', array('Countries')) + ->with(self::RES_DIR, 'en', array('Countries'), true) ->will($this->returnValue($sortedCountries)); $this->assertSame($sortedCountries, $this->bundle->getCountryNames('en')); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php index 3eedaa32643f6..95851e8097ad7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php @@ -104,4 +104,14 @@ public function getInvalidCountries() array('EN'), ); } + + public function testValidateUsingCountrySpecificLocale() + { + \Locale::setDefault('en_GB'); + $existingCountry = 'GB'; + $this->context->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate($existingCountry, new Country()); + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php index 1230e3f322afe..3588887d74998 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php @@ -104,4 +104,16 @@ public function getInvalidLanguages() array('foobar'), ); } + + public function testValidateUsingCountrySpecificLocale() + { + \Locale::setDefault('fr_FR'); + $existingLanguage = 'en'; + $this->context->expects($this->never()) + ->method('addViolation'); + + $this->validator->validate($existingLanguage, new Language(array( + 'message' => 'aMessage' + ))); + } }