|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2015 Koha Development team |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Test::More tests => 6; |
| 22 |
use Koha::Acquisition::Currency; |
| 23 |
use Koha::Acquisition::Currencies; |
| 24 |
use t::lib::TestBuilder; |
| 25 |
|
| 26 |
my $builder = t::lib::TestBuilder->new; |
| 27 |
my $nb_of_currencies = Koha::Acquisition::Currencies->search->count; |
| 28 |
my $new_currency_1 = Koha::Acquisition::Currency->new({ |
| 29 |
currency => 'my_cur_1', |
| 30 |
symbol => 'symb1', |
| 31 |
isocode => 'isoc1', |
| 32 |
rate => 1, |
| 33 |
active => 1, |
| 34 |
})->store; |
| 35 |
|
| 36 |
my $retrieved_currency_1 = Koha::Acquisition::Currencies->find( $new_currency_1->currency ); |
| 37 |
is( $retrieved_currency_1->active, 1, 'Active should have been set to 1' ); |
| 38 |
|
| 39 |
my $new_currency_2 = Koha::Acquisition::Currency->new({ |
| 40 |
currency => 'my_cur_2', |
| 41 |
symbol => 'symb2', |
| 42 |
isocode => 'isoc2', |
| 43 |
rate => 2, |
| 44 |
active => 1, |
| 45 |
})->store; |
| 46 |
|
| 47 |
is( Koha::Acquisition::Currencies->search->count, $nb_of_currencies + 2, 'The 2 currencies should have been added' ); |
| 48 |
my $retrieved_currency_2 = Koha::Acquisition::Currencies->find( $new_currency_2->currency ); |
| 49 |
is( $retrieved_currency_2->active, 1, 'Active should have been set to 1' ); |
| 50 |
|
| 51 |
my $active_currency = Koha::Acquisition::Currencies->get_active; |
| 52 |
is ( $active_currency->currency, $retrieved_currency_2->currency, 'The active currency should be the last one marked as active' ); |
| 53 |
|
| 54 |
my $nb_of_active_currencies = Koha::Acquisition::Currencies->search({active => 1})->count; |
| 55 |
is ( $nb_of_active_currencies, 1, 'Only 1 currency should be marked as active' ); |
| 56 |
|
| 57 |
$retrieved_currency_1->delete; |
| 58 |
is( Koha::Acquisition::Currencies->search->count, $nb_of_currencies + 1, 'Delete should have deleted the currency' ); |