This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
CurrencyFormatTest.php
127 lines (115 loc) · 5.29 KB
/
CurrencyFormatTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_I18n
*/
namespace ZendTest\I18n\View\Helper;
use Locale;
use Zend\I18n\View\Helper\CurrencyFormat as CurrencyFormatHelper;
/**
* @category Zend
* @package Zend_View
* @subpackage UnitTests
* @group Zend_View
* @group Zend_View_Helper
*/
class CurrencyFormatTest extends \PHPUnit_Framework_TestCase
{
/**
* @var CurrencyFormatHelper
*/
public $helper;
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
public function setUp()
{
$this->helper = new CurrencyFormatHelper();
}
public function currencyProvider()
{
return array(
// locale currency show decimals number currencyPattern expected
array('de_AT', 'EUR', true, 1234.56, null, '€ 1.234,56'),
array('de_AT', 'EUR', true, 0.123, null, '€ 0,12'),
array('de_AT', 'EUR', true, 0.123, '#,##0.00 ¤', '0,12 €'),
array('de_AT', 'EUR', true, -0.123, '#,##0.00 ¤; ¤ - #,##0.00', ' € - 0,12'),
array('de_AT', 'EUR', true, -0.123, '¤ #,##0.00; - ¤ #,##0.00', '- € 0,12'),
array('de_DE', 'EUR', true, 1234567.891234567890000, null, '1.234.567,89 €'),
array('de_DE', 'RUR', true, 1234567.891234567890000, null, '1.234.567,89 RUR'),
array('ru_RU', 'EUR', true, 1234567.891234567890000, null, '1 234 567,89 €'),
array('ru_RU', 'RUR', true, 1234567.891234567890000, null, '1 234 567,89 р.'),
array('en_US', 'EUR', true, 1234567.891234567890000, null, '€1,234,567.89'),
array('en_US', 'RUR', true, 1234567.891234567890000, null, 'RUR1,234,567.89'),
array('en_US', 'USD', true, 1234567.891234567890000, null, '$1,234,567.89'),
array('de_AT', 'EUR', false, 1234.56, null, '€ 1.235'),
array('de_AT', 'EUR', false, 0.123, null, '€ 0'),
array('de_DE', 'EUR', false, 1234567.891234567890000, null, '1.234.568 €'),
array('de_DE', 'RUB', false, 1234567.891234567890000, null, '1.234.567,89 RUB'),
//array('ru_RU', 'EUR', false, 1234567.891234567890000, null, '1 234 568 €'),
//array('ru_RU', 'RUR', false, 1234567.891234567890000, null, '1 234 567 р.'),
//array('en_US', 'EUR', false, 1234567.891234567890000, null, '€1,234,568'),
//array('en_US', 'EUR', false, 1234567.891234567890000, null, '€1,234,568'),
array('en_US', 'USD', false, 1234567.891234567890000, null, '$1,234,568'),
);
}
/**
* @dataProvider currencyProvider
*/
public function testBasic($locale, $currencyCode, $showDecimals, $number, $currencyPattern, $expected)
{
$this->assertMbStringEquals(
$expected,
$this->helper->__invoke(
$number,
$currencyCode,
$showDecimals,
$locale,
$currencyPattern
)
);
}
/**
* @dataProvider currencyProvider
*/
public function testSettersProvideDefaults(
$locale,
$currencyCode,
$showDecimals,
$number,
$currencyPattern,
$expected
) {
$this->helper
->setLocale($locale)
->setShouldShowDecimals($showDecimals)
->setCurrencyCode($currencyCode)
->setCurrencyPattern($currencyPattern);
$this->assertMbStringEquals($expected, $this->helper->__invoke($number));
}
public function testViewhelperExecutedSequentially()
{
$helper = $this->helper;
$helper->setShouldShowDecimals(true);
$this->assertEquals('1.234,43 €', $helper(1234.4321, 'EUR', null, 'de_DE'));
$this->assertEquals('1.234 €', $helper(1234.4321, 'EUR', false, 'de_DE'));
$this->assertEquals('1.234,43 €', $helper(1234.4321, 'EUR', null, 'de_DE'));
}
public function testDefaultLocale()
{
$this->assertMbStringEquals(Locale::getDefault(), $this->helper->getLocale());
}
public function assertMbStringEquals($expected, $test, $message = '')
{
$expected = str_replace(array("\xC2\xA0", ' '), '', $expected);
$test = str_replace(array("\xC2\xA0", ' '), '', $test);
$this->assertEquals($expected, $test, $message);
}
}