aboutsummaryrefslogtreecommitdiffstats
path: root/library/intl/tests/NumberFormat
diff options
context:
space:
mode:
authorStefan Parviainen <saparvia@caterva.eu>2014-12-31 10:42:08 +0100
committerStefan Parviainen <saparvia@caterva.eu>2014-12-31 10:42:08 +0100
commit7bf7f8180dbc3a89824815de3bc1e4f40857d2f6 (patch)
tree34e51239e753204989af7d82793c24bb3b304ecb /library/intl/tests/NumberFormat
parent24a16434bccb7b41d026767f81ffe5f060d566bf (diff)
downloadvolse-hubzilla-7bf7f8180dbc3a89824815de3bc1e4f40857d2f6.tar.gz
volse-hubzilla-7bf7f8180dbc3a89824815de3bc1e4f40857d2f6.tar.bz2
volse-hubzilla-7bf7f8180dbc3a89824815de3bc1e4f40857d2f6.zip
Revert "Revert "Language names via intl library.""
This reverts commit 4f35efa0bad4ae6489b63f3eebafe6542d654094.
Diffstat (limited to 'library/intl/tests/NumberFormat')
-rw-r--r--library/intl/tests/NumberFormat/NumberFormatRepositoryTest.php69
-rw-r--r--library/intl/tests/NumberFormat/NumberFormatTest.php131
2 files changed, 200 insertions, 0 deletions
diff --git a/library/intl/tests/NumberFormat/NumberFormatRepositoryTest.php b/library/intl/tests/NumberFormat/NumberFormatRepositoryTest.php
new file mode 100644
index 000000000..41e45805d
--- /dev/null
+++ b/library/intl/tests/NumberFormat/NumberFormatRepositoryTest.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace CommerceGuys\Intl\Tests\NumberFormat;
+
+use CommerceGuys\Intl\NumberFormat\NumberFormatRepository;
+use org\bovigo\vfs\vfsStream;
+
+/**
+ * @coversDefaultClass \CommerceGuys\Intl\NumberFormat\NumberFormatRepository
+ */
+class NumberFormatRepositoryTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * English number format definition.
+ *
+ * @var array
+ */
+ protected $englishDefinition = array(
+ 'numbering_system' => 'latn',
+ 'decimal_pattern' => '#,##0.###',
+ 'percent_pattern' => '#,##0%',
+ 'currency_pattern' => '¤#,##0.00',
+ 'accounting_currency_pattern' => '¤#,##0.00;(¤#,##0.00)',
+ );
+
+ /**
+ * @covers ::__construct
+ */
+ public function testConstructor()
+ {
+ // Mock the existence of JSON definitions on the filesystem.
+ $root = vfsStream::setup('resources');
+ vfsStream::newFile('number_format/en.json')->at($root)->setContent(json_encode($this->englishDefinition));
+
+ // Instantiate the number format repository and confirm that the definition
+ // path was properly set.
+ $numberFormatRepository = new NumberFormatRepository('vfs://resources/number_format/');
+ $definitionPath = $this->getObjectAttribute($numberFormatRepository, 'definitionPath');
+ $this->assertEquals('vfs://resources/number_format/', $definitionPath);
+
+ return $numberFormatRepository;
+ }
+
+ /**
+ * @covers ::get
+ * @covers ::createNumberFormatFromDefinition
+ * @uses \CommerceGuys\Intl\NumberFormat\NumberFormat
+ * @uses \CommerceGuys\Intl\LocaleResolverTrait
+ * @depends testConstructor
+ */
+ public function testGet($numberFormatRepository)
+ {
+ $numberFormat = $numberFormatRepository->get('en');
+ $this->assertInstanceOf('CommerceGuys\\Intl\\NumberFormat\\NumberFormat', $numberFormat);
+ $this->assertEquals('en', $numberFormat->getLocale());
+ $this->assertEquals('latn', $numberFormat->getNumberingSystem());
+ $this->assertEquals('.', $numberFormat->getDecimalSeparator());
+ $this->assertEquals(',', $numberFormat->getGroupingSeparator());
+ $this->assertEquals('+', $numberFormat->getPlusSign());
+ $this->assertEquals('-', $numberFormat->getMinusSign());
+ $this->assertEquals('%', $numberFormat->getPercentSign());
+ $this->assertEquals('#,##0.###', $numberFormat->getDecimalPattern());
+ $this->assertEquals('#,##0%', $numberFormat->getPercentPattern());
+ $this->assertEquals('¤#,##0.00', $numberFormat->getCurrencyPattern());
+ $this->assertEquals('¤#,##0.00;(¤#,##0.00)', $numberFormat->getAccountingCurrencyPattern());
+
+ return $numberFormat;
+ }
+}
diff --git a/library/intl/tests/NumberFormat/NumberFormatTest.php b/library/intl/tests/NumberFormat/NumberFormatTest.php
new file mode 100644
index 000000000..299dc41cb
--- /dev/null
+++ b/library/intl/tests/NumberFormat/NumberFormatTest.php
@@ -0,0 +1,131 @@
+<?php
+
+namespace CommerceGuys\Intl\Tests\NumberFormat;
+
+use CommerceGuys\Intl\NumberFormat\NumberFormat;
+
+/**
+ * @coversDefaultClass CommerceGuys\Intl\NumberFormat\NumberFormat
+ */
+class NumberFormatTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var NumberFormat
+ */
+ protected $numberFormat;
+
+ public function setUp()
+ {
+ $this->numberFormat = new NumberFormat();
+ }
+
+ /**
+ * @covers ::getLocale
+ * @covers ::setLocale
+ */
+ public function testLocale()
+ {
+ $this->numberFormat->setLocale('en');
+ $this->assertEquals('en', $this->numberFormat->getLocale());
+ }
+
+ /**
+ * @covers ::getNumberingSystem
+ * @covers ::setNumberingSystem
+ */
+ public function testNumberingSystem()
+ {
+ $this->numberFormat->setNumberingSystem('latn');
+ $this->assertEquals('latn', $this->numberFormat->getNumberingSystem());
+ }
+
+ /**
+ * @covers ::getDecimalSeparator
+ * @covers ::setDecimalSeparator
+ */
+ public function testDecimalSeparator()
+ {
+ $this->numberFormat->setDecimalSeparator('.');
+ $this->assertEquals('.', $this->numberFormat->getDecimalSeparator());
+ }
+
+ /**
+ * @covers ::getGroupingSeparator
+ * @covers ::setGroupingSeparator
+ */
+ public function testGroupingSeparator()
+ {
+ $this->numberFormat->setGroupingSeparator(',');
+ $this->assertEquals(',', $this->numberFormat->getGroupingSeparator());
+ }
+
+ /**
+ * @covers ::getPlusSign
+ * @covers ::setPlusSign
+ */
+ public function testPlusSign()
+ {
+ $this->numberFormat->setPlusSign('+');
+ $this->assertEquals('+', $this->numberFormat->getPlusSign());
+ }
+
+ /**
+ * @covers ::getMinusSign
+ * @covers ::setMinusSign
+ */
+ public function testMinusSign()
+ {
+ $this->numberFormat->setMinusSign('-');
+ $this->assertEquals('-', $this->numberFormat->getMinusSign());
+ }
+
+ /**
+ * @covers ::getPercentSign
+ * @covers ::setPercentSign
+ */
+ public function testPercentSign()
+ {
+ $this->numberFormat->setPercentSign('%');
+ $this->assertEquals('%', $this->numberFormat->getPercentSign());
+ }
+
+ /**
+ * @covers ::getDecimalPattern
+ * @covers ::setDecimalPattern
+ */
+ public function testDecimalPattern()
+ {
+ $this->numberFormat->setDecimalPattern('#,##0.###');
+ $this->assertEquals('#,##0.###', $this->numberFormat->getDecimalPattern());
+ }
+
+ /**
+ * @covers ::getPercentPattern
+ * @covers ::setPercentPattern
+ */
+ public function testPercentPattern()
+ {
+ $this->numberFormat->setPercentPattern('#,##0%');
+ $this->assertEquals('#,##0%', $this->numberFormat->getPercentPattern());
+ }
+
+ /**
+ * @covers ::getCurrencyPattern
+ * @covers ::setCurrencyPattern
+ */
+ public function testCurrencyPattern()
+ {
+ $this->numberFormat->setCurrencyPattern('¤#,##0.00');
+ $this->assertEquals('¤#,##0.00', $this->numberFormat->getCurrencyPattern());
+ }
+
+ /**
+ * @covers ::getAccountingCurrencyPattern
+ * @covers ::setAccountingCurrencyPattern
+ */
+ public function testAccountingCurrencyPattern()
+ {
+ $this->numberFormat->setAccountingCurrencyPattern('¤#,##0.00;(¤#,##0.00)');
+ $this->assertEquals('¤#,##0.00;(¤#,##0.00)', $this->numberFormat->getAccountingCurrencyPattern());
+ }
+}