From 48b3a6a236d229a203f5c20c705c901ee43ca4c2 Mon Sep 17 00:00:00 2001 From: knut <> Date: Mon, 30 Jan 2006 21:30:35 +0000 Subject: - Ported a few unit tests from the I18N package - Moving report stylesheets to buildscripts/phing - Added a build/dist target for both standard distribution and PEAR package to build.xml --- tests/unit/I18N/core/CultureInfoTest.php | 81 +++++++++++++++++++ tests/unit/I18N/core/NumberFormatInfoTest.php | 88 ++++++++++++++++++++ tests/unit/I18N/core/NumberFormatTest.php | 111 ++++++++++++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100644 tests/unit/I18N/core/CultureInfoTest.php create mode 100644 tests/unit/I18N/core/NumberFormatInfoTest.php create mode 100644 tests/unit/I18N/core/NumberFormatTest.php (limited to 'tests/unit/I18N/core') diff --git a/tests/unit/I18N/core/CultureInfoTest.php b/tests/unit/I18N/core/CultureInfoTest.php new file mode 100644 index 00000000..14b60ece --- /dev/null +++ b/tests/unit/I18N/core/CultureInfoTest.php @@ -0,0 +1,81 @@ +culture = CultureInfo::getInvariantCulture(); + } + + function testCultureName() { + $name = 'en'; + + $this->assertEquals($name, $this->culture->Name); + + //the default/invariant culture should be neutral + $this->assertTrue($this->culture->IsNeutralCulture); + } + + function testCultureList() { + $allCultures = CultureInfo::getCultures(); + $neutralCultures = CultureInfo::getCultures(CultureInfo::NEUTRAL); + $specificCultures = CultureInfo::getCultures(CultureInfo::SPECIFIC); + + //there should be 246 cultures all together. + $this->assertEquals(count($allCultures),246); + $this->assertEquals(count($neutralCultures),76); + $this->assertEquals(count($specificCultures),170); + } + + function testParentCultures() { + $zh_CN = new CultureInfo('zh_CN'); + $parent = $zh_CN->Parent; + $grandparent = $parent->Parent; + + $this->assertEquals($zh_CN->Name, 'zh_CN'); + $this->assertEquals($parent->Name, 'zh'); + $this->assertEquals($grandparent->Name, 'en'); + $this->assertEquals($grandparent->Parent->Name, 'en'); + } + + function testCountryNames() { + $culture = new CultureInfo('fr_FR'); + $this->assertEquals($culture->Countries['AE'], 'Émirats arabes unis'); + } + + function testCurrencies() { + $culture = new CultureInfo('en_AU'); + $au = array('$', 'Australian Dollar'); + $this->assertEquals($au, $culture->Currencies['AUD']); + } + + function testLanguages() { + $culture = new CultureInfo('fr_BE'); + $this->assertEquals($culture->Languages['fr'], 'français'); + } + + function testScripts() { + $culture = new CultureInfo('fr'); + $this->assertEquals($culture->Scripts['Armn'], 'arménien'); + } + + function testTimeZones() { + $culture = new CultureInfo('fi'); + $zone = array( + "America/Los_Angeles", + "Tyynenmeren normaaliaika", + "PST", + "Tyynenmeren kesäaika", + "PDT", + "Los Angeles"); + $this->assertEquals($culture->TimeZones[1],$zone); + } +} + +?> \ No newline at end of file diff --git a/tests/unit/I18N/core/NumberFormatInfoTest.php b/tests/unit/I18N/core/NumberFormatInfoTest.php new file mode 100644 index 00000000..a3b6d05a --- /dev/null +++ b/tests/unit/I18N/core/NumberFormatInfoTest.php @@ -0,0 +1,88 @@ +assertEquals($numberInfo->DecimalDigits,2); + $this->assertEquals($numberInfo->DecimalSeparator,'.'); + $this->assertEquals($numberInfo->GroupSeparator,','); + + //there should be only 1 grouping of size 3 + $groupsize = array(3,false); + $this->assertEquals($numberInfo->GroupSizes, $groupsize); + + //the default negative pattern prefix and postfix + $negPattern = array('-¤',''); + $this->assertEquals($numberInfo->NegativePattern, $negPattern); + + //the default positive pattern prefix and postfix + $negPattern = array('¤',''); + $this->assertEquals($numberInfo->PositivePattern, $negPattern); + + //the default currency symbol + $this->assertEquals($numberInfo->CurrencySymbol, 'US$'); + $this->assertEquals($numberInfo->getCurrencySymbol('JPY'), '¥'); + $this->assertEquals($numberInfo->NegativeInfinitySymbol, '-∞'); + $this->assertEquals($numberInfo->PositiveInfinitySymbol, '+∞'); + $this->assertEquals($numberInfo->NegativeSign, '-'); + $this->assertEquals($numberInfo->PositiveSign, '+'); + $this->assertEquals($numberInfo->NaNSymbol, '�'); + $this->assertEquals($numberInfo->PercentSymbol, '%'); + $this->assertEquals($numberInfo->PerMilleSymbol, '‰'); + } + + function testPatternsSet() { + $numberInfo = NumberFormatInfo::getInstance(); + + $numberInfo->DecimalDigits = 0; + $this->assertEquals($numberInfo->DecimalDigits,0); + + $numberInfo->DecimalSeparator = ','; + $this->assertEquals($numberInfo->DecimalSeparator,','); + + $numberInfo->GroupSeparator = ' '; + $this->assertEquals($numberInfo->GroupSeparator,' '); + + $numberInfo->GroupSizes = array(2,3); + $groupsize = array(2,3); + $this->assertEquals($numberInfo->GroupSizes, $groupsize); + + $numberInfo->NegativePattern = array('-$$','.'); + $negPattern = array('-$$','.'); + $this->assertEquals($numberInfo->NegativePattern, $negPattern); + + $numberInfo->PositivePattern = array('YY','.'); + $negPattern = array('YY','.'); + $this->assertEquals($numberInfo->PositivePattern, $negPattern); + + //the default CurrencySymbol symbol + $numberInfo->CurrencySymbol = '$$$'; + $this->assertEquals($numberInfo->CurrencySymbol, '$$$'); + } + + function testLocalizedPatterns() { + $fr = NumberFormatInfo::getInstance('fr'); + $de = NumberFormatInfo::getInstance('de'); + $en = NumberFormatInfo::getInstance('en_US'); + + $this->assertEquals($fr->DecimalSeparator, ','); + $this->assertEquals($de->DecimalSeparator, ','); + $this->assertEquals($en->DecimalSeparator, '.'); + + $this->assertEquals($fr->GroupSeparator, ' '); + $this->assertEquals($de->GroupSeparator, '.'); + $this->assertEquals($en->GroupSeparator, ','); + } +} + +?> \ No newline at end of file diff --git a/tests/unit/I18N/core/NumberFormatTest.php b/tests/unit/I18N/core/NumberFormatTest.php new file mode 100644 index 00000000..af6a06ca --- /dev/null +++ b/tests/unit/I18N/core/NumberFormatTest.php @@ -0,0 +1,111 @@ +assertEquals($wanted, $formatter->format($number)); + + //currency + $wanted = 'US$123,456,789.13'; + $this->assertEquals($wanted, $formatter->format($number,'c')); + } + + function testLocalizedCurrencyFormats() { + $fr = new NumberFormat('fr'); + $de = new NumberFormat('de'); + $ja = new NumberFormat('ja_JP'); + + $number = '123456789.125156'; + + //french + $wanted = '123 456 789,13 F'; + $this->assertEquals($wanted, $fr->format($number,'c','FRF')); + + //german + $wanted = 'DES 123.456.789,13'; + $this->assertEquals($wanted, $de->format($number,'c','DES')); + + //japanese + $wanted = '¥123,456,789'; + $this->assertEquals($wanted, $ja->format($number,'c','JPY')); + + //custom/unkown currency + $wanted = 'DLL123,456,789'; + $this->assertEquals($wanted, $ja->format($number,'c','DLL')); + } + + function testCustomFormat() { + $formatter = new NumberFormat(); + $number = '123456789.125156'; + + //primay and secondary grouping test + $pattern = '#,###,##.###'; + $wanted = '1,234,567,89.125156'; + $this->assertEquals($wanted, $formatter->format($number, $pattern)); + + //4 digits grouping test + $pattern = '#,####.###'; + $wanted = '1,2345,6789.125156'; + $this->assertEquals($wanted, $formatter->format($number, $pattern)); + + //custom percentage + $pattern = '#,###.00%'; + $wanted = '123,456,789.13%'; + $this->assertEquals($wanted, $formatter->format($number, $pattern)); + } + + function testPercentageFormat() { + $formatter = new NumberFormat(); + $number = '0.125156'; + $wanted = '12%'; + $this->assertEquals($wanted, $formatter->format($number, 'p')); + } + + function testQuotes() { + $formatter = new NumberFormat(); + $number = '123456789.125156'; + + $pattern = "# o'clock"; + $wanted = "123456789 o'clock"; + $this->assertEquals($wanted, $formatter->format($number, $pattern)); + + } + + function testPadding() { + $formatter = new NumberFormat(); + $number = '5'; + + $pattern = '0000'; + $wanted = '0005'; + + //this should fail!!! + $this->assertNotEquals($wanted, $formatter->format($number, $pattern)); + } + + function testFormatWithANegativeValue() { + $formatter = new NumberFormat(); + $number = "-1.2"; + + $wanted = "-1.2"; + $this->assertEquals($wanted, $formatter->format($number)); + } + + public function testFormatWithAScientificPattern() { + $formatter = new NumberFormat(); + $number = "10"; + $expected = "10E"; + $this->assertEquals('10E', $formatter->format($number, 'e')); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3