Bug 12916 - Missing Test to demonstrate warnings.
[koha.git] / t / Number / Price.t
1 use Modern::Perl;
2
3 use Test::More tests => 19;
4
5 use Test::MockModule;
6 use t::lib::Mocks;
7
8 use C4::Budgets;
9 my $budget_module = Test::MockModule->new('C4::Budgets');
10 my $currency;
11 $budget_module->mock( 'GetCurrency', sub { return $currency; } );
12 use_ok('Koha::Number::Price');
13
14 my $format = {
15     p_cs_precedes => 1, # Force to place the symbol at the beginning
16     p_sep_by_space => 0, # Force to not add a space between the symbol and the number
17 };
18 t::lib::Mocks::mock_preference( 'CurrencyFormat', 'US' );
19 $currency = {
20     currency => 'USD',
21     symbol   => '$',
22     rate     => 1,
23     active   => 1,
24 };
25
26 is( Koha::Number::Price->new->format( $format ),    '0.00', 'US: format 0' );
27 is( Koha::Number::Price->new(3)->format( $format ), '3.00', 'US: format 3' );
28 is( Koha::Number::Price->new(1234567890)->format( $format ),
29     '1,234,567,890.00', 'US: format 1234567890' );
30
31 # FIXME This should be display symbol, but it was the case before the creation of this module
32 is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ),
33     '0.00', 'US: format 0 with symbol' );
34 is( Koha::Number::Price->new(3)->format( { %$format, with_symbol => 1 } ),
35     '3.00', 'US: format 3 with symbol' );
36 is(
37     Koha::Number::Price->new(1234567890)
38       ->format( { %$format, with_symbol => 1 }, 'US: format 1234567890 with symbol' ),
39     '1,234,567,890.00'
40 );
41
42 is( Koha::Number::Price->new->unformat,    '0', 'US: unformat 0' );
43 is( Koha::Number::Price->new(3)->unformat, '3', 'US: unformat 3' );
44 is( Koha::Number::Price->new(1234567890)->unformat,
45     '1234567890', 'US: unformat 1234567890' );
46
47 t::lib::Mocks::mock_preference( 'CurrencyFormat', 'FR' );
48 $currency = {
49     currency => 'EUR',
50     symbol   => '€',
51     rate     => 1,
52     active   => 1,
53 };
54
55 # Actually,the price formating for France is 3,00€
56 # How put the symbol at the end with Number::Format?
57 is( Koha::Number::Price->new->format( $format ),    '0,00', 'FR: format 0' );
58 is( Koha::Number::Price->new(3)->format( $format ), '3,00', 'FR: format 3' );
59 is(
60     Koha::Number::Price->new(1234567890)->format( $format ),
61     '1 234 567 890,00',
62     'FR: format 1234567890'
63 );
64 is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ),
65     '€0,00', 'FR: format 0 with symbol' );
66 is( Koha::Number::Price->new(3)->format( { %$format, with_symbol => 1 } ),
67     '€3,00', 'FR: format 3 with symbol' );
68 is(
69     Koha::Number::Price->new(1234567890)
70       ->format( { %$format, with_symbol => 1 }, 'FR: format 123567890 with symbol' ),
71     '€1 234 567 890,00'
72 );
73
74 is( Koha::Number::Price->new->unformat,    '0', 'FR: unformat 0' );
75 is( Koha::Number::Price->new(3)->unformat, '3', 'FR: unformat 3' );
76 is( Koha::Number::Price->new(1234567890)->unformat,
77     '1234567890', 'FR: unformat 1234567890' );