3 # Copyright 2019 Koha Development team
5 # This file is part of Koha
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.
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.
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>.
22 use Test::More tests => 7;
24 use Koha::Account::DebitTypes;
27 use t::lib::TestBuilder;
31 my $schema = Koha::Database->new->schema;
32 $schema->storage->txn_begin;
34 my $builder = t::lib::TestBuilder->new;
35 my $number_of_debit_types = Koha::Account::DebitTypes->search->count;
37 my $new_debit_type_1 = Koha::Account::DebitType->new(
40 description => 'my description 3',
41 can_be_added_manually => 1,
42 default_amount => 0.45,
46 my $new_debit_type_2 = Koha::Account::DebitType->new(
49 description => 'my description 4',
50 can_be_added_manually => 1,
55 Koha::Account::DebitTypes->search->count,
56 $number_of_debit_types + 2,
57 '2 debit types added successfully'
60 my $retrieved_debit_type_1 =
61 Koha::Account::DebitTypes->find( $new_debit_type_1->code );
63 $retrieved_debit_type_1->description,
64 $new_debit_type_1->description,
65 'Find a debit type by code should return the correct one (non-system)'
67 ok( !$retrieved_debit_type_1->is_system,
68 'Non-system debit type identified correctly by "is_system"' );
70 my $retrieved_debit_type_system = Koha::Account::DebitTypes->find('OVERDUE');
71 is( $retrieved_debit_type_system->code,
73 'Find a debit type by code should return the correct one (system)' );
74 ok( $retrieved_debit_type_system->is_system,
75 'System debit type identified correctly by "is_system"' );
78 $retrieved_debit_type_system->delete;
82 $_->isa('Koha::Exceptions::CannotDeleteDefault'),
83 'A system debit type cannot be deleted'
86 $retrieved_debit_type_1->delete;
88 Koha::Account::DebitTypes->search->count,
89 $number_of_debit_types + 1,
90 'A non-system debit type can be deleted'
93 $schema->storage->txn_rollback;