From de5adecf74fcf71b55c48efaa18d83fffbf06ce5 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Wed, 7 Mar 2018 23:32:04 +0000 Subject: [PATCH 1/3] [Intl] Add basic tests for the Intl class --- src/Symfony/Component/Intl/Tests/IntlTest.php | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/Symfony/Component/Intl/Tests/IntlTest.php diff --git a/src/Symfony/Component/Intl/Tests/IntlTest.php b/src/Symfony/Component/Intl/Tests/IntlTest.php new file mode 100644 index 0000000000000..fd614f616eea1 --- /dev/null +++ b/src/Symfony/Component/Intl/Tests/IntlTest.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Tests; + +use Symfony\Component\Intl\Intl; +use PHPUnit\Framework\TestCase; + +class IntlTest extends TestCase +{ + /** + * @requires extension intl + */ + public function testIsExtensionLoadedChecksIfIntlExtensionIsLoaded() + { + $this->assertTrue(Intl::isExtensionLoaded()); + } + + public function testGetCurrencyBundleCreatesTheCurrencyBundle() + { + $this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface', Intl::getCurrencyBundle()); + } + + public function testGetLanguageBundleCreatesTheLanguageBundle() + { + $this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LanguageBundleInterface', Intl::getLanguageBundle()); + } + + public function testGetLocaleBundleCreatesTheLocaleBundle() + { + $this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle()); + } + + public function testGetRegionBundleCreatesTheRegionBundle() + { + $this->assertInstanceOf('Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface', Intl::getLocaleBundle()); + } + + public function testGetIcuVersionReadsTheVersionOfInstalledIcuLibrary() + { + $this->assertStringMatchesFormat('%d.%d', Intl::getIcuVersion()); + } + + public function testGetIcuDataVersionReadsTheVersionOfInstalledIcuData() + { + $this->assertStringMatchesFormat('%d.%d', Intl::getIcuDataVersion()); + } + + public function testGetIcuStubVersionReadsTheVersionOfBundledStubs() + { + $this->assertStringMatchesFormat('%d.%d', Intl::getIcuStubVersion()); + } + + public function testGetDataDirectoryReturnsThePathToIcuData() + { + $this->assertDirectoryExists(Intl::getDataDirectory()); + } +} From 7e5c8efc3582cc9b2928a3e9d84b12568577ca31 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Wed, 7 Mar 2018 23:51:23 +0000 Subject: [PATCH 2/3] [Intl] Load locale aliases to support alias fallbacks For example, zh_TW is an alias to zh_Hant_TW. Without aliases, zh_TW would fall back to zh (which is incorrect). With aliases loaded, zh_TW will fall back properly to zh_Hant_TW. --- src/Symfony/Component/Intl/Intl.php | 6 ++++++ src/Symfony/Component/Intl/Tests/IntlTest.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Symfony/Component/Intl/Intl.php b/src/Symfony/Component/Intl/Intl.php index 3444c10f83435..e552b994fd361 100644 --- a/src/Symfony/Component/Intl/Intl.php +++ b/src/Symfony/Component/Intl/Intl.php @@ -15,6 +15,7 @@ use Symfony\Component\Intl\Data\Bundle\Reader\BufferedBundleReader; use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReader; use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface; +use Symfony\Component\Intl\Data\Provider\LocaleDataProvider; use Symfony\Component\Intl\Data\Provider\ScriptDataProvider; use Symfony\Component\Intl\ResourceBundle\CurrencyBundle; use Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface; @@ -259,6 +260,11 @@ private static function getEntryReader() new JsonBundleReader(), self::BUFFER_SIZE )); + $localeDataProvider = new LocaleDataProvider( + self::getDataDirectory().'/'.self::LOCALE_DIR, + self::$entryReader + ); + self::$entryReader->setLocaleAliases($localeDataProvider->getAliases()); } return self::$entryReader; diff --git a/src/Symfony/Component/Intl/Tests/IntlTest.php b/src/Symfony/Component/Intl/Tests/IntlTest.php index fd614f616eea1..db58346ed391d 100644 --- a/src/Symfony/Component/Intl/Tests/IntlTest.php +++ b/src/Symfony/Component/Intl/Tests/IntlTest.php @@ -63,4 +63,22 @@ public function testGetDataDirectoryReturnsThePathToIcuData() { $this->assertDirectoryExists(Intl::getDataDirectory()); } + + /** + * @requires extension intl + */ + public function testLocaleAliasesAreLoaded() + { + \Locale::setDefault('zh_TW'); + $countryNameZhTw = Intl::getRegionBundle()->getCountryName('AD'); + + \Locale::setDefault('zh_Hant_TW'); + $countryNameHantZhTw = Intl::getRegionBundle()->getCountryName('AD'); + + \Locale::setDefault('zh'); + $countryNameZh = Intl::getRegionBundle()->getCountryName('AD'); + + $this->assertSame($countryNameZhTw, $countryNameHantZhTw, 'zh_TW is an alias to zh_Hant_TW'); + $this->assertNotSame($countryNameZh, $countryNameZhTw, 'zh_TW does not fall back to zh'); + } } From da80cfc807f4224db76fec8a7dac66d1b36aee22 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Thu, 8 Mar 2018 00:13:26 +0000 Subject: [PATCH 3/3] [Intl] Support older phpunit versions --- src/Symfony/Component/Intl/Tests/IntlTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Intl/Tests/IntlTest.php b/src/Symfony/Component/Intl/Tests/IntlTest.php index db58346ed391d..d77655b77d476 100644 --- a/src/Symfony/Component/Intl/Tests/IntlTest.php +++ b/src/Symfony/Component/Intl/Tests/IntlTest.php @@ -61,7 +61,7 @@ public function testGetIcuStubVersionReadsTheVersionOfBundledStubs() public function testGetDataDirectoryReturnsThePathToIcuData() { - $this->assertDirectoryExists(Intl::getDataDirectory()); + $this->assertTrue(is_dir(Intl::getDataDirectory())); } /** pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy