6 use Koha
::Acquisition
::Currencies
;
10 # work around wide character warnings
11 binmode Test
::More
->builder->output, ":encoding(UTF-8)";
12 binmode Test
::More
->builder->failure_output, ":encoding(UTF-8)";
15 my $dbh = C4
::Context
->dbh;
16 $dbh->{AutoCommit
} = 0;
17 $dbh->{RaiseError
} = 1;
19 # set some test price strings and expected output
20 my @prices2test=( { string
=> '25,5 £, $34,55, $LD35', expected
=> '34.55' },
21 { string
=> '32 EUR, 42.50$ USD, 54 CAD', expected
=>'42.50' },
22 { string
=> '38.80 Ksh, ¥300, 51,50 USD', expected
=> '51.50' },
23 { string
=> '44 $, 33 €, 64 Br, £30', expected
=> '44' },
24 { string
=> '9 EUR,$34,55 USD,$7.35 CAN', expected
=> '34.55' },
25 { string
=> '$55.32', expected
=> '55.32' },
26 { string
=> '9.99 USD (paperback)', expected
=> '9.99' },
27 { string
=> '$9.99 USD (paperback)', expected
=> '9.99' },
28 { string
=> '18.95 (U.S.)', expected
=> '18.95' },
29 { string
=> '$5.99 ($7.75 CAN)', expected
=> '5.99' },
30 { string
=> '5.99 (7.75 CAN)', expected
=> '5.99' },
33 plan tests
=> 2 * scalar @prices2test;
35 # set active currency test data
36 my $CURRENCY = 'TEST';
41 # disables existing active currency if necessary.
42 my $active_currency = Koha
::Acquisition
::Currencies
->get_active;
44 if ($active_currency) {
45 $curr = $active_currency->currency;
46 $dbh->do("UPDATE currency set active = 0 where currency = '$curr'");
49 $dbh->do("INSERT INTO currency ( currency,symbol,isocode,rate,active )
50 VALUES ('$CURRENCY','$SYMBOL','$ISOCODE','$RATE',1)");
51 foreach my $price (@prices2test) {
53 MungeMarcPrice
($price->{'string'}),
55 "got expected price from $price->{'string'} (using currency.isocode)",
59 # run tests again, but fall back to currency name
60 $dbh->do('DELETE FROM aqbasket');
61 $dbh->do('DELETE FROM currency');
62 $dbh->do("INSERT INTO currency ( currency, symbol, rate, active )
63 VALUES ('$ISOCODE', '$SYMBOL', '$RATE', 1)");
65 foreach my $price (@prices2test) {
67 MungeMarcPrice
($price->{'string'}),
69 "got expected price from $price->{'string'} (using ISO code as currency name)",