Bug 14285: Bengali locale needs to be re-defined
[koha.git] / t / db_dependent / MungeMarcPrice.t
blobf661323e7816acee7bf53090c03592b941fdcb00
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
5 use C4::Biblio;
6 use C4::Budgets;
7 use Test::More;
8 use utf8;
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)";
14 # start transaction
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';
37 my $SYMBOL = '$';
38 my $ISOCODE = 'USD';
39 my $RATE= 1;
41 # disables existing active currency if necessary.
42 my $active_currency = C4::Budgets->GetCurrency();
43 my $curr;
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) {
52 is(
53 MungeMarcPrice($price->{'string'}),
54 $price->{'expected'},
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) {
66 is(
67 MungeMarcPrice($price->{'string'}),
68 $price->{'expected'},
69 "got expected price from $price->{'string'} (using ISO code as currency name)",
73 # Cleanup
74 $dbh->rollback;