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