Bug 24603: Simplify tests using TestBuilder
[koha.git] / t / db_dependent / Koha / Account / DebitTypes.t
blob0c4812d2bdb4edcae3fb17acd34aa56c407bccff
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
22 use Test::More tests => 3;
24 use Koha::Account::DebitType;
25 use Koha::Account::DebitTypes;
26 use Koha::Database;
28 use t::lib::TestBuilder;
30 use Try::Tiny;
32 my $schema = Koha::Database->new->schema;
33 $schema->storage->txn_begin;
35 my $builder = t::lib::TestBuilder->new;
36 my $number_of_debit_types = Koha::Account::DebitTypes->search->count;
38 my $new_debit_type_1 = Koha::Account::DebitType->new(
40 code => '3CODE',
41 description => 'my description 3',
42 can_be_invoiced => 1,
43 default_amount => 0.45,
45 )->store;
47 my $new_debit_type_2 = Koha::Account::DebitType->new(
49 code => '4CODE',
50 description => 'my description 4',
51 can_be_invoiced => 1,
53 )->store;
55 my $retrieved_debit_types_all = Koha::Account::DebitTypes->search();
56 try {
57 $retrieved_debit_types_all->delete;
59 catch {
60 ok(
61 $_->isa('Koha::Exceptions::CannotDeleteDefault'),
62 'A system debit type cannot be deleted via the set'
65 is(
66 Koha::Account::DebitTypes->search->count,
67 $number_of_debit_types + 2,
68 'System debit types cannot be deleted as a set'
71 my $retrieved_debit_types_limited = Koha::Account::DebitTypes->search(
73 code => { 'in' => [ $new_debit_type_1->code, $new_debit_type_2->code ] }
76 $retrieved_debit_types_limited->delete;
77 is( Koha::Account::DebitTypes->search->count,
78 $number_of_debit_types, 'Non-system debit types can be deleted as a set' );
80 $schema->storage->txn_rollback;